Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SimpleCFGTest.java @ 15145:df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
This required some changes to loop transformations: when peeling don't create duplicates for the exit proxies.
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Mon, 14 Apr 2014 15:21:27 +0200 |
parents | 8569b9e047cd |
children | d897375b372a |
rev | line source |
---|---|
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
6334
f8ba3bb81f6f
Renamed com.oracle.graal.tests project to com.oracle.graal.compiler.test
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5695
diff
changeset
|
23 package com.oracle.graal.compiler.test; |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
25 import org.junit.*; |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
26 |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
27 import com.oracle.graal.debug.*; |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.nodes.*; |
6529
2e96dc4eb8e2
renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
29 import com.oracle.graal.nodes.cfg.*; |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
31 public class SimpleCFGTest extends GraalCompilerTest { |
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
32 |
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
33 private static void dumpGraph(final StructuredGraph graph) { |
13197
8569b9e047cd
change debug scopes implementation to prevent extra frames related to mechanism being added to call stack
Doug Simon <doug.simon@oracle.com>
parents:
9663
diff
changeset
|
34 Debug.dump(graph, "Graph"); |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
35 } |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
36 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
37 @Test |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 public void testImplies() { |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 StructuredGraph graph = new StructuredGraph(); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
40 |
9434
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7660
diff
changeset
|
41 AbstractEndNode trueEnd = graph.add(new EndNode()); |
50f02c7d1cec
Rename EndNode => AbstractEndNode and make abstract class. Introduce concrete EndNode subclass.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7660
diff
changeset
|
42 AbstractEndNode falseEnd = graph.add(new EndNode()); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
43 |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13197
diff
changeset
|
44 BeginNode trueBegin = graph.add(new BeginNode()); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
45 trueBegin.setNext(trueEnd); |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13197
diff
changeset
|
46 BeginNode falseBegin = graph.add(new BeginNode()); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
47 falseBegin.setNext(falseEnd); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
48 |
7660
0b646334c5f7
keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents:
6529
diff
changeset
|
49 IfNode ifNode = graph.add(new IfNode(null, trueBegin, falseBegin, 0.5)); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
50 graph.start().setNext(ifNode); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
52 MergeNode merge = graph.add(new MergeNode()); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
53 merge.addForwardEnd(trueEnd); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
54 merge.addForwardEnd(falseEnd); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
55 ReturnNode returnNode = graph.add(new ReturnNode(null)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
56 merge.setNext(returnNode); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
57 |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
58 dumpGraph(graph); |
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
59 |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
60 ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
61 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
62 Block[] blocks = cfg.getBlocks(); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
63 // check number of blocks |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
64 assertEquals(4, blocks.length); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
65 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
66 // check block - node assignment |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
67 assertEquals(blocks[0], cfg.blockFor(graph.start())); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
68 assertEquals(blocks[0], cfg.blockFor(ifNode)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
69 assertEquals(blocks[1], cfg.blockFor(trueBegin)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
70 assertEquals(blocks[1], cfg.blockFor(trueEnd)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
71 assertEquals(blocks[2], cfg.blockFor(falseBegin)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
72 assertEquals(blocks[2], cfg.blockFor(falseEnd)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
73 assertEquals(blocks[3], cfg.blockFor(merge)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
74 assertEquals(blocks[3], cfg.blockFor(returnNode)); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
75 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
76 // check dominators |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
77 assertDominator(blocks[0], null); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
78 assertDominator(blocks[1], blocks[0]); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
79 assertDominator(blocks[2], blocks[0]); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
80 assertDominator(blocks[3], blocks[0]); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
81 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
82 // check dominated |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
83 assertDominatedSize(blocks[0], 3); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
84 assertDominatedSize(blocks[1], 0); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
85 assertDominatedSize(blocks[2], 0); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
86 assertDominatedSize(blocks[3], 0); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
87 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
88 // check postdominators |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
89 assertPostdominator(blocks[0], blocks[3]); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
90 assertPostdominator(blocks[1], blocks[3]); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
91 assertPostdominator(blocks[2], blocks[3]); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
92 assertPostdominator(blocks[3], null); |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
93 } |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
94 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
95 public static void assertDominator(Block block, Block expectedDominator) { |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
96 Assert.assertEquals("dominator of " + block, expectedDominator, block.getDominator()); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
97 } |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
98 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
99 public static void assertDominatedSize(Block block, int size) { |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
100 Assert.assertEquals("number of dominated blocks of " + block, size, block.getDominated().size()); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
101 } |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
102 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
103 public static void assertPostdominator(Block block, Block expectedPostdominator) { |
9663
822adbb2ee7b
CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents:
9436
diff
changeset
|
104 Assert.assertEquals("postdominator of " + block, expectedPostdominator, block.getPostdominator()); |
5459
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
105 } |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
106 |
ecb598b9d535
add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
107 } |