Search in sources :

Example 21 with LoopExitNode

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

the class DeoptimizationGroupingPhase method exitLoops.

private static void exitLoops(AbstractDeoptimizeNode deopt, EndNode end, ControlFlowGraph cfg) {
    Block block = cfg.blockFor(deopt);
    Loop<Block> loop = block.getLoop();
    while (loop != null) {
        end.graph().addBeforeFixed(end, end.graph().add(new LoopExitNode((LoopBeginNode) loop.getHeader().getBeginNode())));
        loop = loop.getParent();
    }
}
Also used : LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 22 with LoopExitNode

use of org.graalvm.compiler.nodes.LoopExitNode 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)

Example 23 with LoopExitNode

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

the class ComputeInliningRelevance method createLoopScope.

/**
 * Determines the parent of the given loop and creates a {@link Scope} object for each one. This
 * method will call itself recursively if no {@link Scope} for the parent loop exists.
 */
private Scope createLoopScope(LoopBeginNode loopBegin, EconomicMap<LoopBeginNode, Scope> loops, Scope topScope) {
    Scope scope = loops.get(loopBegin);
    if (scope == null) {
        final Scope parent;
        // look for the parent scope
        FixedNode current = loopBegin.forwardEnd();
        while (true) {
            if (current.predecessor() == null) {
                if (current instanceof LoopBeginNode) {
                    // if we reach a LoopBeginNode then we're within this loop
                    parent = createLoopScope((LoopBeginNode) current, loops, topScope);
                    break;
                } else if (current instanceof StartNode) {
                    // we're within the outermost scope
                    parent = topScope;
                    break;
                } else {
                    assert current instanceof MergeNode : current;
                    // follow any path upwards - it doesn't matter which one
                    current = ((AbstractMergeNode) current).forwardEndAt(0);
                }
            } else if (current instanceof LoopExitNode) {
                // if we reach a loop exit then we follow this loop and have the same parent
                parent = createLoopScope(((LoopExitNode) current).loopBegin(), loops, topScope).parent;
                break;
            } else {
                current = (FixedNode) current.predecessor();
            }
        }
        scope = new Scope(loopBegin, parent);
        loops.put(loopBegin, scope);
    }
    return scope;
}
Also used : AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) StartNode(org.graalvm.compiler.nodes.StartNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode)

Example 24 with LoopExitNode

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

the class ReentrantNodeIterator method processLoop.

public static <StateT> LoopInfo<StateT> processLoop(NodeIteratorClosure<StateT> closure, LoopBeginNode loop, StateT initialState) {
    EconomicMap<FixedNode, StateT> blockEndStates = apply(closure, loop, initialState, loop);
    LoopInfo<StateT> info = new LoopInfo<>(loop.loopEnds().count(), loop.loopExits().count());
    for (LoopEndNode end : loop.loopEnds()) {
        if (blockEndStates.containsKey(end)) {
            info.endStates.put(end, blockEndStates.get(end));
        }
    }
    for (LoopExitNode exit : loop.loopExits()) {
        if (blockEndStates.containsKey(exit)) {
            info.exitStates.put(exit, blockEndStates.get(exit));
        }
    }
    return info;
}
Also used : LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 25 with LoopExitNode

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

the class ScopedPostOrderNodeIterator method processScope.

public void processScope() {
    FixedNode current;
    queue(currentScopeStart);
    while ((current = nextQueuedNode()) != null) {
        assert current.isAlive();
        if (current instanceof Invoke) {
            invoke((Invoke) current);
            queueSuccessors(current);
        } else if (current instanceof LoopBeginNode) {
            queueLoopBeginSuccessors((LoopBeginNode) current);
        } else if (current instanceof LoopExitNode) {
            queueLoopExitSuccessors((LoopExitNode) current);
        } else if (current instanceof LoopEndNode) {
        // nothing todo
        } else if (current instanceof AbstractMergeNode) {
            queueSuccessors(current);
        } else if (current instanceof FixedWithNextNode) {
            queueSuccessors(current);
        } else if (current instanceof EndNode) {
            queueMerge((EndNode) current);
        } else if (current instanceof ControlSinkNode) {
        // nothing todo
        } else if (current instanceof ControlSplitNode) {
            queueSuccessors(current);
        } else {
            assert false : current;
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) Invoke(org.graalvm.compiler.nodes.Invoke) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Aggregations

LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)25 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)18 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)17 FixedNode (org.graalvm.compiler.nodes.FixedNode)16 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)14 Node (org.graalvm.compiler.graph.Node)13 EndNode (org.graalvm.compiler.nodes.EndNode)12 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)10 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)9 PhiNode (org.graalvm.compiler.nodes.PhiNode)9 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)9 MergeNode (org.graalvm.compiler.nodes.MergeNode)8 ArrayList (java.util.ArrayList)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)6 IfNode (org.graalvm.compiler.nodes.IfNode)6 FrameState (org.graalvm.compiler.nodes.FrameState)5