Search in sources :

Example 21 with LoweringPhase

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

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

Example 23 with LoweringPhase

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

the class UnsafeReadEliminationTest method testEarlyReadElimination.

public void testEarlyReadElimination(StructuredGraph graph, int reads, int writes) {
    PhaseContext context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new EarlyReadEliminationPhase(canonicalizer).apply(graph, context);
    Assert.assertEquals(3, graph.getNodes().filter(UnsafeAccessNode.class).count());
    // after lowering the same applies for reads and writes
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new EarlyReadEliminationPhase(canonicalizer).apply(graph, context);
    Assert.assertEquals(reads, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals(writes, graph.getNodes().filter(WriteNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) EarlyReadEliminationPhase(org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase)

Example 24 with LoweringPhase

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

the class SchedulingTest2 method testValueProxyInputs.

@Test
public void testValueProxyInputs() {
    StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
    BeginNode beginNode = graph.add(new BeginNode());
    returnNode.replaceAtPredecessor(beginNode);
    beginNode.setNext(returnNode);
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
    schedulePhase.apply(graph);
    ScheduleResult schedule = graph.getLastSchedule();
    BlockMap<List<Node>> blockToNodesMap = schedule.getBlockToNodesMap();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    assertDeepEquals(2, schedule.getCFG().getBlocks().length);
    for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
        if (node instanceof AddNode) {
            assertTrue(node.toString() + " expected: " + nodeToBlock.get(beginNode) + " but was: " + nodeToBlock.get(node), nodeToBlock.get(node) != nodeToBlock.get(beginNode));
        }
    }
    for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
        Block block = nodeToBlock.get(fs);
        assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
        for (Node usage : fs.usages()) {
            if (usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) {
                assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
                if (usage != block.getBeginNode()) {
                    List<Node> map = blockToNodesMap.get(block);
                    assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
                }
            }
        }
    }
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
    MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
    new GuardLoweringPhase().apply(graph, midContext);
    FrameStateAssignmentPhase phase = new FrameStateAssignmentPhase();
    phase.apply(graph);
    schedulePhase.apply(graph);
    schedule = graph.getLastSchedule();
    blockToNodesMap = schedule.getBlockToNodesMap();
    nodeToBlock = schedule.getNodeToBlockMap();
    for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
        Block block = nodeToBlock.get(fs);
        assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
        for (Node usage : fs.usages()) {
            if ((usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) || (usage instanceof DeoptDuring && ((DeoptDuring) usage).stateDuring() == fs)) {
                assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
                if (usage != block.getBeginNode()) {
                    List<Node> map = blockToNodesMap.get(block);
                    assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
                }
            }
        }
    }
}
Also used : FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) AddNode(org.graalvm.compiler.nodes.calc.AddNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) Node(org.graalvm.compiler.graph.Node) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptDuring(org.graalvm.compiler.nodes.DeoptimizingNode.DeoptDuring) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) StateSplit(org.graalvm.compiler.nodes.StateSplit) Test(org.junit.Test)

Example 25 with LoweringPhase

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

the class PushNodesThroughPiTest method compileTestSnippet.

private StructuredGraph compileTestSnippet(final String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    canonicalizer.apply(graph, context);
    return graph;
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Aggregations

LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)31 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)30 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)27 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)19 DebugContext (org.graalvm.compiler.debug.DebugContext)13 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)12 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)12 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)10 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)8 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)7 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)6 Test (org.junit.Test)6 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)5 Node (org.graalvm.compiler.graph.Node)5 OptionValues (org.graalvm.compiler.options.OptionValues)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 FrameStateAssignmentPhase (org.graalvm.compiler.phases.common.FrameStateAssignmentPhase)4 List (java.util.List)3 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)3 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)3