Search in sources :

Example 11 with ControlFlowGraph

use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.

the class GraalCompilerState method preLIRGeneration.

/**
 * Sets up {@link LIR} generation.
 */
protected final void preLIRGeneration() {
    assert request.graph.isFrozen() : "Graph not frozen.";
    Object stub = null;
    schedule = request.graph.getLastSchedule();
    ControlFlowGraph cfg = deepCopy(schedule.getCFG());
    Block[] blocks = cfg.getBlocks();
    Block startBlock = cfg.getStartBlock();
    assert startBlock != null;
    assert startBlock.getPredecessorCount() == 0;
    codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
    linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
    LIR lir = new LIR(cfg, linearScanOrder, codeEmittingOrder, getGraphOptions(), getGraphDebug());
    FrameMapBuilder frameMapBuilder = request.backend.newFrameMapBuilder(registerConfig);
    lirGenRes = request.backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, request.graph, stub);
    lirGenTool = request.backend.newLIRGenerator(lirGenRes);
    nodeLirGen = request.backend.newNodeLIRBuilder(request.graph, lirGenTool);
}
Also used : LIR(org.graalvm.compiler.lir.LIR) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 12 with ControlFlowGraph

use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.

the class EffectsPhase method runAnalysis.

@SuppressWarnings("try")
public boolean runAnalysis(StructuredGraph graph, PhaseContextT context) {
    boolean changed = false;
    CompilationAlarm compilationAlarm = CompilationAlarm.current();
    DebugContext debug = graph.getDebug();
    for (int iteration = 0; iteration < maxIterations && !compilationAlarm.hasExpired(); iteration++) {
        try (DebugContext.Scope s = debug.scope(debug.areScopesEnabled() ? "iteration " + iteration : null)) {
            ScheduleResult schedule;
            ControlFlowGraph cfg;
            if (unscheduled) {
                schedule = null;
                cfg = ControlFlowGraph.compute(graph, true, true, false, false);
            } else {
                new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST).apply(graph, false);
                schedule = graph.getLastSchedule();
                cfg = schedule.getCFG();
            }
            try (DebugContext.Scope scheduleScope = debug.scope("EffectsPhaseWithSchedule", schedule)) {
                Closure<?> closure = createEffectsClosure(context, schedule, cfg);
                ReentrantBlockIterator.apply(closure, cfg.getStartBlock());
                if (closure.needsApplyEffects()) {
                    // apply the effects collected during this iteration
                    HashSetNodeEventListener listener = new HashSetNodeEventListener();
                    try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
                        closure.applyEffects();
                    }
                    if (debug.isDumpEnabled(DebugContext.VERBOSE_LEVEL)) {
                        debug.dump(DebugContext.VERBOSE_LEVEL, graph, "%s iteration", getName());
                    }
                    new DeadCodeEliminationPhase(Required).apply(graph);
                    EconomicSet<Node> changedNodes = listener.getNodes();
                    for (Node node : graph.getNodes()) {
                        if (node instanceof Simplifiable) {
                            changedNodes.add(node);
                        }
                    }
                    postIteration(graph, context, changedNodes);
                }
                if (closure.hasChanged()) {
                    changed = true;
                } else {
                    break;
                }
            } catch (Throwable t) {
                throw debug.handle(t);
            }
        }
    }
    return changed;
}
Also used : ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) CompilationAlarm(org.graalvm.compiler.core.common.util.CompilationAlarm) Node(org.graalvm.compiler.graph.Node) DebugContext(org.graalvm.compiler.debug.DebugContext) HashSetNodeEventListener(org.graalvm.compiler.phases.common.util.HashSetNodeEventListener) NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) Simplifiable(org.graalvm.compiler.graph.spi.Simplifiable)

Example 13 with ControlFlowGraph

use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.

the class NestedLoopTest method test.

private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
    Assert.assertEquals(3, cfg.getLoops().size());
    Loop<Block> rootLoop = cfg.getLoops().get(0);
    Loop<Block> nestedLoop = cfg.getLoops().get(1);
    Loop<Block> innerMostLoop = cfg.getLoops().get(2);
    Invoke a = getInvoke("a", graph);
    Invoke b = getInvoke("b", graph);
    Invoke c = getInvoke("c", graph);
    Invoke d = getInvoke("d", graph);
    Assert.assertTrue(containsDirect(rootLoop, a, cfg));
    Assert.assertTrue(containsDirect(nestedLoop, b, cfg));
    Assert.assertTrue(containsDirect(innerMostLoop, c, cfg));
    Assert.assertTrue(containsDirect(innerMostLoop, d, cfg));
    Assert.assertTrue(contains(rootLoop, d, cfg));
    Assert.assertTrue(contains(nestedLoop, d, cfg));
    Assert.assertEquals(rootExits, rootLoop.getExits().size());
    Assert.assertEquals(nestedExits, nestedLoop.getExits().size());
    Assert.assertEquals(innerExits, innerMostLoop.getExits().size());
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) Block(org.graalvm.compiler.nodes.cfg.Block) DebugContext(org.graalvm.compiler.debug.DebugContext) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 14 with ControlFlowGraph

use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.

the class NodeLIRBuilder method getLIRBlock.

public LabelRef getLIRBlock(FixedNode b) {
    assert gen.getResult().getLIR().getControlFlowGraph() instanceof ControlFlowGraph;
    Block result = ((ControlFlowGraph) gen.getResult().getLIR().getControlFlowGraph()).blockFor(b);
    int suxIndex = 0;
    for (AbstractBlockBase<?> succ : gen.getCurrentBlock().getSuccessors()) {
        if (succ == result) {
            assert gen.getCurrentBlock() instanceof Block;
            return LabelRef.forSuccessor(gen.getResult().getLIR(), gen.getCurrentBlock(), suxIndex);
        }
        suxIndex++;
    }
    throw GraalError.shouldNotReachHere("Block not in successor list of current block");
}
Also used : ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) LIR.verifyBlock(org.graalvm.compiler.lir.LIR.verifyBlock) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 15 with ControlFlowGraph

use of org.graalvm.compiler.nodes.cfg.ControlFlowGraph in project graal by oracle.

the class PartialEscapeAnalysisTest method testPartialEscapeAnalysis.

@SafeVarargs
protected final void testPartialEscapeAnalysis(String snippet, double expectedProbability, int expectedCount, Class<? extends Node>... invalidNodeClasses) {
    prepareGraph(snippet, false);
    for (AbstractMergeNode merge : graph.getNodes(AbstractMergeNode.TYPE)) {
        merge.setStateAfter(null);
    }
    new DeadCodeEliminationPhase().apply(graph);
    new CanonicalizerPhase().apply(graph, context);
    try {
        Assert.assertTrue("partial escape analysis should have removed all NewInstanceNode allocations", graph.getNodes().filter(NewInstanceNode.class).isEmpty());
        Assert.assertTrue("partial escape analysis should have removed all NewArrayNode allocations", graph.getNodes().filter(NewArrayNode.class).isEmpty());
        ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
        double probabilitySum = 0;
        int materializeCount = 0;
        for (CommitAllocationNode materialize : graph.getNodes().filter(CommitAllocationNode.class)) {
            probabilitySum += cfg.blockFor(materialize).probability() * materialize.getVirtualObjects().size();
            materializeCount += materialize.getVirtualObjects().size();
        }
        Assert.assertEquals("unexpected number of MaterializeObjectNodes", expectedCount, materializeCount);
        Assert.assertEquals("unexpected probability of MaterializeObjectNodes", expectedProbability, probabilitySum, 0.01);
        for (Node node : graph.getNodes()) {
            for (Class<? extends Node> clazz : invalidNodeClasses) {
                Assert.assertFalse("instance of invalid class: " + clazz.getSimpleName(), clazz.isInstance(node) && node.usages().isNotEmpty());
            }
        }
    } catch (AssertionError e) {
        TypeSystemTest.outputGraph(graph, snippet + ": " + e.getMessage());
        throw e;
    }
}
Also used : ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode)

Aggregations

ControlFlowGraph (org.graalvm.compiler.nodes.cfg.ControlFlowGraph)17 Block (org.graalvm.compiler.nodes.cfg.Block)12 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 DebugContext (org.graalvm.compiler.debug.DebugContext)5 Node (org.graalvm.compiler.graph.Node)5 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)5 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)4 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)4 List (java.util.List)3 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)3 ArrayList (java.util.ArrayList)2 BlockMap (org.graalvm.compiler.core.common.cfg.BlockMap)2 NodeEventScope (org.graalvm.compiler.graph.Graph.NodeEventScope)2 LIR (org.graalvm.compiler.lir.LIR)2 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 EndNode (org.graalvm.compiler.nodes.EndNode)2 IfNode (org.graalvm.compiler.nodes.IfNode)2