Search in sources :

Example 1 with InvocationPluginReceiver

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver 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;
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 2 with InvocationPluginReceiver

use of org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver 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;
    }
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)2 InvocationPluginReceiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1