Search in sources :

Example 6 with DeadCodeEliminationPhase

use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.

the class LockEliminationTest method getGraph.

private StructuredGraph getGraph(String snippet) {
    ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
    StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
    HighTierContext context = getDefaultHighTierContext();
    new CanonicalizerPhase().apply(graph, context);
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, context);
    new DeadCodeEliminationPhase().apply(graph);
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new LockEliminationPhase().apply(graph);
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) LockEliminationPhase(org.graalvm.compiler.phases.common.LockEliminationPhase) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 7 with DeadCodeEliminationPhase

use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase 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 DeadCodeEliminationPhase

use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.

the class GraphKit method inline.

/**
 * Inlines a given invocation to a method. The graph of the inlined method is processed in the
 * same manner as for snippets and method substitutions.
 */
public void inline(InvokeNode invoke) {
    ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Plugins plugins = new Plugins(graphBuilderPlugins);
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
    if (invoke.graph().trackNodeSourcePosition()) {
        calleeGraph.setTrackNodeSourcePosition();
    }
    IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
    GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
    instance.apply(calleeGraph);
    // Remove all frame states from inlinee
    calleeGraph.clearAllStateAfter();
    new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
    InliningUtil.inline(invoke, calleeGraph, false, method);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 9 with DeadCodeEliminationPhase

use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.

the class NoDeadCodeVerifyHandler method verify.

@Override
public void verify(DebugContext debug, Object object, String format, Object... args) {
    OptionValues options = debug.getOptions();
    if (Options.NDCV.getValue(options) != OFF && object instanceof StructuredGraph) {
        StructuredGraph graph = (StructuredGraph) object;
        List<Node> before = graph.getNodes().snapshot();
        new DeadCodeEliminationPhase().run(graph);
        List<Node> after = graph.getNodes().snapshot();
        assert after.size() <= before.size();
        if (before.size() != after.size()) {
            if (discovered.put(format, Boolean.TRUE) == null) {
                before.removeAll(after);
                String prefix = format == null ? "" : format + ": ";
                GraalError error = new GraalError("%sfound dead nodes in %s: %s", prefix, graph, before);
                if (Options.NDCV.getValue(options) == INFO) {
                    System.out.println(error.getMessage());
                } else if (Options.NDCV.getValue(options) == VERBOSE) {
                    error.printStackTrace(System.out);
                } else {
                    assert Options.NDCV.getValue(options) == FATAL;
                    throw error;
                }
            }
        }
    }
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) Node(org.graalvm.compiler.graph.Node) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 10 with DeadCodeEliminationPhase

use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.

the class BoxingEliminationTest method compareGraphs.

private void compareGraphs(final String snippet, final String referenceSnippet, final boolean loopPeeling, final boolean excludeVirtual) {
    graph = parseEager(snippet, AllowAssumptions.NO);
    HighTierContext context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    if (loopPeeling) {
        new LoopPeelingPhase(new DefaultLoopPolicies()).apply(graph, context);
    }
    new DeadCodeEliminationPhase().apply(graph);
    canonicalizer.apply(graph, context);
    new PartialEscapePhase(false, canonicalizer, graph.getOptions()).apply(graph, context);
    new DeadCodeEliminationPhase().apply(graph);
    canonicalizer.apply(graph, context);
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
    new InliningPhase(new CanonicalizerPhase()).apply(referenceGraph, context);
    new DeadCodeEliminationPhase().apply(referenceGraph);
    new CanonicalizerPhase().apply(referenceGraph, context);
    assertEquals(referenceGraph, graph, excludeVirtual, true);
}
Also used : LoopPeelingPhase(org.graalvm.compiler.loop.phases.LoopPeelingPhase) PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DefaultLoopPolicies(org.graalvm.compiler.loop.DefaultLoopPolicies) 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)

Aggregations

DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)23 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)16 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)16 DebugContext (org.graalvm.compiler.debug.DebugContext)11 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)10 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)9 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 Node (org.graalvm.compiler.graph.Node)6 Invoke (org.graalvm.compiler.nodes.Invoke)4 HashMap (java.util.HashMap)3 FrameState (org.graalvm.compiler.nodes.FrameState)3 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)3 InstalledCode (jdk.vm.ci.code.InstalledCode)2 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)2 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)2 LoopsData (org.graalvm.compiler.loop.LoopsData)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 Builder (org.graalvm.compiler.nodes.StructuredGraph.Builder)2