Search in sources :

Example 11 with SchedulePhase

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

the class GraalCompilerTest method getCanonicalGraphString.

protected static String getCanonicalGraphString(StructuredGraph graph, boolean excludeVirtual, boolean checkConstants) {
    SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.EARLIEST);
    schedule.apply(graph);
    ScheduleResult scheduleResult = graph.getLastSchedule();
    NodeMap<Integer> canonicalId = graph.createNodeMap();
    int nextId = 0;
    List<String> constantsLines = new ArrayList<>();
    StringBuilder result = new StringBuilder();
    for (Block block : scheduleResult.getCFG().getBlocks()) {
        result.append("Block ").append(block).append(' ');
        if (block == scheduleResult.getCFG().getStartBlock()) {
            result.append("* ");
        }
        result.append("-> ");
        for (Block succ : block.getSuccessors()) {
            result.append(succ).append(' ');
        }
        result.append('\n');
        for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
            if (node instanceof ValueNode && node.isAlive()) {
                if (!excludeVirtual || !(node instanceof VirtualObjectNode || node instanceof ProxyNode || node instanceof FullInfopointNode || node instanceof ParameterNode)) {
                    if (node instanceof ConstantNode) {
                        String name = checkConstants ? node.toString(Verbosity.Name) : node.getClass().getSimpleName();
                        if (excludeVirtual) {
                            constantsLines.add(name);
                        } else {
                            constantsLines.add(name + "    (" + filteredUsageCount(node) + ")");
                        }
                    } else {
                        int id;
                        if (canonicalId.get(node) != null) {
                            id = canonicalId.get(node);
                        } else {
                            id = nextId++;
                            canonicalId.set(node, id);
                        }
                        String name = node.getClass().getSimpleName();
                        result.append("  ").append(id).append('|').append(name);
                        if (node instanceof AccessFieldNode) {
                            result.append('#');
                            result.append(((AccessFieldNode) node).field());
                        }
                        if (!excludeVirtual) {
                            result.append("    (");
                            result.append(filteredUsageCount(node));
                            result.append(')');
                        }
                        result.append('\n');
                    }
                }
            }
        }
    }
    StringBuilder constantsLinesResult = new StringBuilder();
    constantsLinesResult.append(constantsLines.size()).append(" constants:\n");
    Collections.sort(constantsLines);
    for (String s : constantsLines) {
        constantsLinesResult.append(s);
        constantsLinesResult.append('\n');
    }
    return constantsLinesResult.toString() + result.toString();
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) BreakpointNode(org.graalvm.compiler.nodes.BreakpointNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ArrayList(java.util.ArrayList) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 12 with SchedulePhase

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

the class GraalCompilerTest method getScheduledGraphString.

/**
 * @param graph
 * @return a scheduled textual dump of {@code graph} .
 */
protected static String getScheduledGraphString(StructuredGraph graph) {
    SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
    schedule.apply(graph);
    ScheduleResult scheduleResult = graph.getLastSchedule();
    StringBuilder result = new StringBuilder();
    Block[] blocks = scheduleResult.getCFG().getBlocks();
    for (Block block : blocks) {
        result.append("Block ").append(block).append(' ');
        if (block == scheduleResult.getCFG().getStartBlock()) {
            result.append("* ");
        }
        result.append("-> ");
        for (Block succ : block.getSuccessors()) {
            result.append(succ).append(' ');
        }
        result.append('\n');
        for (Node node : scheduleResult.getBlockToNodesMap().get(block)) {
            result.append(String.format("%1S\n", node));
        }
    }
    return result.toString();
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) BreakpointNode(org.graalvm.compiler.nodes.BreakpointNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 13 with SchedulePhase

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

the class GraphScheduleTest method assertOrderedAfterSchedule.

protected void assertOrderedAfterSchedule(StructuredGraph graph, SchedulePhase.SchedulingStrategy strategy, Node a, Node b) {
    SchedulePhase ibp = new SchedulePhase(strategy);
    ibp.apply(graph);
    assertOrderedAfterLastSchedule(graph, a, b);
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase)

Example 14 with SchedulePhase

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

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

the class SchedulingTest method testValueProxyInputs.

@Test
public void testValueProxyInputs() {
    StructuredGraph graph = parseEager("testValueProxyInputsSnippet", AllowAssumptions.YES);
    for (FrameState fs : graph.getNodes().filter(FrameState.class).snapshot()) {
        fs.replaceAtUsages(null);
        GraphUtil.killWithUnusedFloatingInputs(fs);
    }
    SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST);
    schedulePhase.apply(graph);
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getCFG().getNodeToBlock();
    assertTrue(graph.getNodes().filter(LoopExitNode.class).count() == 1);
    LoopExitNode loopExit = graph.getNodes().filter(LoopExitNode.class).first();
    List<Node> list = schedule.nodesFor(nodeToBlock.get(loopExit));
    for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
        if (!(node instanceof AddNode)) {
            assertTrue(node.toString(), nodeToBlock.get(node) == nodeToBlock.get(loopExit));
            assertTrue(list.indexOf(node) + " < " + list.indexOf(loopExit) + ", " + node + ", " + loopExit, list.indexOf(node) < list.indexOf(loopExit));
        }
    }
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) Node(org.graalvm.compiler.graph.Node) Block(org.graalvm.compiler.nodes.cfg.Block) FrameState(org.graalvm.compiler.nodes.FrameState) AddNode(org.graalvm.compiler.nodes.calc.AddNode) Test(org.junit.Test)

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