Search in sources :

Example 1 with InlineInfo

use of org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo 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 2 with InlineInfo

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

the class PartialEvaluator method postPartialEvaluation.

private static void postPartialEvaluation(final StructuredGraph graph) {
    NeverPartOfCompilationNode.verifyNotFoundIn(graph);
    for (AllowMaterializeNode materializeNode : graph.getNodes(AllowMaterializeNode.TYPE).snapshot()) {
        materializeNode.replaceAtUsages(materializeNode.getFrame());
        graph.removeFixed(materializeNode);
    }
    TruffleCompilerRuntime rt = TruffleCompilerRuntime.getRuntime();
    for (VirtualObjectNode virtualObjectNode : graph.getNodes(VirtualObjectNode.TYPE)) {
        if (virtualObjectNode instanceof VirtualInstanceNode) {
            VirtualInstanceNode virtualInstanceNode = (VirtualInstanceNode) virtualObjectNode;
            ResolvedJavaType type = virtualInstanceNode.type();
            if (rt.isValueType(type)) {
                virtualInstanceNode.setIdentity(false);
            }
        }
    }
    if (!TruffleCompilerOptions.getValue(TruffleInlineAcrossTruffleBoundary)) {
        // Do not inline across Truffle boundaries.
        for (MethodCallTargetNode mct : graph.getNodes(MethodCallTargetNode.TYPE)) {
            InlineInfo inlineInfo = rt.getInlineInfo(mct.targetMethod(), false);
            if (!inlineInfo.allowsInlining()) {
                mct.invoke().setUseForInlining(false);
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) TruffleCompilerRuntime(org.graalvm.compiler.truffle.common.TruffleCompilerRuntime) AllowMaterializeNode(org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 3 with InlineInfo

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

the class BytecodeParser method appendInvoke.

protected Invoke appendInvoke(InvokeKind initialInvokeKind, ResolvedJavaMethod initialTargetMethod, ValueNode[] args) {
    ResolvedJavaMethod targetMethod = initialTargetMethod;
    InvokeKind invokeKind = initialInvokeKind;
    if (initialInvokeKind.isIndirect()) {
        ResolvedJavaType contextType = this.frameState.getMethod().getDeclaringClass();
        ResolvedJavaMethod specialCallTarget = MethodCallTargetNode.findSpecialCallTarget(initialInvokeKind, args[0], initialTargetMethod, contextType);
        if (specialCallTarget != null) {
            invokeKind = InvokeKind.Special;
            targetMethod = specialCallTarget;
        }
    }
    JavaKind resultType = targetMethod.getSignature().getReturnKind();
    if (!parsingIntrinsic() && DeoptALot.getValue(options)) {
        append(new DeoptimizeNode(DeoptimizationAction.None, RuntimeConstraint));
        frameState.pushReturn(resultType, ConstantNode.defaultForKind(resultType, graph));
        return null;
    }
    JavaType returnType = targetMethod.getSignature().getReturnType(method.getDeclaringClass());
    if (graphBuilderConfig.eagerResolving() || parsingIntrinsic()) {
        returnType = returnType.resolve(targetMethod.getDeclaringClass());
    }
    if (invokeKind.hasReceiver()) {
        args[0] = emitExplicitExceptions(args[0]);
    }
    if (initialInvokeKind == InvokeKind.Special && !targetMethod.isConstructor()) {
        emitCheckForInvokeSuperSpecial(args);
    }
    InlineInfo inlineInfo = null;
    try {
        currentInvoke = new CurrentInvoke(args, invokeKind, returnType);
        if (tryNodePluginForInvocation(args, targetMethod)) {
            if (TraceParserPlugins.getValue(options)) {
                traceWithContext("used node plugin for %s", targetMethod.format("%h.%n(%p)"));
            }
            return null;
        }
        if (invokeKind.hasReceiver() && args[0].isNullConstant()) {
            append(new DeoptimizeNode(InvalidateRecompile, NullCheckException));
            return null;
        }
        if (!invokeKind.isIndirect() || (UseGuardedIntrinsics.getValue(options) && !GeneratePIC.getValue(options))) {
            if (tryInvocationPlugin(invokeKind, args, targetMethod, resultType, returnType)) {
                if (TraceParserPlugins.getValue(options)) {
                    traceWithContext("used invocation plugin for %s", targetMethod.format("%h.%n(%p)"));
                }
                return null;
            }
        }
        if (invokeKind.isDirect()) {
            inlineInfo = tryInline(args, targetMethod);
            if (inlineInfo == SUCCESSFULLY_INLINED) {
                return null;
            }
        }
    } finally {
        currentInvoke = null;
    }
    int invokeBci = bci();
    JavaTypeProfile profile = getProfileForInvoke(invokeKind);
    ExceptionEdgeAction edgeAction = getActionForInvokeExceptionEdge(inlineInfo);
    boolean partialIntrinsicExit = false;
    if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
        partialIntrinsicExit = true;
        ResolvedJavaMethod originalMethod = intrinsicContext.getOriginalMethod();
        BytecodeParser intrinsicCallSiteParser = getNonIntrinsicAncestor();
        if (intrinsicCallSiteParser != null) {
            // When exiting a partial intrinsic, the invoke to the original
            // must use the same context as the call to the intrinsic.
            invokeBci = intrinsicCallSiteParser.bci();
            profile = intrinsicCallSiteParser.getProfileForInvoke(invokeKind);
            edgeAction = intrinsicCallSiteParser.getActionForInvokeExceptionEdge(inlineInfo);
        } else {
            // so the bci must be set to unknown, so that the inliner patches it later.
            assert intrinsicContext.isPostParseInlined();
            invokeBci = BytecodeFrame.UNKNOWN_BCI;
            profile = null;
            edgeAction = graph.method().getAnnotation(Snippet.class) == null ? ExceptionEdgeAction.INCLUDE_AND_HANDLE : ExceptionEdgeAction.OMIT;
        }
        if (originalMethod.isStatic()) {
            invokeKind = InvokeKind.Static;
        } else {
            // The original call to the intrinsic must have been devirtualized
            // otherwise we wouldn't be here.
            invokeKind = InvokeKind.Special;
        }
        Signature sig = originalMethod.getSignature();
        returnType = sig.getReturnType(method.getDeclaringClass());
        resultType = sig.getReturnKind();
        assert intrinsicContext.allowPartialIntrinsicArgumentMismatch() || checkPartialIntrinsicExit(intrinsicCallSiteParser == null ? null : intrinsicCallSiteParser.currentInvoke.args, args);
        targetMethod = originalMethod;
    }
    Invoke invoke = createNonInlinedInvoke(edgeAction, invokeBci, args, targetMethod, invokeKind, resultType, returnType, profile);
    if (partialIntrinsicExit) {
        // This invoke must never be later inlined as it might select the intrinsic graph.
        // Until there is a mechanism to guarantee that any late inlining will not select
        // the intrinsic graph, prevent this invoke from being inlined.
        invoke.setUseForInlining(false);
    }
    return invoke;
}
Also used : InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) Snippet(org.graalvm.compiler.api.replacements.Snippet) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ResolveClassBeforeStaticInvoke(org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke) Invoke(org.graalvm.compiler.nodes.Invoke) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile) Signature(jdk.vm.ci.meta.Signature) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

InlineInfo (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 JavaType (jdk.vm.ci.meta.JavaType)1 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)1 Signature (jdk.vm.ci.meta.Signature)1 Snippet (org.graalvm.compiler.api.replacements.Snippet)1 ResolveClassBeforeStaticInvoke (org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke)1 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)1 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InlineInvokePlugin (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin)1 InlineInfo.createStandardInlineInfo (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo)1 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)1 VirtualInstanceNode (org.graalvm.compiler.nodes.virtual.VirtualInstanceNode)1 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)1