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());
}
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();
}
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;
}
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;
}
}
}
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));
}
}
}
Aggregations