Search in sources :

Example 16 with SchedulePhase

use of org.graalvm.compiler.phases.schedule.SchedulePhase 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 17 with SchedulePhase

use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.

the class ConditionalEliminationTestBase method testProxies.

public void testProxies(String snippet, int expectedProxiesCreated) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
    canonicalizer1.disableSimplification();
    canonicalizer1.apply(graph, context);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    int baseProxyCount = graph.getNodes().filter(ProxyNode.class).count();
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    new SchedulePhase(graph.getOptions()).apply(graph, context);
    int actualProxiesCreated = graph.getNodes().filter(ProxyNode.class).count() - baseProxyCount;
    Assert.assertEquals(expectedProxiesCreated, actualProxiesCreated);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 18 with SchedulePhase

use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.

the class EscapeAnalysisTest method testPeeledLoop.

@Test
public void testPeeledLoop() {
    prepareGraph("testPeeledLoopSnippet", false);
    new LoopPeelingPhase(new DefaultLoopPolicies()).apply(graph, getDefaultHighTierContext());
    new SchedulePhase(graph.getOptions()).apply(graph);
}
Also used : LoopPeelingPhase(org.graalvm.compiler.loop.phases.LoopPeelingPhase) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) DefaultLoopPolicies(org.graalvm.compiler.loop.DefaultLoopPolicies) Test(org.junit.Test)

Example 19 with SchedulePhase

use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.

the class GuardLoweringPhase method run.

@Override
protected void run(StructuredGraph graph, MidTierContext context) {
    if (graph.getGuardsStage().allowsFloatingGuards()) {
        SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
        schedulePhase.apply(graph);
        ScheduleResult schedule = graph.getLastSchedule();
        for (Block block : schedule.getCFG().getBlocks()) {
            processBlock(block, schedule);
        }
        graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
    }
    assert assertNoGuardsLeft(graph);
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 20 with SchedulePhase

use of org.graalvm.compiler.phases.schedule.SchedulePhase in project graal by oracle.

the class GraphPrinter method getScheduleOrNull.

@SuppressWarnings("try")
static StructuredGraph.ScheduleResult getScheduleOrNull(Graph graph) {
    if (graph instanceof StructuredGraph) {
        StructuredGraph sgraph = (StructuredGraph) graph;
        StructuredGraph.ScheduleResult scheduleResult = sgraph.getLastSchedule();
        if (scheduleResult == null) {
            DebugContext debug = graph.getDebug();
            try (Scope scope = debug.disable()) {
                SchedulePhase schedule = new SchedulePhase(graph.getOptions());
                schedule.apply(sgraph);
                scheduleResult = sgraph.getLastSchedule();
            } catch (Throwable t) {
            }
        }
        return scheduleResult;
    }
    return null;
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Scope(org.graalvm.compiler.debug.DebugContext.Scope) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)20 Block (org.graalvm.compiler.nodes.cfg.Block)10 Node (org.graalvm.compiler.graph.Node)9 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)8 ScheduleResult (org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult)8 DebugContext (org.graalvm.compiler.debug.DebugContext)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)4 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 ControlFlowGraph (org.graalvm.compiler.nodes.cfg.ControlFlowGraph)4 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)4 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)3 FrameState (org.graalvm.compiler.nodes.FrameState)3 FullInfopointNode (org.graalvm.compiler.nodes.FullInfopointNode)3