use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerArrayPlugins.
private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
Registration r = new Registration(plugins, Array.class, bytecodeProvider);
r.register2("newInstance", Class.class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode componentType, ValueNode length) {
b.addPush(JavaKind.Object, new DynamicNewArrayNode(componentType, length, true));
return true;
}
});
r.registerMethodSubstitution(ArraySubstitutions.class, "getLength", Object.class);
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class StandardGraphBuilderPlugins method registerShortPlugins.
private static void registerShortPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Short.class);
r.register1("reverseBytes", short.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
// return (short) (Integer.reverse(i) >> 16);
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
b.push(JavaKind.Short, b.append(charCast.canonical(null)));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class ReplacementsImpl method getSubstitutionBytecode.
@Override
public Bytecode getSubstitutionBytecode(ResolvedJavaMethod method) {
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(providers.getMetaAccess());
return msPlugin.getBytecodeProvider().getBytecode(substitute);
}
return null;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class ReplacementsImpl method getSubstitution.
@Override
public StructuredGraph getSubstitution(ResolvedJavaMethod method, int invokeBci, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
StructuredGraph result;
InvocationPlugin plugin = graphBuilderPlugins.getInvocationPlugins().lookupInvocation(method);
if (plugin != null && (!plugin.inlineOnly() || invokeBci >= 0)) {
MetaAccessProvider metaAccess = providers.getMetaAccess();
if (plugin instanceof MethodSubstitutionPlugin) {
MethodSubstitutionPlugin msPlugin = (MethodSubstitutionPlugin) plugin;
ResolvedJavaMethod substitute = msPlugin.getSubstitute(metaAccess);
StructuredGraph graph = UseSnippetGraphCache.getValue(options) ? graphs.get(substitute) : null;
if (graph == null || graph.trackNodeSourcePosition() != trackNodeSourcePosition) {
try (DebugContext debug = openDebugContext("Substitution_", method)) {
graph = makeGraph(debug, msPlugin.getBytecodeProvider(), substitute, null, method, trackNodeSourcePosition, replaceePosition);
if (!UseSnippetGraphCache.getValue(options)) {
return graph;
}
graph.freeze();
graphs.putIfAbsent(substitute, graph);
graph = graphs.get(substitute);
}
}
assert graph.isFrozen();
result = graph;
} else {
Bytecode code = new ResolvedJavaMethodBytecode(method);
ConstantReflectionProvider constantReflection = providers.getConstantReflection();
ConstantFieldProvider constantFieldProvider = providers.getConstantFieldProvider();
StampProvider stampProvider = providers.getStampProvider();
try (DebugContext debug = openDebugContext("Substitution_", method)) {
result = new IntrinsicGraphBuilder(options, debug, metaAccess, constantReflection, constantFieldProvider, stampProvider, code, invokeBci).buildGraph(plugin);
}
}
} else {
result = null;
}
return result;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class TruffleGraphBuilderPlugins method registerOptimizedCallTargetPlugins.
public static void registerOptimizedCallTargetPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, KnownTruffleTypes types) {
final ResolvedJavaType optimizedCallTargetType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedCallTarget");
Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedCallTargetType));
r.register2("createFrame", new ResolvedJavaSymbol(types.classFrameDescriptor), Object[].class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode descriptor, ValueNode args) {
if (canDelayIntrinsification) {
return false;
}
if (!descriptor.isJavaConstant()) {
throw b.bailout("Parameter 'descriptor' is not a compile-time constant");
}
ValueNode nonNullArguments = b.add(PiNode.create(args, StampFactory.objectNonNull(StampTool.typeReferenceOrNull(args))));
b.addPush(JavaKind.Object, new NewFrameNode(b, descriptor, nonNullArguments, types));
return true;
}
});
r.register2("castArrayFixedLength", Object[].class, int.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode args, ValueNode length) {
b.addPush(JavaKind.Object, new PiArrayNode(args, length, args.stamp(NodeView.DEFAULT)));
return true;
}
});
registerUnsafeCast(r, canDelayIntrinsification);
}
Aggregations