Search in sources :

Example 6 with Invoke

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

the class NestedLoopEffectsPhaseComplexityTest method prepareGraph.

private StructuredGraph prepareGraph(String snippet, int inliningCount) {
    ResolvedJavaMethod callerMethod = getResolvedJavaMethod(snippet);
    StructuredGraph callerGraph = parseEager(callerMethod, AllowAssumptions.YES);
    PhaseSuite<HighTierContext> graphBuilderSuite = getDefaultGraphBuilderSuite();
    HighTierContext context = new HighTierContext(getProviders(), graphBuilderSuite, OptimisticOptimizations.ALL);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    Invoke next = callerGraph.getNodes(MethodCallTargetNode.TYPE).first().invoke();
    StructuredGraph calleeGraph = parseBytecodes(next.callTarget().targetMethod(), context, canonicalizer);
    ResolvedJavaMethod calleeMethod = next.callTarget().targetMethod();
    for (int i = 0; i < inliningCount; i++) {
        next = callerGraph.getNodes(MethodCallTargetNode.TYPE).first().invoke();
        EconomicSet<Node> canonicalizeNodes = InliningUtil.inlineForCanonicalization(next, calleeGraph, false, calleeMethod);
        canonicalizer.applyIncremental(callerGraph, context, canonicalizeNodes);
        callerGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, callerGraph, "After inlining %s into %s iteration %d", calleeMethod, callerMethod, i);
    }
    return callerGraph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 7 with Invoke

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

the class MonitorGraphTest method parseAndProcess.

private StructuredGraph parseAndProcess(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    ParameterNode param = graph.getNodes(ParameterNode.TYPE).first();
    if (param != null) {
        ConstantNode constant = ConstantNode.forInt(0, graph);
        for (Node n : param.usages().snapshot()) {
            if (!(n instanceof FrameState)) {
                n.replaceFirstInput(param, constant);
            }
        }
    }
    Map<Invoke, Double> hints = new HashMap<>();
    for (Invoke invoke : graph.getInvokes()) {
        hints.put(invoke, 1000d);
    }
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(hints, new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, context);
    new DeadCodeEliminationPhase().apply(graph);
    return graph;
}
Also used : HashMap(java.util.HashMap) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) FrameState(org.graalvm.compiler.nodes.FrameState) Invoke(org.graalvm.compiler.nodes.Invoke) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 8 with Invoke

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

the class AnalysisMethodCalleeWalker method walkCallees.

/**
 * Visit the callees of this method.
 */
VisitResult walkCallees(AnalysisMethod method, CallPathVisitor visitor) {
    final StructuredGraph graph = method.getTypeFlow().getGraph();
    if (graph != null) {
        for (Invoke invoke : graph.getInvokes()) {
            final CallTargetNode callTarget = invoke.callTarget();
            final AnalysisMethod callee = (AnalysisMethod) callTarget.targetMethod();
            walkMethodAndCallees(callee, method, invoke, visitor);
        }
    }
    return VisitResult.CONTINUE;
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Invoke(org.graalvm.compiler.nodes.Invoke) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode)

Example 9 with Invoke

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

the class CompileQueue method defaultParseFunction.

@SuppressWarnings("try")
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
    if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
        throw VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
    }
    HostedProviders providers = (HostedProviders) config.lookupBackend(method).getProviders();
    boolean needParsing = false;
    OptionValues options = HostedOptionValues.singleton();
    StructuredGraph graph = method.buildGraph(debug, method, providers, Purpose.AOT_COMPILATION);
    if (graph == null) {
        InvocationPlugin plugin = providers.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
        if (plugin != null && !plugin.inlineOnly()) {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            // DebugContext debug = new DebugContext(options, providers.getSnippetReflection());
            graph = new SubstrateIntrinsicGraphBuilder(debug.getOptions(), debug, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), code).buildGraph(plugin);
        }
    }
    if (graph == null && method.isNative() && NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        graph = DeletedMethod.buildGraph(debug, method, providers, DeletedMethod.NATIVE_MESSAGE);
    }
    if (graph == null) {
        needParsing = true;
        if (!method.compilationInfo.isDeoptTarget()) {
            /*
                 * Disabling liveness analysis preserves the values of local variables beyond the
                 * bytecode-liveness. This greatly helps debugging. When local variable numbers are
                 * reused by javac, local variables can still get illegal values. Since we cannot
                 * "restore" such illegal values during deoptimization, we must do liveness analysis
                 * for deoptimization target methods.
                 */
            options = new OptionValues(options, GraalOptions.OptClearNonLiveLocals, false);
        }
        graph = new StructuredGraph.Builder(options, debug).method(method).build();
    }
    try (DebugContext.Scope s = debug.scope("Parsing", graph, method, this)) {
        try {
            if (needParsing) {
                GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
                new HostedGraphBuilderPhase(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
            } else {
                graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
            }
            new DeadStoreRemovalPhase().apply(graph);
            new DevirtualizeCallsPhase().apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /*
                 * The StrengthenStampsPhase may not insert type check nodes for specialized
                 * methods, because we would get type state mismatches regarding Const<Type> !=
                 * <Type>
                 */
            /*
                 * cwimmer: the old, commented out, condition always disabled checking of static
                 * analysis results. Therefore, the checks are broken right now.
                 */
            // new StrengthenStampsPhase(BootImageOptions.CheckStaticAnalysisResults.getValue()
            // && method.compilationInfo.deoptTarget != null &&
            // !method.compilationInfo.isDeoptTarget).apply(graph);
            new StrengthenStampsPhase(false).apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /* Check that graph is in good shape after parsing. */
            assert GraphOrder.assertSchedulableGraph(graph);
            method.compilationInfo.graph = graph;
            for (Invoke invoke : graph.getInvokes()) {
                if (!canBeUsedForInlining(invoke)) {
                    invoke.setUseForInlining(false);
                }
                if (invoke.callTarget() instanceof MethodCallTargetNode) {
                    MethodCallTargetNode targetNode = (MethodCallTargetNode) invoke.callTarget();
                    HostedMethod invokeTarget = (HostedMethod) targetNode.targetMethod();
                    if (targetNode.invokeKind().isDirect()) {
                        if (invokeTarget.wrapped.isImplementationInvoked()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
                            ensureParsed(invokeTarget, new DirectCallReason(method, reason));
                        }
                    } else {
                        for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
                            ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
                        }
                    }
                }
            }
        } catch (Throwable ex) {
            GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
            error.addContext("method: " + method.format("%r %H.%n(%p)"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateIntrinsicGraphBuilder(com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder) HostedGraphBuilderPhase(com.oracle.svm.hosted.phases.HostedGraphBuilderPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Invoke(org.graalvm.compiler.nodes.Invoke) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) DevirtualizeCallsPhase(com.oracle.svm.hosted.phases.DevirtualizeCallsPhase) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 10 with Invoke

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

the class MustNotSynchronizeAnnotationChecker method synchronizesIndirectly.

/**
 * Does this method call a method that synchronizes?
 */
protected boolean synchronizesIndirectly(HostedMethod methodImpl) throws WarningException {
    boolean result = false;
    final StructuredGraph graph = methodImpl.compilationInfo.getGraph();
    if (graph != null) {
        for (Invoke invoke : graph.getInvokes()) {
            final HostedMethod callee = (HostedMethod) invoke.callTarget().targetMethod();
            if (invoke.callTarget().invokeKind().isDirect()) {
                result |= checkMethod(callee, callee);
                if (result) {
                    return result;
                }
            } else {
                for (HostedMethod calleeImpl : callee.getImplementations()) {
                    result |= checkMethod(callee, calleeImpl);
                    /* One violation is too many. */
                    if (result) {
                        return result;
                    }
                }
            }
        }
    }
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

Invoke (org.graalvm.compiler.nodes.Invoke)49 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 Node (org.graalvm.compiler.graph.Node)17 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)17 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 FixedNode (org.graalvm.compiler.nodes.FixedNode)13 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)12 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)10 FrameState (org.graalvm.compiler.nodes.FrameState)10 DebugContext (org.graalvm.compiler.debug.DebugContext)9 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 EndNode (org.graalvm.compiler.nodes.EndNode)7 GraalError (org.graalvm.compiler.debug.GraalError)6 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)6 ArrayList (java.util.ArrayList)5 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)5 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)5