Search in sources :

Example 6 with FloatingReadPhase

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

the class FloatingReadTest method test.

@SuppressWarnings("try")
private void test(final String snippet) {
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
        PhaseContext context = new PhaseContext(getProviders());
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        new FloatingReadPhase().apply(graph);
        ReturnNode returnNode = null;
        MonitorExit monitorexit = null;
        for (Node n : graph.getNodes()) {
            if (n instanceof ReturnNode) {
                assert returnNode == null;
                returnNode = (ReturnNode) n;
            } else if (n instanceof MonitorExit) {
                monitorexit = (MonitorExit) n;
            }
        }
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After lowering");
        Assert.assertNotNull(returnNode);
        Assert.assertNotNull(monitorexit);
        Assert.assertTrue(returnNode.result() instanceof FloatingReadNode);
        FloatingReadNode read = (FloatingReadNode) returnNode.result();
        assertOrderedAfterSchedule(graph, read, (Node) monitorexit);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) Node(org.graalvm.compiler.graph.Node) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) MonitorExit(org.graalvm.compiler.nodes.extended.MonitorExit) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 7 with FloatingReadPhase

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

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

the class ConditionalEliminationTest2 method testRedundantCompares.

@Test
public void testRedundantCompares() {
    StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new FloatingReadPhase().apply(graph);
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    assertDeepEquals(1, graph.getNodes().filter(GuardNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) Test(org.junit.Test)

Example 9 with FloatingReadPhase

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

the class MemoryGraphCanonicalizeTest method testGraph.

public void testGraph(String name, int expectedWrites) {
    StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
    HighTierContext context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new IncrementalCanonicalizerPhase<>(canonicalizer, new FloatingReadPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, context);
    int writes = graph.getNodes().filter(WriteNode.class).count();
    assertTrue(writes == expectedWrites, "Expected %d writes, found %d", expectedWrites, writes);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) IncrementalCanonicalizerPhase(org.graalvm.compiler.phases.common.IncrementalCanonicalizerPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase)

Example 10 with FloatingReadPhase

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

the class MemoryScheduleTest method getFinalSchedule.

@SuppressWarnings("try")
private ScheduleResult getFinalSchedule(final String snippet, final TestMode mode, final SchedulingStrategy schedulingStrategy) {
    OptionValues options = new OptionValues(getInitialOptions(), OptScheduleOutOfLoops, schedulingStrategy == SchedulingStrategy.LATEST_OUT_OF_LOOPS, OptImplicitNullChecks, false);
    final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, options);
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope d = debug.scope("FloatingReadTest", graph)) {
        HighTierContext context = getDefaultHighTierContext();
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        canonicalizer.apply(graph, context);
        if (mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
            new InliningPhase(canonicalizer).apply(graph, context);
        }
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) {
            graph.clearAllStateAfter();
        }
        debug.dump(DebugContext.BASIC_LEVEL, graph, "after removal of framestates");
        new FloatingReadPhase().apply(graph);
        new RemoveValueProxyPhase().apply(graph);
        MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new GuardLoweringPhase().apply(graph, midContext);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, midContext);
        SchedulePhase schedule = new SchedulePhase(schedulingStrategy);
        schedule.apply(graph);
        assertDeepEquals(1, graph.getNodes().filter(StartNode.class).count());
        return graph.getLastSchedule();
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) OptionValues(org.graalvm.compiler.options.OptionValues) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase)

Aggregations

StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)12 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)12 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)12 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)12 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)7 DebugContext (org.graalvm.compiler.debug.DebugContext)6 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)5 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)4 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)3 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)3 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)3 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)3 Test (org.junit.Test)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)2 FrameStateAssignmentPhase (org.graalvm.compiler.phases.common.FrameStateAssignmentPhase)2 RemoveValueProxyPhase (org.graalvm.compiler.phases.common.RemoveValueProxyPhase)2 JavaKind (jdk.vm.ci.meta.JavaKind)1