Search in sources :

Example 21 with EndNode

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

the class NodePosIteratorTest method testSuccessors.

@Test
public void testSuccessors() {
    TestNode n = new TestNode();
    EndNode s1 = new EndNode();
    EndNode s2 = new EndNode();
    EndNode s3 = new EndNode();
    EndNode s4 = new EndNode();
    n.s1 = s1;
    n.s2 = s2;
    n.stail = new NodeSuccessorList<>(n, new Node[] { s3, s4 });
    NodeIterable<Node> successors = n.successors();
    Iterator<Node> iterator = successors.iterator();
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s1);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s2);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s3);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s4);
    Assert.assertFalse(iterator.hasNext());
    Assert.assertFalse(iterator.hasNext());
    Iterator<Position> positionIterator = n.successorPositions().iterator();
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals(Node.class.getSimpleName() + ":s1", positionIterator.next().toString());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals(Node.class.getSimpleName() + ":s2", positionIterator.next().toString());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals(NodeSuccessorList.class.getSimpleName() + ":stail[0]", positionIterator.next().toString());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals(NodeSuccessorList.class.getSimpleName() + ":stail[1]", positionIterator.next().toString());
    Assert.assertFalse(positionIterator.hasNext());
    Assert.assertFalse(positionIterator.hasNext());
    iterator = successors.iterator();
    n.s1 = s4;
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s4);
    n.s2 = s1;
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s1);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s3);
    n.stail.initialize(1, s4);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s4);
    Assert.assertFalse(iterator.hasNext());
    iterator = successors.iterator();
    n.s1 = null;
    n.s2 = s2;
    n.stail.initialize(0, null);
    n.stail.initialize(1, s4);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s2);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), s4);
    Assert.assertFalse(iterator.hasNext());
}
Also used : EndNode(org.graalvm.compiler.nodes.EndNode) Position(org.graalvm.compiler.graph.Position) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) Test(org.junit.Test)

Example 22 with EndNode

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

the class LoopTransformations method cleanupMerge.

/**
 * Cleanup the merge and remove the predecessors too.
 */
private static void cleanupMerge(AbstractMergeNode mergeNode, AbstractBeginNode landingNode) {
    for (EndNode end : mergeNode.cfgPredecessors().snapshot()) {
        mergeNode.removeEnd(end);
        end.safeDelete();
    }
    mergeNode.prepareDelete(landingNode);
    mergeNode.safeDelete();
}
Also used : AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) EndNode(org.graalvm.compiler.nodes.EndNode)

Example 23 with EndNode

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

the class InliningIterator method apply.

public LinkedList<Invoke> apply() {
    LinkedList<Invoke> invokes = new LinkedList<>();
    FixedNode current;
    forcedQueue(start);
    while ((current = nextQueuedNode()) != null) {
        assert current.isAlive();
        if (current instanceof Invoke && ((Invoke) current).callTarget() instanceof MethodCallTargetNode) {
            if (current != start) {
                invokes.addLast((Invoke) current);
            }
            queueSuccessors(current);
        } else if (current instanceof LoopBeginNode) {
            queueSuccessors(current);
        } else if (current instanceof LoopEndNode) {
        // nothing to do
        } 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 to do
        } else if (current instanceof ControlSplitNode) {
            queueSuccessors(current);
        } else {
            assert false : current;
        }
    }
    assert invokes.size() == count(start.graph().getInvokes());
    return invokes;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) 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) LinkedList(java.util.LinkedList) Invoke(org.graalvm.compiler.nodes.Invoke) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 24 with EndNode

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

Example 25 with EndNode

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

the class SinglePassNodeIterator method queueSuccessors.

/**
 * Two methods enqueue items in {@link #nodeQueue}. Of them, only this method enqueues items
 * with non-null state (the other method being {@link #queueMerge(EndNode)}).
 *
 * <p>
 * A space optimization is made: the state is cloned for all successors except the first. Given
 * that right after invoking this method, {@link #nextQueuedNode()} is invoked, that single
 * non-cloned state instance is in effect "handed over" to its next owner (thus realizing an
 * owner-is-mutator access protocol).
 * </p>
 */
private void queueSuccessors(FixedNode x) {
    T startState = state;
    T curState = startState;
    for (Node succ : x.successors()) {
        if (succ != null) {
            if (curState == null) {
                // the current state isn't cloned for the first successor
                // conceptually, the state is handed over to it
                curState = startState.clone();
            }
            AbstractBeginNode begin = (AbstractBeginNode) succ;
            nodeQueue.addFirst(new PathStart<>(begin, curState));
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

EndNode (org.graalvm.compiler.nodes.EndNode)30 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)22 FixedNode (org.graalvm.compiler.nodes.FixedNode)18 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)16 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)15 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)14 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)13 MergeNode (org.graalvm.compiler.nodes.MergeNode)13 Node (org.graalvm.compiler.graph.Node)12 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)12 ValueNode (org.graalvm.compiler.nodes.ValueNode)10 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)9 PhiNode (org.graalvm.compiler.nodes.PhiNode)9 BeginNode (org.graalvm.compiler.nodes.BeginNode)7 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)7 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 FrameState (org.graalvm.compiler.nodes.FrameState)6 IfNode (org.graalvm.compiler.nodes.IfNode)6 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)6