Search in sources :

Example 1 with IterativeConditionalEliminationPhase

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

the class ConditionalEliminationTest14 method test1.

@Test
public void test1() {
    StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    /* Convert the LoadIndexNode to ReadNode with floating guards. */
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    /* Convert the ReadNode to FloatingReadNode. */
    new FloatingReadPhase().apply(graph);
    /* Apply the phase that we want to test. */
    new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
    Assert.assertEquals("All guards must be floating", 0, graph.getNodes(FixedGuardNode.TYPE).count());
    Assert.assertEquals("All array accesses must have been lowered", 0, graph.getNodes().filter(LoadIndexedNode.class).count());
    Assert.assertEquals("All reads must be floating", 0, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals("Must have floating reads (3 array accesses, 1 array length)", 4, graph.getNodes().filter(FloatingReadNode.class).count());
    NodeIterable<GuardNode> boundsChecks = graph.getNodes(GuardNode.TYPE).filter(n -> ((GuardNode) n).getReason() == DeoptimizationReason.BoundsCheckException);
    Assert.assertEquals("Must have only 1 bounds check remaining", 1, boundsChecks.count());
    LogicNode condition = boundsChecks.first().getCondition();
    Assert.assertTrue("Bounds check must check for array length 8", condition instanceof IntegerBelowNode && ((IntegerBelowNode) condition).getY().valueEquals(ConstantNode.forInt(8)));
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) LogicNode(org.graalvm.compiler.nodes.LogicNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) Test(org.junit.Test)

Example 2 with IterativeConditionalEliminationPhase

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

the class IfNodeCanonicalizationTest method test.

public void test(String name, Class<? extends Node> expectedClass, int expectedCount) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    new ConvertDeoptimizeToGuardPhase().apply(graph, context);
    graph.clearAllStateAfter();
    graph.setGuardsStage(StructuredGraph.GuardsStage.AFTER_FSA);
    canonicalizer.apply(graph, context);
    // new DominatorConditionalEliminationPhase(true).apply(graph, context);
    new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
    canonicalizer.apply(graph, context);
    canonicalizer.apply(graph, context);
    Assert.assertEquals(expectedCount, graph.getNodes().filter(expectedClass).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase)

Example 3 with IterativeConditionalEliminationPhase

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

the class ConditionalEliminationTestBase method testConditionalElimination.

@SuppressWarnings("try")
protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) {
        prepareGraph(graph, canonicalizer1, context, applyLowering);
        new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
        canonicalizer.apply(graph, context);
        canonicalizer.apply(graph, context);
    } catch (Throwable t) {
        debug.handle(t);
    }
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
    try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest.ReferenceGraph", referenceGraph)) {
        prepareGraph(referenceGraph, canonicalizer, context, applyLowering);
        if (applyConditionalEliminationOnReference) {
            new ConditionalEliminationPhase(true).apply(referenceGraph, context);
        }
        canonicalizer.apply(referenceGraph, context);
        canonicalizer.apply(referenceGraph, context);
    } catch (Throwable t) {
        debug.handle(t);
    }
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)3 IterativeConditionalEliminationPhase (org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase)3 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)3 DebugContext (org.graalvm.compiler.debug.DebugContext)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 GuardNode (org.graalvm.compiler.nodes.GuardNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 IntegerBelowNode (org.graalvm.compiler.nodes.calc.IntegerBelowNode)1 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)1 ConvertDeoptimizeToGuardPhase (org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase)1 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)1 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)1 Test (org.junit.Test)1