use of org.graalvm.compiler.graph.Position in project graal by oracle.
the class LoopTransformations method unswitch.
public static void unswitch(LoopEx loop, List<ControlSplitNode> controlSplitNodeSet) {
ControlSplitNode firstNode = controlSplitNodeSet.iterator().next();
LoopFragmentWhole originalLoop = loop.whole();
StructuredGraph graph = firstNode.graph();
loop.loopBegin().incrementUnswitches();
// create new control split out of loop
ControlSplitNode newControlSplit = (ControlSplitNode) firstNode.copyWithInputs();
originalLoop.entryPoint().replaceAtPredecessor(newControlSplit);
/*
* The code below assumes that all of the control split nodes have the same successor
* structure, which should have been enforced by findUnswitchable.
*/
Iterator<Position> successors = firstNode.successorPositions().iterator();
assert successors.hasNext();
// original loop is used as first successor
Position firstPosition = successors.next();
AbstractBeginNode originalLoopBegin = BeginNode.begin(originalLoop.entryPoint());
firstPosition.set(newControlSplit, originalLoopBegin);
while (successors.hasNext()) {
Position position = successors.next();
// create a new loop duplicate and connect it.
LoopFragmentWhole duplicateLoop = originalLoop.duplicate();
AbstractBeginNode newBegin = BeginNode.begin(duplicateLoop.entryPoint());
position.set(newControlSplit, newBegin);
// For each cloned ControlSplitNode, simplify the proper path
for (ControlSplitNode controlSplitNode : controlSplitNodeSet) {
ControlSplitNode duplicatedControlSplit = duplicateLoop.getDuplicatedNode(controlSplitNode);
if (duplicatedControlSplit.isAlive()) {
AbstractBeginNode survivingSuccessor = (AbstractBeginNode) position.get(duplicatedControlSplit);
survivingSuccessor.replaceAtUsages(InputType.Guard, newBegin);
graph.removeSplitPropagate(duplicatedControlSplit, survivingSuccessor);
}
}
}
// original loop is simplified last to avoid deleting controlSplitNode too early
for (ControlSplitNode controlSplitNode : controlSplitNodeSet) {
if (controlSplitNode.isAlive()) {
AbstractBeginNode survivingSuccessor = (AbstractBeginNode) firstPosition.get(controlSplitNode);
survivingSuccessor.replaceAtUsages(InputType.Guard, originalLoopBegin);
graph.removeSplitPropagate(controlSplitNode, survivingSuccessor);
}
}
// TODO (gd) probabilities need some amount of fixup.. (probably also in other transforms)
}
use of org.graalvm.compiler.graph.Position in project graal by oracle.
the class NodePosIteratorTest method testInputs.
@Test
public void testInputs() {
TestNode n = new TestNode();
ConstantNode i1 = ConstantNode.forInt(1);
ConstantNode i2 = ConstantNode.forDouble(1.0d);
ConstantNode i3 = ConstantNode.forInt(4);
ConstantNode i4 = ConstantNode.forInt(14);
n.itail = new NodeInputList<>(n, new ValueNode[] { i3, i4 });
n.i1 = i1;
n.i2 = i2;
NodeIterable<Node> inputs = n.inputs();
Iterator<Node> iterator = inputs.iterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i1);
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i2);
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i3);
Assert.assertTrue(iterator.hasNext());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
Assert.assertFalse(iterator.hasNext());
Assert.assertFalse(iterator.hasNext());
Iterator<Position> positionIterator = n.inputPositions().iterator();
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("ConstantNode:i1", positionIterator.next().toString());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("FloatingNode:i2", positionIterator.next().toString());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("NodeInputList:itail[0]", positionIterator.next().toString());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertTrue(positionIterator.hasNext());
Assert.assertEquals("NodeInputList:itail[1]", positionIterator.next().toString());
Assert.assertFalse(positionIterator.hasNext());
Assert.assertFalse(positionIterator.hasNext());
iterator = inputs.iterator();
n.i1 = i4;
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
n.i2 = i1;
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i1);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i3);
n.itail.initialize(1, i4);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
Assert.assertFalse(iterator.hasNext());
iterator = inputs.iterator();
n.i1 = null;
n.i2 = i2;
n.itail.initialize(0, null);
n.itail.initialize(1, i4);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i2);
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(iterator.next(), i4);
Assert.assertFalse(iterator.hasNext());
}
use of org.graalvm.compiler.graph.Position 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.graph.Position in project graal by oracle.
the class CFGPrinter method printNamedNodes.
private void printNamedNodes(Node node, Iterator<Position> iter, String prefix, String suffix, String hideSuffix) {
int lastIndex = -1;
while (iter.hasNext()) {
Position pos = iter.next();
if (hideSuffix != null && pos.getName().endsWith(hideSuffix)) {
continue;
}
if (pos.getIndex() != lastIndex) {
if (lastIndex != -1) {
out.print(suffix);
}
out.print(prefix).print(pos.getName()).print(": ");
lastIndex = pos.getIndex();
}
out.print(nodeToString(pos.get(node))).print(" ");
}
if (lastIndex != -1) {
out.print(suffix);
}
}
use of org.graalvm.compiler.graph.Position in project graal by oracle.
the class CanonicalStringGraphPrinter method writeCanonicalGraphExpressionString.
protected static void writeCanonicalGraphExpressionString(ValueNode node, boolean checkConstants, boolean removeIdentities, PrintWriter writer) {
writer.print(node.getClass().getSimpleName());
writer.print("(");
Fields properties = node.getNodeClass().getData();
for (int i = 0; i < properties.getCount(); i++) {
String dataStr = String.valueOf(properties.get(node, i));
if (removeIdentities) {
dataStr = removeIdentities(dataStr);
}
writer.print(dataStr);
if (i + 1 < properties.getCount() || node.inputPositions().iterator().hasNext()) {
writer.print(", ");
}
}
Iterator<Position> iterator = node.inputPositions().iterator();
while (iterator.hasNext()) {
Position position = iterator.next();
Node input = position.get(node);
if (checkConstants && input instanceof ConstantNode) {
ConstantNode constantNode = (ConstantNode) input;
String valueString = constantNode.getValue().toValueString();
if (removeIdentities) {
valueString = removeIdentities(valueString);
}
writer.print(valueString);
} else if (input instanceof ValueNode && !(input instanceof PhiNode) && !(input instanceof FixedNode)) {
writeCanonicalGraphExpressionString((ValueNode) input, checkConstants, removeIdentities, writer);
} else if (input == null) {
writer.print("null");
} else {
writer.print(input.getClass().getSimpleName());
}
if (iterator.hasNext()) {
writer.print(", ");
}
}
writer.print(")");
}
Aggregations