Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java @ 16841:cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 15 Aug 2014 11:34:38 +0200 |
parents | 1668de777c42 |
children | 9619ba4daf4c |
rev | line source |
---|---|
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.compiler.test.ea; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
25 import static org.junit.Assert.*; |
16841
cbd42807a31f
moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents:
16714
diff
changeset
|
26 |
13694
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
27 import java.util.*; |
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
28 |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
29 import org.junit.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
30 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.api.code.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.compiler.test.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.java.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
35 import com.oracle.graal.phases.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
36 import com.oracle.graal.phases.common.*; |
15470
c55f44b3c5e5
remove NodesToDoubles, refactoring of node probability and inlining relevance computation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14978
diff
changeset
|
37 import com.oracle.graal.phases.common.inlining.*; |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 import com.oracle.graal.phases.tiers.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
39 import com.oracle.graal.virtual.phases.ea.*; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
40 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
41 public class PEAReadEliminationTest extends GraalCompilerTest { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
42 |
10783
2151364f2076
add EarlyReadEliminationPhase, including tests
Lukas Stadler <lukas.stadler@jku.at>
parents:
10763
diff
changeset
|
43 protected StructuredGraph graph; |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
44 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
45 public static Object staticField; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
46 |
10763
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
47 public static class TestObject { |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
48 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
49 public int x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
50 public int y; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
52 public TestObject(int x, int y) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
53 this.x = x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
54 this.y = y; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
55 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
56 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
57 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
58 public static class TestObject2 { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
59 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
60 public Object x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
61 public Object y; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
62 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
63 public TestObject2(Object x, Object y) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
64 this.x = x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
65 this.y = y; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
66 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
67 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
68 |
10763
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
69 public static class TestObject3 extends TestObject { |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
70 |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
71 public int z; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
72 |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
73 public TestObject3(int x, int y, int z) { |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
74 super(x, y); |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
75 this.z = z; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
76 } |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
77 } |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
78 |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
79 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
80 public static int testSimpleSnippet(TestObject a) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
81 a.x = 2; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
82 staticField = a; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
83 return a.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
84 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
85 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
86 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
87 public void testSimple() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
88 ValueNode result = getReturn("testSimpleSnippet").result(); |
11909
fd94583ddee5
removed the IterableNodeType marker interface from LoadFieldNode (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents:
11660
diff
changeset
|
89 assertTrue(graph.getNodes().filter(LoadFieldNode.class).isEmpty()); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
90 assertTrue(result.isConstant()); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
91 assertDeepEquals(2, result.asConstant().asInt()); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
92 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
93 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
94 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
95 public static int testSimpleConflictSnippet(TestObject a, TestObject b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
96 a.x = 2; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
97 b.x = 3; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
98 staticField = a; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
99 return a.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
100 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
101 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
102 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
103 public void testSimpleConflict() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
104 ValueNode result = getReturn("testSimpleConflictSnippet").result(); |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
105 assertFalse(result.isConstant()); |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
106 assertTrue(result instanceof LoadFieldNode); |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
107 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
108 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
109 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
110 public static int testParamSnippet(TestObject a, int b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
111 a.x = b; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
112 return a.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
113 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
114 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
115 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
116 public void testParam() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
117 ValueNode result = getReturn("testParamSnippet").result(); |
11909
fd94583ddee5
removed the IterableNodeType marker interface from LoadFieldNode (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents:
11660
diff
changeset
|
118 assertTrue(graph.getNodes().filter(LoadFieldNode.class).isEmpty()); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
119 assertDeepEquals(graph.getParameter(1), result); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
120 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
121 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
122 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
123 public static int testMaterializedSnippet(int a) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
124 TestObject obj = new TestObject(a, 0); |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
125 staticField = obj; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
126 return obj.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
127 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
128 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
129 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
130 public void testMaterialized() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
131 ValueNode result = getReturn("testMaterializedSnippet").result(); |
11909
fd94583ddee5
removed the IterableNodeType marker interface from LoadFieldNode (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents:
11660
diff
changeset
|
132 assertTrue(graph.getNodes().filter(LoadFieldNode.class).isEmpty()); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
133 assertDeepEquals(graph.getParameter(0), result); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
134 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
135 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
136 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
137 public static int testSimpleLoopSnippet(TestObject obj, int a, int b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
138 obj.x = a; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
139 for (int i = 0; i < 10; i++) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
140 staticField = obj; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
141 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
142 return obj.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
143 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
144 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
145 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
146 public void testSimpleLoop() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
147 ValueNode result = getReturn("testSimpleLoopSnippet").result(); |
11909
fd94583ddee5
removed the IterableNodeType marker interface from LoadFieldNode (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents:
11660
diff
changeset
|
148 assertTrue(graph.getNodes().filter(LoadFieldNode.class).isEmpty()); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
149 assertDeepEquals(graph.getParameter(1), result); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
150 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
151 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
152 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
153 public static int testBadLoopSnippet(TestObject obj, TestObject obj2, int a, int b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
154 obj.x = a; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
155 for (int i = 0; i < 10; i++) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
156 staticField = obj; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
157 obj2.x = 10; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
158 obj.x = 0; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
159 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
160 return obj.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
161 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
162 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
163 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
164 public void testBadLoop() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
165 ValueNode result = getReturn("testBadLoopSnippet").result(); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
166 assertDeepEquals(0, graph.getNodes().filter(LoadFieldNode.class).count()); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
167 assertTrue(result instanceof ProxyNode); |
14978
e302df8bf51c
separate subclasses for value and guard phis and proxies
Lukas Stadler <lukas.stadler@oracle.com>
parents:
13694
diff
changeset
|
168 assertTrue(((ProxyNode) result).value() instanceof ValuePhiNode); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
169 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
170 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
171 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
172 public static int testBadLoop2Snippet(TestObject obj, TestObject obj2, int a, int b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
173 obj.x = a; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
174 for (int i = 0; i < 10; i++) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
175 obj.x = 0; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
176 obj2.x = 10; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
177 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
178 return obj.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
179 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
180 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
181 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
182 public void testBadLoop2() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
183 ValueNode result = getReturn("testBadLoop2Snippet").result(); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
184 assertDeepEquals(1, graph.getNodes().filter(LoadFieldNode.class).count()); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
185 assertTrue(result instanceof LoadFieldNode); |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
186 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
187 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
188 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
189 public static int testPhiSnippet(TestObject a, int b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
190 if (b < 0) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
191 a.x = 1; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
192 } else { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
193 a.x = 2; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
194 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
195 return a.x; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
196 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
197 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
198 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
199 public void testPhi() { |
13694
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
200 processMethod("testPhiSnippet"); |
11909
fd94583ddee5
removed the IterableNodeType marker interface from LoadFieldNode (GRAAL-471)
Doug Simon <doug.simon@oracle.com>
parents:
11660
diff
changeset
|
201 assertTrue(graph.getNodes().filter(LoadFieldNode.class).isEmpty()); |
13694
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
202 List<ReturnNode> returnNodes = graph.getNodes(ReturnNode.class).snapshot(); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
203 assertDeepEquals(2, returnNodes.size()); |
13694
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
204 assertTrue(returnNodes.get(0).predecessor() instanceof StoreFieldNode); |
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
205 assertTrue(returnNodes.get(1).predecessor() instanceof StoreFieldNode); |
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
206 assertTrue(returnNodes.get(0).result().isConstant()); |
0e8c22aa6ec3
adapt tests for new IfNode and MergeNode simplifications
Lukas Stadler <lukas.stadler@jku.at>
parents:
13690
diff
changeset
|
207 assertTrue(returnNodes.get(1).result().isConstant()); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
208 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
209 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
210 @SuppressWarnings("all") |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
211 public static void testSimpleStoreSnippet(TestObject a, int b) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
212 a.x = b; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
213 a.x = b; |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
214 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
215 |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
216 @Test |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
217 public void testSimpleStore() { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
218 processMethod("testSimpleStoreSnippet"); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
219 assertDeepEquals(1, graph.getNodes().filter(StoreFieldNode.class).count()); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
220 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
221 |
10763
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
222 public static int testValueProxySnippet(boolean b, TestObject o) { |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
223 int sum = 0; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
224 if (b) { |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
225 sum += o.x; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
226 } else { |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
227 TestObject3 p = (TestObject3) o; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
228 sum += p.x; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
229 } |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
230 sum += o.x; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
231 return sum; |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
232 } |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
233 |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
234 @Test |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
235 public void testValueProxy() { |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
236 processMethod("testValueProxySnippet"); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
237 assertDeepEquals(2, graph.getNodes().filter(LoadFieldNode.class).count()); |
10763
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
238 } |
5e338844c64c
make early read elimination see through ValueProxies
Lukas Stadler <lukas.stadler@jku.at>
parents:
10725
diff
changeset
|
239 |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
240 final ReturnNode getReturn(String snippet) { |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
241 processMethod(snippet); |
15622
7b09605b29c5
renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents:
15473
diff
changeset
|
242 assertDeepEquals(1, graph.getNodes(ReturnNode.class).count()); |
13690
08f58bfde0dd
add IterableNodeType to ReturnNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
13614
diff
changeset
|
243 return graph.getNodes(ReturnNode.class).first(); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
244 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
245 |
10783
2151364f2076
add EarlyReadEliminationPhase, including tests
Lukas Stadler <lukas.stadler@jku.at>
parents:
10763
diff
changeset
|
246 protected void processMethod(final String snippet) { |
16714
1668de777c42
renamed GraalCompilerTest.parse to GraalCompilerTest.parseEager and improved javadoc for all parse* methods
Doug Simon <doug.simon@oracle.com>
parents:
15622
diff
changeset
|
247 graph = parseEager(snippet); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
248 Assumptions assumptions = new Assumptions(false); |
13585 | 249 HighTierContext context = new HighTierContext(getProviders(), assumptions, null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL); |
11567
c69df2e602f4
Use CanonicalizerPhase.applyIncremental in InliningPhase.
Roland Schatz <roland.schatz@oracle.com>
parents:
11437
diff
changeset
|
250 new InliningPhase(new CanonicalizerPhase(true)).apply(graph, context); |
15473
9fa849f665cc
cleanup phase within PartialEscapePhase
Lukas Stadler <lukas.stadler@oracle.com>
parents:
15470
diff
changeset
|
251 new PartialEscapePhase(false, true, new CanonicalizerPhase(true), null).apply(graph, context); |
10725
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
252 } |
e35a72e32aae
add test for early read elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
253 } |