43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.core.test;
|
|
24 |
|
|
25 |
import java.util.List;
|
|
26 |
|
|
27 |
import org.graalvm.compiler.graph.Node;
|
|
28 |
import org.graalvm.compiler.graph.NodeMap;
|
|
29 |
import org.graalvm.compiler.nodes.StructuredGraph;
|
|
30 |
import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
|
|
31 |
import org.graalvm.compiler.nodes.cfg.Block;
|
|
32 |
import org.graalvm.compiler.phases.schedule.SchedulePhase;
|
48861
|
33 |
import org.junit.Assert;
|
|
34 |
|
|
35 |
import jdk.vm.ci.meta.SpeculationLog;
|
43972
|
36 |
|
|
37 |
public class GraphScheduleTest extends GraalCompilerTest {
|
|
38 |
|
|
39 |
protected void assertOrderedAfterSchedule(StructuredGraph graph, Node a, Node b) {
|
48861
|
40 |
assertOrderedAfterSchedule(graph, SchedulePhase.SchedulingStrategy.LATEST, a, b);
|
|
41 |
}
|
|
42 |
|
|
43 |
protected void assertOrderedAfterSchedule(StructuredGraph graph, SchedulePhase.SchedulingStrategy strategy, Node a, Node b) {
|
|
44 |
SchedulePhase ibp = new SchedulePhase(strategy);
|
43972
|
45 |
ibp.apply(graph);
|
48861
|
46 |
assertOrderedAfterLastSchedule(graph, a, b);
|
|
47 |
}
|
|
48 |
|
|
49 |
protected void assertOrderedAfterLastSchedule(StructuredGraph graph, Node a, Node b) {
|
43972
|
50 |
assertOrderedAfterSchedule(graph.getLastSchedule(), a, b);
|
|
51 |
}
|
|
52 |
|
|
53 |
protected void assertOrderedAfterSchedule(ScheduleResult ibp, Node a, Node b) {
|
|
54 |
NodeMap<Block> nodeToBlock = ibp.getCFG().getNodeToBlock();
|
|
55 |
Block bBlock = nodeToBlock.get(b);
|
|
56 |
Block aBlock = nodeToBlock.get(a);
|
|
57 |
|
|
58 |
if (bBlock == aBlock) {
|
|
59 |
List<Node> instructions = ibp.nodesFor(bBlock);
|
48861
|
60 |
Assert.assertTrue(a + " should be before " + b, instructions.indexOf(b) > instructions.indexOf(a));
|
43972
|
61 |
} else {
|
|
62 |
Block block = bBlock;
|
|
63 |
while (block != null) {
|
|
64 |
if (block == aBlock) {
|
|
65 |
return;
|
|
66 |
}
|
|
67 |
block = block.getDominator();
|
|
68 |
}
|
|
69 |
Assert.fail("block of A doesn't dominate the block of B");
|
|
70 |
}
|
|
71 |
}
|
48861
|
72 |
|
|
73 |
@Override
|
|
74 |
protected SpeculationLog getSpeculationLog() {
|
|
75 |
return getCodeCache().createSpeculationLog();
|
|
76 |
}
|
43972
|
77 |
}
|