< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/NestedLoopTest.java

Print this page




 144     private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
 145         StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
 146         DebugContext debug = graph.getDebug();
 147         debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
 148         ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
 149 
 150         Assert.assertEquals(3, cfg.getLoops().size());
 151         Loop<Block> rootLoop = cfg.getLoops().get(0);
 152         Loop<Block> nestedLoop = cfg.getLoops().get(1);
 153         Loop<Block> innerMostLoop = cfg.getLoops().get(2);
 154         Invoke a = getInvoke("a", graph);
 155         Invoke b = getInvoke("b", graph);
 156         Invoke c = getInvoke("c", graph);
 157         Invoke d = getInvoke("d", graph);
 158         Assert.assertTrue(containsDirect(rootLoop, a, cfg));
 159         Assert.assertTrue(containsDirect(nestedLoop, b, cfg));
 160         Assert.assertTrue(containsDirect(innerMostLoop, c, cfg));
 161         Assert.assertTrue(containsDirect(innerMostLoop, d, cfg));
 162         Assert.assertTrue(contains(rootLoop, d, cfg));
 163         Assert.assertTrue(contains(nestedLoop, d, cfg));
 164         Assert.assertEquals(rootExits, rootLoop.getExits().size());
 165         Assert.assertEquals(nestedExits, nestedLoop.getExits().size());
 166         Assert.assertEquals(innerExits, innerMostLoop.getExits().size());
 167         debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
 168     }
 169 
 170     private static boolean contains(Loop<Block> loop, Invoke node, ControlFlowGraph cfg) {
 171         Block block = cfg.blockFor((Node) node);
 172         Assert.assertNotNull(block);
 173         return loop.getBlocks().contains(block);
 174     }
 175 
 176     private static boolean containsDirect(Loop<Block> loop, Invoke node, ControlFlowGraph cfg) {
 177         for (Loop<Block> child : loop.getChildren()) {
 178             if (contains(child, node, cfg)) {
 179                 return false;
 180             }
 181         }
 182         return contains(loop, node, cfg);
 183     }
 184 }


 144     private void test(String snippet, int rootExits, int nestedExits, int innerExits) {
 145         StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
 146         DebugContext debug = graph.getDebug();
 147         debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
 148         ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
 149 
 150         Assert.assertEquals(3, cfg.getLoops().size());
 151         Loop<Block> rootLoop = cfg.getLoops().get(0);
 152         Loop<Block> nestedLoop = cfg.getLoops().get(1);
 153         Loop<Block> innerMostLoop = cfg.getLoops().get(2);
 154         Invoke a = getInvoke("a", graph);
 155         Invoke b = getInvoke("b", graph);
 156         Invoke c = getInvoke("c", graph);
 157         Invoke d = getInvoke("d", graph);
 158         Assert.assertTrue(containsDirect(rootLoop, a, cfg));
 159         Assert.assertTrue(containsDirect(nestedLoop, b, cfg));
 160         Assert.assertTrue(containsDirect(innerMostLoop, c, cfg));
 161         Assert.assertTrue(containsDirect(innerMostLoop, d, cfg));
 162         Assert.assertTrue(contains(rootLoop, d, cfg));
 163         Assert.assertTrue(contains(nestedLoop, d, cfg));
 164         Assert.assertEquals(rootExits, rootLoop.getLoopExits().size());
 165         Assert.assertEquals(nestedExits, nestedLoop.getLoopExits().size());
 166         Assert.assertEquals(innerExits, innerMostLoop.getLoopExits().size());
 167         debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
 168     }
 169 
 170     private static boolean contains(Loop<Block> loop, Invoke node, ControlFlowGraph cfg) {
 171         Block block = cfg.blockFor((Node) node);
 172         Assert.assertNotNull(block);
 173         return loop.getBlocks().contains(block);
 174     }
 175 
 176     private static boolean containsDirect(Loop<Block> loop, Invoke node, ControlFlowGraph cfg) {
 177         for (Loop<Block> child : loop.getChildren()) {
 178             if (contains(child, node, cfg)) {
 179                 return false;
 180             }
 181         }
 182         return contains(loop, node, cfg);
 183     }
 184 }
< prev index next >