Search in sources :

Example 1 with InlineInvokePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin in project graal by oracle.

the class BytecodeParser method createNonInlinedInvoke.

protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, ValueNode[] invokeArgs, ResolvedJavaMethod targetMethod, InvokeKind invokeKind, JavaKind resultType, JavaType returnType, JavaTypeProfile profile) {
    StampPair returnStamp = graphBuilderConfig.getPlugins().getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
    }
    MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, targetMethod, invokeArgs, returnStamp, profile));
    Invoke invoke = createNonInlinedInvoke(exceptionEdge, invokeBci, callTarget, resultType);
    for (InlineInvokePlugin plugin : graphBuilderConfig.getPlugins().getInlineInvokePlugins()) {
        plugin.notifyNotInlined(this, targetMethod, invoke);
    }
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ResolveClassBeforeStaticInvoke(org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 2 with InlineInvokePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin in project graal by oracle.

the class SubstrateReplacements method setGraphBuilderPlugins.

@Override
public void setGraphBuilderPlugins(Plugins plugins) {
    Plugins copy = new Plugins(plugins);
    copy.clearInlineInvokePlugins();
    for (InlineInvokePlugin plugin : plugins.getInlineInvokePlugins()) {
        copy.appendInlineInvokePlugin(plugin == this ? new SnippetInlineInvokePlugin() : plugin);
    }
    super.setGraphBuilderPlugins(copy);
}
Also used : InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 3 with InlineInvokePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin in project graal by oracle.

the class PEGraphDecoder method trySimplifyInvoke.

protected LoopScope trySimplifyInvoke(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
    // attempt to devirtualize the call
    ResolvedJavaMethod specialCallTarget = getSpecialCallTarget(invokeData, callTarget);
    if (specialCallTarget != null) {
        callTarget.setTargetMethod(specialCallTarget);
        callTarget.setInvokeKind(InvokeKind.Special);
    }
    if (tryInvocationPlugin(methodScope, loopScope, invokeData, callTarget)) {
        /*
             * The invocation plugin handled the call, so decoding continues in the calling method.
             */
        return loopScope;
    }
    LoopScope inlineLoopScope = tryInline(methodScope, loopScope, invokeData, callTarget);
    if (inlineLoopScope != null) {
        /*
             * We can inline the call, so decoding continues in the inlined method.
             */
        return inlineLoopScope;
    }
    for (InlineInvokePlugin plugin : inlineInvokePlugins) {
        plugin.notifyNotInlined(new PENonAppendGraphBuilderContext(methodScope, invokeData.invoke), callTarget.targetMethod(), invokeData.invoke);
    }
    return null;
}
Also used : InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with InlineInvokePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin in project graal by oracle.

the class PEGraphDecoder method tryInline.

protected LoopScope tryInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
    if (!callTarget.invokeKind().isDirect()) {
        return null;
    }
    ResolvedJavaMethod targetMethod = callTarget.targetMethod();
    if (targetMethod.hasNeverInlineDirective()) {
        return null;
    }
    ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
    GraphBuilderContext graphBuilderContext = new PENonAppendGraphBuilderContext(methodScope, invokeData.invoke);
    for (InlineInvokePlugin plugin : inlineInvokePlugins) {
        InlineInfo inlineInfo = plugin.shouldInlineInvoke(graphBuilderContext, targetMethod, arguments);
        if (inlineInfo != null) {
            if (inlineInfo.getMethodToInline() == null) {
                return null;
            } else {
                return doInline(methodScope, loopScope, invokeData, inlineInfo, arguments);
            }
        }
    }
    return null;
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ValueNode(org.graalvm.compiler.nodes.ValueNode) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 5 with InlineInvokePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin in project graal by oracle.

the class PEGraphDecoder method finishInlining.

@Override
protected void finishInlining(MethodScope is) {
    PEMethodScope inlineScope = (PEMethodScope) is;
    ResolvedJavaMethod inlineMethod = inlineScope.method;
    PEMethodScope methodScope = inlineScope.caller;
    LoopScope loopScope = inlineScope.callerLoopScope;
    InvokeData invokeData = inlineScope.invokeData;
    Invoke invoke = invokeData.invoke;
    FixedNode invokeNode = invoke.asNode();
    ValueNode exceptionValue = null;
    int returnNodeCount = 0;
    int unwindNodeCount = 0;
    List<ControlSinkNode> returnAndUnwindNodes = inlineScope.returnAndUnwindNodes;
    for (int i = 0; i < returnAndUnwindNodes.size(); i++) {
        FixedNode fixedNode = returnAndUnwindNodes.get(i);
        if (fixedNode instanceof ReturnNode) {
            returnNodeCount++;
        } else if (fixedNode.isAlive()) {
            assert fixedNode instanceof UnwindNode;
            unwindNodeCount++;
        }
    }
    if (unwindNodeCount > 0) {
        FixedNode unwindReplacement;
        if (invoke instanceof InvokeWithExceptionNode) {
            /* Decoding continues for the exception handler. */
            unwindReplacement = makeStubNode(methodScope, loopScope, invokeData.exceptionNextOrderId);
        } else {
            /* No exception handler available, so the only thing we can do is deoptimize. */
            unwindReplacement = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler));
        }
        if (unwindNodeCount == 1) {
            /* Only one UnwindNode, we can use the exception directly. */
            UnwindNode unwindNode = getSingleMatchingNode(returnAndUnwindNodes, returnNodeCount > 0, UnwindNode.class);
            exceptionValue = unwindNode.exception();
            unwindNode.replaceAndDelete(unwindReplacement);
        } else {
            /*
                 * More than one UnwindNode. This can happen with the loop explosion strategy
                 * FULL_EXPLODE_UNTIL_RETURN, where we keep exploding after the loop and therefore
                 * also explode exception paths. Merge the exception in a similar way as multiple
                 * return values.
                 */
            MergeNode unwindMergeNode = graph.add(new MergeNode());
            exceptionValue = InliningUtil.mergeValueProducers(unwindMergeNode, getMatchingNodes(returnAndUnwindNodes, returnNodeCount > 0, UnwindNode.class, unwindNodeCount), null, unwindNode -> unwindNode.exception());
            unwindMergeNode.setNext(unwindReplacement);
            ensureExceptionStateDecoded(inlineScope);
            unwindMergeNode.setStateAfter(inlineScope.exceptionState.duplicateModified(JavaKind.Object, JavaKind.Object, exceptionValue));
        }
    }
    assert invoke.next() == null;
    assert !(invoke instanceof InvokeWithExceptionNode) || ((InvokeWithExceptionNode) invoke).exceptionEdge() == null;
    ValueNode returnValue;
    if (returnNodeCount == 0) {
        returnValue = null;
    } else if (returnNodeCount == 1) {
        ReturnNode returnNode = getSingleMatchingNode(returnAndUnwindNodes, unwindNodeCount > 0, ReturnNode.class);
        returnValue = returnNode.result();
        FixedNode n = nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(returnNode));
        returnNode.replaceAndDelete(n);
    } else {
        AbstractMergeNode merge = graph.add(new MergeNode());
        merge.setStateAfter((FrameState) ensureNodeCreated(methodScope, loopScope, invokeData.stateAfterOrderId));
        returnValue = InliningUtil.mergeReturns(merge, getMatchingNodes(returnAndUnwindNodes, unwindNodeCount > 0, ReturnNode.class, returnNodeCount));
        FixedNode n = nodeAfterInvoke(methodScope, loopScope, invokeData, merge);
        merge.setNext(n);
    }
    invokeNode.replaceAtUsages(returnValue);
    /*
         * Usage the handles that we have on the return value and the exception to update the
         * orderId->Node table.
         */
    registerNode(loopScope, invokeData.invokeOrderId, returnValue, true, true);
    if (invoke instanceof InvokeWithExceptionNode) {
        registerNode(loopScope, invokeData.exceptionOrderId, exceptionValue, true, true);
    }
    if (inlineScope.exceptionPlaceholderNode != null) {
        inlineScope.exceptionPlaceholderNode.replaceAtUsagesAndDelete(exceptionValue);
    }
    deleteInvoke(invoke);
    for (InlineInvokePlugin plugin : inlineInvokePlugins) {
        plugin.notifyAfterInline(inlineMethod);
    }
}
Also used : SIZE_IGNORED(org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED) LoopExplosionKind(org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin.LoopExplosionKind) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) JavaKind(jdk.vm.ci.meta.JavaKind) Option(org.graalvm.compiler.options.Option) EconomicMap(org.graalvm.collections.EconomicMap) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) Map(java.util.Map) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) SimplifyingGraphDecoder(org.graalvm.compiler.nodes.SimplifyingGraphDecoder) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) SourceLanguagePositionProvider(org.graalvm.compiler.graph.SourceLanguagePositionProvider) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) IfNode(org.graalvm.compiler.nodes.IfNode) GraphUtil(org.graalvm.compiler.nodes.util.GraphUtil) OptionKey(org.graalvm.compiler.options.OptionKey) NodeView(org.graalvm.compiler.nodes.NodeView) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) SourceLanguagePosition(org.graalvm.compiler.graph.SourceLanguagePosition) Stamp(org.graalvm.compiler.core.common.type.Stamp) Bytecode(org.graalvm.compiler.bytecode.Bytecode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) List(java.util.List) GraalError.unimplemented(org.graalvm.compiler.debug.GraalError.unimplemented) FrameState(org.graalvm.compiler.nodes.FrameState) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) GraalError(org.graalvm.compiler.debug.GraalError) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) OptionType(org.graalvm.compiler.options.OptionType) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException) StateSplit(org.graalvm.compiler.nodes.StateSplit) LoopExplosionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin) Architecture(jdk.vm.ci.code.Architecture) BailoutException(jdk.vm.ci.code.BailoutException) HashMap(java.util.HashMap) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ArrayList(java.util.ArrayList) InliningUtil(org.graalvm.compiler.phases.common.inlining.InliningUtil) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CYCLES_IGNORED(org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED) DebugContext(org.graalvm.compiler.debug.DebugContext) NodeClass(org.graalvm.compiler.graph.NodeClass) CFGVerifier(org.graalvm.compiler.core.common.cfg.CFGVerifier) StampTool(org.graalvm.compiler.nodes.type.StampTool) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Equivalence(org.graalvm.collections.Equivalence) Assumptions(jdk.vm.ci.meta.Assumptions) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) OptionValues(org.graalvm.compiler.options.OptionValues) FixedNode(org.graalvm.compiler.nodes.FixedNode) Canonicalizable(org.graalvm.compiler.graph.spi.Canonicalizable) NodeInfo(org.graalvm.compiler.nodeinfo.NodeInfo) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Invoke(org.graalvm.compiler.nodes.Invoke) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) FrameState(org.graalvm.compiler.nodes.FrameState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) Invoke(org.graalvm.compiler.nodes.Invoke) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

InlineInvokePlugin (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin)7 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 Invoke (org.graalvm.compiler.nodes.Invoke)3 Assumptions (jdk.vm.ci.meta.Assumptions)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 StampPair (org.graalvm.compiler.core.common.type.StampPair)2 SourceLanguagePositionProvider (org.graalvm.compiler.graph.SourceLanguagePositionProvider)2 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)2 EncodedGraph (org.graalvm.compiler.nodes.EncodedGraph)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 LoopExplosionPlugin (org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin)2 ParameterPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Architecture (jdk.vm.ci.code.Architecture)1 BailoutException (jdk.vm.ci.code.BailoutException)1