Search in sources :

Example 1 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class TypedNodeIteratorTest method complicatedIterationTest.

@Test
public void complicatedIterationTest() {
    OptionValues options = getOptions();
    Graph graph = new Graph(options, getDebug(options));
    graph.add(new TestNode("a"));
    for (TestNode tn : graph.getNodes(TestNode.TYPE)) {
        String name = tn.getName();
        for (int i = 0; i < name.length(); ++i) {
            char c = name.charAt(i);
            if (c == 'a') {
                tn.safeDelete();
                graph.add(new TestNode("b"));
                graph.add(new TestNode("c"));
            } else if (c == 'b') {
                tn.safeDelete();
            } else if (c == 'c') {
                graph.add(new TestNode("d"));
                graph.add(new TestNode("e"));
                graph.add(new TestNode("d"));
                graph.add(new TestNode("e"));
                graph.add(new TestNode("e"));
                graph.add(new TestNode("d"));
                graph.add(new TestNode("e"));
                graph.add(new TestNode("d"));
            } else if (c == 'd') {
                for (TestNode tn2 : graph.getNodes(TestNode.TYPE)) {
                    if (tn2.getName().equals("e")) {
                        tn2.safeDelete();
                    } else if (tn2.getName().equals("c")) {
                        tn2.safeDelete();
                    }
                }
            } else if (c == 'e') {
                fail("All e nodes must have been deleted by visiting the d node");
            }
        }
    }
    assertEquals("dddd", toString(graph.getNodes(TestNode.TYPE)));
}
Also used : Graph(org.graalvm.compiler.graph.Graph) OptionValues(org.graalvm.compiler.options.OptionValues) Test(org.junit.Test)

Example 2 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class TypedNodeIteratorTest method iteratorBehaviorTest.

@Test
public void iteratorBehaviorTest() {
    OptionValues options = getOptions();
    Graph graph = new Graph(options, getDebug(options));
    graph.add(new TestNode("a"));
    Iterator<TestNode> iterator = graph.getNodes(TestNode.TYPE).iterator();
    assertTrue(iterator.hasNext());
    assertEquals("a", iterator.next().getName());
    assertFalse(iterator.hasNext());
    graph.add(new TestNode("b"));
    assertTrue(iterator.hasNext());
    assertEquals("b", iterator.next().getName());
    assertFalse(iterator.hasNext());
    TestNode c = new TestNode("c");
    graph.add(c);
    assertTrue(iterator.hasNext());
    c.safeDelete();
    assertFalse(iterator.hasNext());
}
Also used : Graph(org.graalvm.compiler.graph.Graph) OptionValues(org.graalvm.compiler.options.OptionValues) Test(org.junit.Test)

Example 3 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class TypedNodeIteratorTest method deletingNodeTest.

@Test
public void deletingNodeTest() {
    TestNode testNode = new TestNode("a");
    OptionValues options = getOptions();
    Graph graph = new Graph(options, getDebug(options));
    graph.add(testNode);
    testNode.safeDelete();
    assertEquals("", toString(graph.getNodes(TestNode.TYPE)));
}
Also used : Graph(org.graalvm.compiler.graph.Graph) OptionValues(org.graalvm.compiler.options.OptionValues) Test(org.junit.Test)

Example 4 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class TypedNodeIteratorTest2 method addingNodeDuringIterationTest.

@Test
public void addingNodeDuringIterationTest() {
    Graph graph = new Graph(getOptions(), getDebug());
    graph.add(new NodeB("b1"));
    NodeD d1 = graph.add(new NodeD("d1"));
    StringBuilder sb = new StringBuilder();
    for (NodeB tn : graph.getNodes(NodeB.TYPE)) {
        if (tn == d1) {
            graph.add(new NodeB("b2"));
        }
        sb.append(tn.getName());
    }
    assertEquals("b1d1b2", sb.toString());
    for (NodeB tn : graph.getNodes(NodeB.TYPE)) {
        if (tn == d1) {
            graph.add(new NodeB("b3"));
        }
        assertNotNull(tn);
    }
    assertEquals(4, graph.getNodes(NodeB.TYPE).count());
    assertEquals(1, graph.getNodes(NodeD.TYPE).count());
}
Also used : Graph(org.graalvm.compiler.graph.Graph) Test(org.junit.Test)

Example 5 with Graph

use of org.graalvm.compiler.graph.Graph in project graal by oracle.

the class NodeBitMapTest method before.

@Before
public void before() {
    // Need to initialize HotSpotGraalRuntime before any Node class is initialized.
    Graal.getRuntime();
    OptionValues options = getOptions();
    graph = new Graph(options, getDebug(options));
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = graph.add(new TestNode());
    }
    map = graph.createNodeBitMap();
}
Also used : Graph(org.graalvm.compiler.graph.Graph) OptionValues(org.graalvm.compiler.options.OptionValues) Before(org.junit.Before)

Aggregations

Graph (org.graalvm.compiler.graph.Graph)33 Test (org.junit.Test)22 OptionValues (org.graalvm.compiler.options.OptionValues)21 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)3 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 EndNode (org.graalvm.compiler.nodes.EndNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 DuplicationReplacement (org.graalvm.compiler.graph.Graph.DuplicationReplacement)2 Node (org.graalvm.compiler.graph.Node)2 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)2 MergeNode (org.graalvm.compiler.nodes.MergeNode)2 Before (org.junit.Before)2 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1