use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class CGlobalDataFeature method registerInvocationPlugins.
@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, InvocationPlugins invocationPlugins, boolean hosted) {
Registration r = new Registration(invocationPlugins, CGlobalData.class);
r.register1("get", Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
VMError.guarantee(receiver.get().isConstant(), "Accessed CGlobalData is not a compile-time constant: " + b.getMethod().asStackTraceElement(b.bci()));
CGlobalDataImpl<?> data = (CGlobalDataImpl<?>) SubstrateObjectConstant.asObject(receiver.get().asConstant());
CGlobalDataInfo info = CGlobalDataFeature.this.map.get(data);
b.addPush(targetMethod.getSignature().getReturnKind(), new CGlobalDataLoadAddressNode(info));
return true;
}
});
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class BytecodeParser method tryInvocationPlugin.
@SuppressWarnings("try")
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, JavaType returnType) {
InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod);
if (plugin != null) {
if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
// method should be called.
assert !targetMethod.hasBytecodes() : "TODO: when does this happen?";
return false;
}
InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args);
IntrinsicGuard intrinsicGuard = null;
if (invokeKind.isIndirect()) {
intrinsicGuard = guardIntrinsic(args, targetMethod, pluginReceiver);
if (intrinsicGuard == null) {
return false;
} else if (intrinsicGuard.nonIntrinsicBranch == null) {
assert lastInstr instanceof FixedGuardNode;
}
}
InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null;
try (DebugCloseable context = openNodeContext(targetMethod)) {
if (plugin.execute(this, targetMethod, pluginReceiver, args)) {
afterInvocationPluginExecution(true, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
return true;
} else {
afterInvocationPluginExecution(false, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
}
}
}
return false;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class SubstrateReplacements method makeInvocationPlugins.
@Platforms(Platform.HOSTED_ONLY.class)
private static InvocationPlugins makeInvocationPlugins(GraphBuilderConfiguration.Plugins plugins, Builder builder, Function<Object, Object> objectReplacer) {
Map<ResolvedJavaMethod, InvocationPlugin> result = new HashMap<>(builder.delayedInvocationPluginMethods.size());
for (ResolvedJavaMethod method : builder.delayedInvocationPluginMethods) {
ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) objectReplacer.apply(method);
InvocationPlugin plugin = plugins.getInvocationPlugins().lookupInvocation(replacedMethod);
assert plugin != null : "expected invocation plugin for " + replacedMethod;
result.put(replacedMethod, plugin);
}
return new InvocationPlugins(result, null);
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class PEGraphDecoder method tryInvocationPlugin.
protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
if (invocationPlugins == null || invocationPlugins.isEmpty()) {
return false;
}
Invoke invoke = invokeData.invoke;
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
if (invocationPlugin == null) {
return false;
}
ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
/*
* Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
*/
invoke.asNode().replaceAtPredecessor(null);
PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor);
InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
if (graphBuilderContext.invokeConsumed) {
/* Nothing to do. */
} else if (graphBuilderContext.lastInstr != null) {
registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
deleteInvoke(invoke);
} else {
assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
invoke.asNode().replaceAtUsages(null);
deleteInvoke(invoke);
}
return true;
} else {
/* Intrinsification failed, restore original state: invoke is in Graph. */
invokePredecessor.setNext(invoke.asNode());
return false;
}
}
use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin in project graal by oracle.
the class SPARCGraphBuilderPlugins method registerIntegerLongPlugins.
private static void registerIntegerLongPlugins(InvocationPlugins plugins, Class<?> substituteDeclaringClass, JavaKind kind, BytecodeProvider bytecodeProvider) {
Class<?> declaringClass = kind.toBoxedJavaClass();
Class<?> type = kind.toJavaClass();
Registration r = new Registration(plugins, declaringClass, bytecodeProvider);
r.registerMethodSubstitution(substituteDeclaringClass, "numberOfLeadingZeros", type);
r.registerMethodSubstitution(substituteDeclaringClass, "numberOfTrailingZeros", type);
r.register1("bitCount", type, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.push(JavaKind.Int, b.append(new BitCountNode(value).canonical(null)));
return true;
}
});
}
Aggregations