Search in sources :

Example 6 with InlineInvokePlugin

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

the class PEGraphDecoder method doInline.

protected LoopScope doInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, InlineInfo inlineInfo, ValueNode[] arguments) {
    ResolvedJavaMethod inlineMethod = inlineInfo.getMethodToInline();
    EncodedGraph graphToInline = lookupEncodedGraph(inlineMethod, inlineInfo.getOriginalMethod(), inlineInfo.getIntrinsicBytecodeProvider(), graph.trackNodeSourcePosition());
    if (graphToInline == null) {
        return null;
    }
    assert !graph.trackNodeSourcePosition() || graphToInline.trackNodeSourcePosition() : graph + " " + graphToInline;
    if (methodScope.inliningDepth > Options.InliningDepthError.getValue(options)) {
        throw tooDeepInlining(methodScope);
    }
    for (InlineInvokePlugin plugin : inlineInvokePlugins) {
        plugin.notifyBeforeInline(inlineMethod);
    }
    Invoke invoke = invokeData.invoke;
    FixedNode invokeNode = invoke.asNode();
    FixedWithNextNode predecessor = (FixedWithNextNode) invokeNode.predecessor();
    invokeNode.replaceAtPredecessor(null);
    PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, graphToInline, inlineMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
    if (!inlineMethod.isStatic()) {
        if (StampTool.isPointerAlwaysNull(arguments[0])) {
            /*
                 * The receiver is null, so we can unconditionally throw a NullPointerException
                 * instead of performing any inlining.
                 */
            DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.NullCheckException));
            predecessor.setNext(deoptimizeNode);
            finishInlining(inlineScope);
            /* Continue decoding in the caller. */
            return loopScope;
        } else if (!StampTool.isPointerNonNull(arguments[0])) {
            /* The receiver might be null, so we need to insert a null check. */
            PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, predecessor);
            arguments[0] = graphBuilderContext.nullCheckedValue(arguments[0]);
            predecessor = graphBuilderContext.lastInstr;
        }
    }
    LoopScope inlineLoopScope = createInitialLoopScope(inlineScope, predecessor);
    /*
         * The GraphEncoder assigns parameters a nodeId immediately after the fixed nodes.
         * Initializing createdNodes here avoid decoding and immediately replacing the
         * ParameterNodes.
         */
    int firstArgumentNodeId = inlineScope.maxFixedNodeOrderId + 1;
    for (int i = 0; i < arguments.length; i++) {
        inlineLoopScope.createdNodes[firstArgumentNodeId + i] = arguments[i];
    }
    // Copy assumptions from inlinee to caller
    Assumptions assumptions = graph.getAssumptions();
    Assumptions inlinedAssumptions = graphToInline.getAssumptions();
    if (assumptions != null) {
        if (inlinedAssumptions != null) {
            assumptions.record(inlinedAssumptions);
        }
    } else {
        assert inlinedAssumptions == null : String.format("cannot inline graph (%s) which makes assumptions into a graph (%s) that doesn't", inlineMethod, graph);
    }
    // Copy inlined methods from inlinee to caller
    List<ResolvedJavaMethod> inlinedMethods = graphToInline.getInlinedMethods();
    if (inlinedMethods != null) {
        graph.getMethods().addAll(inlinedMethods);
    }
    if (graphToInline.getFields() != null) {
        for (ResolvedJavaField field : graphToInline.getFields()) {
            graph.recordField(field);
        }
    }
    if (graphToInline.hasUnsafeAccess()) {
        graph.markUnsafeAccess();
    }
    /*
         * Do the actual inlining by returning the initial loop scope for the inlined method scope.
         */
    return inlineLoopScope;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) FixedNode(org.graalvm.compiler.nodes.FixedNode) Invoke(org.graalvm.compiler.nodes.Invoke) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Assumptions(jdk.vm.ci.meta.Assumptions) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 7 with InlineInvokePlugin

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

the class PartialEvaluator method doGraphPE.

protected void doGraphPE(CompilableTruffleAST compilable, StructuredGraph graph, HighTierContext tierContext, TruffleInliningPlan inliningDecision) {
    LoopExplosionPlugin loopExplosionPlugin = new PELoopExplosionPlugin();
    ParameterPlugin parameterPlugin = new InterceptReceiverPlugin(compilable);
    ReplacementsImpl replacements = (ReplacementsImpl) providers.getReplacements();
    InlineInvokePlugin[] inlineInvokePlugins;
    InlineInvokePlugin inlineInvokePlugin = new PEInlineInvokePlugin(inliningDecision);
    HistogramInlineInvokePlugin histogramPlugin = null;
    if (TruffleCompilerOptions.getValue(PrintTruffleExpansionHistogram)) {
        histogramPlugin = new HistogramInlineInvokePlugin(graph);
        inlineInvokePlugins = new InlineInvokePlugin[] { replacements, inlineInvokePlugin, histogramPlugin };
    } else {
        inlineInvokePlugins = new InlineInvokePlugin[] { replacements, inlineInvokePlugin };
    }
    SourceLanguagePositionProvider sourceLanguagePosition = new TruffleSourceLanguagePositionProvider(inliningDecision);
    PEGraphDecoder decoder = createGraphDecoder(graph, tierContext, loopExplosionPlugin, decodingInvocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod, sourceLanguagePosition);
    decoder.decode(graph.method(), graph.trackNodeSourcePosition());
    if (TruffleCompilerOptions.getValue(PrintTruffleExpansionHistogram)) {
        histogramPlugin.print(compilable);
    }
}
Also used : SourceLanguagePositionProvider(org.graalvm.compiler.graph.SourceLanguagePositionProvider) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) ReplacementsImpl(org.graalvm.compiler.replacements.ReplacementsImpl) LoopExplosionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin) CachingPEGraphDecoder(org.graalvm.compiler.replacements.CachingPEGraphDecoder) PEGraphDecoder(org.graalvm.compiler.replacements.PEGraphDecoder) HistogramInlineInvokePlugin(org.graalvm.compiler.truffle.compiler.debug.HistogramInlineInvokePlugin) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) HistogramInlineInvokePlugin(org.graalvm.compiler.truffle.compiler.debug.HistogramInlineInvokePlugin)

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