annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/SimpleCFGTest.java @ 21554:b1530a6cce8c

renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Tue, 26 May 2015 23:21:15 +0200
parents ea8d6fa333ab
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
15536
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
25 import java.util.*;
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
26
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import org.junit.*;
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
28
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
19306
a0a760b0fb5f pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19250
diff changeset
30 import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions;
6529
2e96dc4eb8e2 renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents: 6334
diff changeset
31 import com.oracle.graal.nodes.cfg.*;
21554
b1530a6cce8c renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 19765
diff changeset
32 import com.oracle.jvmci.debug.*;
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33
9663
822adbb2ee7b CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents: 9436
diff changeset
34 public class SimpleCFGTest extends GraalCompilerTest {
822adbb2ee7b CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents: 9436
diff changeset
35
822adbb2ee7b CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents: 9436
diff changeset
36 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
37 Debug.dump(graph, "Graph");
9663
822adbb2ee7b CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents: 9436
diff changeset
38 }
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40 @Test
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 public void testImplies() {
19306
a0a760b0fb5f pulled method evolution dependencies out of Assumptions and directly into StructuredGraph
Doug Simon <doug.simon@oracle.com>
parents: 19250
diff changeset
42 StructuredGraph graph = new StructuredGraph(AllowAssumptions.YES);
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43
19509
caad3adc5fde Change forward ends to type EndNode and not AbstractEndNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19306
diff changeset
44 EndNode trueEnd = graph.add(new EndNode());
caad3adc5fde Change forward ends to type EndNode and not AbstractEndNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19306
diff changeset
45 EndNode falseEnd = graph.add(new EndNode());
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46
18994
8b4ef818169c Make AbstractBeginNode an abstract class and create concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18993
diff changeset
47 AbstractBeginNode trueBegin = graph.add(new BeginNode());
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48 trueBegin.setNext(trueEnd);
18994
8b4ef818169c Make AbstractBeginNode an abstract class and create concrete subclass BeginNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18993
diff changeset
49 AbstractBeginNode falseBegin = graph.add(new BeginNode());
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 falseBegin.setNext(falseEnd);
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
52 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
53 graph.start().setNext(ifNode);
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54
18996
46c2e70d54ad Make AbstractMergeNode abstract and introduce concrete subclass MergeNode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18995
diff changeset
55 AbstractMergeNode merge = graph.add(new MergeNode());
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 merge.addForwardEnd(trueEnd);
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57 merge.addForwardEnd(falseEnd);
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 16895
diff changeset
58 ReturnNode returnNode = graph.add(new ReturnNode(null));
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
59 merge.setNext(returnNode);
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
60
9663
822adbb2ee7b CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents: 9436
diff changeset
61 dumpGraph(graph);
822adbb2ee7b CFGVerifier: verify post-dominator calculation
Bernhard Urban <bernhard.urban@jku.at>
parents: 9436
diff changeset
62
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63 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
64
15537
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
65 List<Block> blocks = cfg.getBlocks();
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
66 // check number of blocks
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
67 assertDeepEquals(4, blocks.size());
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
68
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
69 // check block - node assignment
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
70 assertDeepEquals(blocks.get(0), cfg.blockFor(graph.start()));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
71 assertDeepEquals(blocks.get(0), cfg.blockFor(ifNode));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
72 assertDeepEquals(blocks.get(1), cfg.blockFor(trueBegin));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
73 assertDeepEquals(blocks.get(1), cfg.blockFor(trueEnd));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
74 assertDeepEquals(blocks.get(2), cfg.blockFor(falseBegin));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
75 assertDeepEquals(blocks.get(2), cfg.blockFor(falseEnd));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
76 assertDeepEquals(blocks.get(3), cfg.blockFor(merge));
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
77 assertDeepEquals(blocks.get(3), cfg.blockFor(returnNode));
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
78
15536
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
79 // check postOrder
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
80 Iterator<Block> it = cfg.postOrder().iterator();
15537
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
81 for (int i = blocks.size() - 1; i >= 0; i--) {
15536
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
82 assertTrue(it.hasNext());
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
83 Block b = it.next();
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15537
diff changeset
84 assertDeepEquals(blocks.get(i), b);
15536
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
85 }
d897375b372a SimpleCFGTest: check postOrder().
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
86
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 // check dominators
15537
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
88 assertDominator(blocks.get(0), null);
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
89 assertDominator(blocks.get(1), blocks.get(0));
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
90 assertDominator(blocks.get(2), blocks.get(0));
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
91 assertDominator(blocks.get(3), blocks.get(0));
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
92
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
93 // check dominated
15537
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
94 assertDominatedSize(blocks.get(0), 3);
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
95 assertDominatedSize(blocks.get(1), 0);
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
96 assertDominatedSize(blocks.get(2), 0);
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
97 assertDominatedSize(blocks.get(3), 0);
5459
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 // check postdominators
15537
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
100 assertPostdominator(blocks.get(0), blocks.get(3));
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
101 assertPostdominator(blocks.get(1), blocks.get(3));
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
102 assertPostdominator(blocks.get(2), blocks.get(3));
8117e9cadb48 Use List instead of an array in AbstractControlFlowGraph.
Josef Eisl <josef.eisl@jku.at>
parents: 15536
diff changeset
103 assertPostdominator(blocks.get(3), null);
5459
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
104 }
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 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
107 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
108 }
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
109
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
110 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
111 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
112 }
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
113
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
114 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
115 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
116 }
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
117
ecb598b9d535 add simple test for ControlFlowGraph block computation
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
118 }