Search in sources :

Example 1 with Position

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)
}
Also used : LoopFragmentWhole(org.graalvm.compiler.loop.LoopFragmentWhole) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Position(org.graalvm.compiler.graph.Position) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 2 with Position

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());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) 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) ValueNode(org.graalvm.compiler.nodes.ValueNode) Test(org.junit.Test)

Example 3 with Position

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());
}
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 4 with Position

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);
    }
}
Also used : Position(org.graalvm.compiler.graph.Position)

Example 5 with Position

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(")");
}
Also used : Fields(org.graalvm.compiler.core.common.Fields) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) Position(org.graalvm.compiler.graph.Position) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Aggregations

Position (org.graalvm.compiler.graph.Position)5 Node (org.graalvm.compiler.graph.Node)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 EndNode (org.graalvm.compiler.nodes.EndNode)2 FloatingNode (org.graalvm.compiler.nodes.calc.FloatingNode)2 Test (org.junit.Test)2 Fields (org.graalvm.compiler.core.common.Fields)1 LoopFragmentWhole (org.graalvm.compiler.loop.LoopFragmentWhole)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 FullInfopointNode (org.graalvm.compiler.nodes.FullInfopointNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)1