Search in sources :

Example 16 with DeadCodeEliminationPhase

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

the class ReplacementsParseTest method testGraph.

@SuppressWarnings("try")
private void testGraph(String name) {
    StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
    try (DebugContext.Scope s0 = graph.getDebug().scope(name, graph)) {
        for (OpaqueNode node : graph.getNodes().filter(OpaqueNode.class)) {
            node.replaceAndDelete(node.getValue());
        }
        HighTierContext context = getDefaultHighTierContext();
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        new FloatingReadPhase().apply(graph);
        canonicalizer.apply(graph, context);
        new DeadCodeEliminationPhase().apply(graph);
        new GuardLoweringPhase().apply(graph, getDefaultMidTierContext());
        new FrameStateAssignmentPhase().apply(graph);
    } catch (Throwable e) {
        throw graph.getDebug().handle(e);
    }
}
Also used : FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase)

Example 17 with DeadCodeEliminationPhase

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

the class MethodSubstitutionTest method testGraph.

@SuppressWarnings("try")
protected StructuredGraph testGraph(final String snippet, String name) {
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("MethodSubstitutionTest", getResolvedJavaMethod(snippet))) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
        HighTierContext context = getDefaultHighTierContext();
        debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
        new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
        debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
        new CanonicalizerPhase().apply(graph, context);
        new DeadCodeEliminationPhase().apply(graph);
        // Try to ensure any macro nodes are lowered to expose any resulting invokes
        if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
            new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        }
        if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
            new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
        }
        assertNotInGraph(graph, MacroNode.class);
        if (name != null) {
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    if (invoke.callTarget() instanceof MethodCallTargetNode) {
                        MethodCallTargetNode call = (MethodCallTargetNode) invoke.callTarget();
                        assertTrue(!call.targetMethod().getName().equals(name), "Unexpected invoke of intrinsic %s", call.targetMethod());
                    }
                }
            }
        } else {
            assertNotInGraph(graph, Invoke.class);
        }
        return graph;
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : MacroNode(org.graalvm.compiler.replacements.nodes.MacroNode) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) Invoke(org.graalvm.compiler.nodes.Invoke) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MacroNode(org.graalvm.compiler.replacements.nodes.MacroNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) 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 18 with DeadCodeEliminationPhase

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

the class PartialEscapeAnalysisTest method testPartialEscapeAnalysis.

@SafeVarargs
protected final void testPartialEscapeAnalysis(String snippet, double expectedProbability, int expectedCount, Class<? extends Node>... invalidNodeClasses) {
    prepareGraph(snippet, false);
    for (AbstractMergeNode merge : graph.getNodes(AbstractMergeNode.TYPE)) {
        merge.setStateAfter(null);
    }
    new DeadCodeEliminationPhase().apply(graph);
    new CanonicalizerPhase().apply(graph, context);
    try {
        Assert.assertTrue("partial escape analysis should have removed all NewInstanceNode allocations", graph.getNodes().filter(NewInstanceNode.class).isEmpty());
        Assert.assertTrue("partial escape analysis should have removed all NewArrayNode allocations", graph.getNodes().filter(NewArrayNode.class).isEmpty());
        ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
        double probabilitySum = 0;
        int materializeCount = 0;
        for (CommitAllocationNode materialize : graph.getNodes().filter(CommitAllocationNode.class)) {
            probabilitySum += cfg.blockFor(materialize).probability() * materialize.getVirtualObjects().size();
            materializeCount += materialize.getVirtualObjects().size();
        }
        Assert.assertEquals("unexpected number of MaterializeObjectNodes", expectedCount, materializeCount);
        Assert.assertEquals("unexpected probability of MaterializeObjectNodes", expectedProbability, probabilitySum, 0.01);
        for (Node node : graph.getNodes()) {
            for (Class<? extends Node> clazz : invalidNodeClasses) {
                Assert.assertFalse("instance of invalid class: " + clazz.getSimpleName(), clazz.isInstance(node) && node.usages().isNotEmpty());
            }
        }
    } catch (AssertionError e) {
        TypeSystemTest.outputGraph(graph, snippet + ": " + e.getMessage());
        throw e;
    }
}
Also used : ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode)

Example 19 with DeadCodeEliminationPhase

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

the class NestedLoopEffectsPhaseComplexityTest method parseBytecodes.

private StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer) {
    OptionValues options = getInitialOptions();
    StructuredGraph newGraph = new StructuredGraph.Builder(options, getDebugContext(options, null, method), AllowAssumptions.NO).method(method).build();
    context.getGraphBuilderSuite().apply(newGraph, context);
    new DeadCodeEliminationPhase(Optional).apply(newGraph);
    canonicalizer.apply(newGraph, context);
    return newGraph;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 20 with DeadCodeEliminationPhase

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

the class CompiledMethodTest method test1.

/**
 * Usages of the constant {@code " "} are replaced with the constant {@code "-"} and it is
 * verified that executing the compiled code produces a result that the preserves the node
 * replacement unless deoptimization occurs (e.g., due to -Xcomp causing profiles to be
 * missing).
 */
@Test
public void test1() {
    final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
    final StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.NO);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new DeadCodeEliminationPhase().apply(graph);
    for (ConstantNode node : ConstantNode.getConstantNodes(graph)) {
        if (node.getStackKind() == JavaKind.Object && " ".equals(getSnippetReflection().asObject(String.class, node.asJavaConstant()))) {
            node.replace(graph, ConstantNode.forConstant(getSnippetReflection().forObject("-"), getMetaAccess(), graph));
        }
    }
    InstalledCode compiledMethod = getCode(javaMethod, graph);
    try {
        Object result = compiledMethod.executeVarargs("1", "2", "3");
        if (!"1-2-3".equals(result)) {
            // Deoptimization probably occurred
            Assert.assertEquals("interpreter", result);
        }
    } catch (InvalidInstalledCodeException t) {
        Assert.fail("method invalidated");
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvalidInstalledCodeException(jdk.vm.ci.code.InvalidInstalledCodeException) InstalledCode(jdk.vm.ci.code.InstalledCode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

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