Search in sources :

Example 11 with CanonicalizerPhase

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

the class ScalarTypeSystemTest method test.

private void test(final String snippet, final String referenceSnippet) {
    // No debug scope to reduce console noise for @Test(expected = ...) tests
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    PhaseContext context = new PhaseContext(getProviders());
    new CanonicalizerPhase().apply(graph, context);
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 12 with CanonicalizerPhase

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

the class StampCanonicalizerTest method testZeroReturn.

private void testZeroReturn(String methodName) {
    StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new DeadCodeEliminationPhase().apply(graph);
    assertConstantReturn(graph, 0);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 13 with CanonicalizerPhase

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

the class EarlyReadEliminationTest method processMethod.

protected StructuredGraph processMethod(String snippet, boolean doLowering) {
    StructuredGraph graph = parseEager(getResolvedJavaMethod(snippet), AllowAssumptions.NO);
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    if (doLowering) {
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    }
    new EarlyReadEliminationPhase(new CanonicalizerPhase()).apply(graph, context);
    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) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) EarlyReadEliminationPhase(org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase)

Example 14 with CanonicalizerPhase

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

the class EscapeAnalysisTest method testRemovalSpecialCase.

/**
 * Test the case where allocations before and during a loop that have no usages other than their
 * phi need to be recognized as an important change. This needs a loop so that the allocation is
 * not trivially removed by dead code elimination.
 */
@Test
public void testRemovalSpecialCase() {
    prepareGraph("testRemovalSpecialCaseSnippet", false);
    Assert.assertEquals(2, graph.getNodes().filter(CommitAllocationNode.class).count());
    // create the situation by removing the if
    graph.replaceFixedWithFloating(graph.getNodes().filter(LoadFieldNode.class).first(), graph.unique(ConstantNode.forInt(0)));
    new CanonicalizerPhase().apply(graph, context);
    // verify that an additional run removes all allocations
    new PartialEscapePhase(false, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
    Assert.assertEquals(0, graph.getNodes().filter(CommitAllocationNode.class).count());
}
Also used : PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Test(org.junit.Test)

Example 15 with CanonicalizerPhase

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

the class EscapeAnalysisTest method testChangeHandling.

/**
 * Tests that a graph with allocations that does not make progress during PEA will not be
 * changed.
 */
@Test
public void testChangeHandling() {
    prepareGraph("testChangeHandlingSnippet", false);
    Assert.assertEquals(2, graph.getNodes().filter(CommitAllocationNode.class).count());
    Assert.assertEquals(1, graph.getNodes().filter(BoxNode.class).count());
    List<Node> nodes = graph.getNodes().snapshot();
    // verify that an additional run doesn't add or remove nodes
    new PartialEscapePhase(false, false, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
    Assert.assertEquals(nodes.size(), graph.getNodeCount());
    for (Node node : nodes) {
        Assert.assertTrue(node.isAlive());
    }
}
Also used : PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) Node(org.graalvm.compiler.graph.Node) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Test(org.junit.Test)

Aggregations

CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)114 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)98 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)60 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)48 DebugContext (org.graalvm.compiler.debug.DebugContext)34 Test (org.junit.Test)33 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)31 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)27 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)16 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)14 Node (org.graalvm.compiler.graph.Node)12 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)12 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)10 OptionValues (org.graalvm.compiler.options.OptionValues)10 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)10 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)9 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)9 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)8 Invoke (org.graalvm.compiler.nodes.Invoke)8