Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: tests/compiler/dart2js/backend_dart/opt_redundant_phi_test.dart

Issue 853083005: Revert "Allow LetCont to bind multiple continuations." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'sexpr_unstringifier.dart'; 5 import 'sexpr_unstringifier.dart';
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart'; 7 import 'package:compiler/src/cps_ir/cps_ir_nodes.dart';
8 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; 8 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart';
9 import 'package:compiler/src/cps_ir/optimizers.dart'; 9 import 'package:compiler/src/cps_ir/optimizers.dart';
10 10
11 // The 'read in loop' IR tests the most basic case of redundant phi removal 11 // The 'read in loop' IR tests the most basic case of redundant phi removal
12 // and represents the following source code: 12 // and represents the following source code:
13 // 13 //
14 // void main() { 14 // void main() {
15 // int j = 42; 15 // int j = 42;
16 // for (int i = 0; i < 2; i++) { 16 // for (int i = 0; i < 2; i++) {
17 // print(j.toString()); 17 // print(j.toString());
18 // } 18 // }
19 // } 19 // }
20 20
21 String READ_IN_LOOP_IN = """ 21 String READ_IN_LOOP_IN = """
22 (FunctionDefinition main () return () 22 (FunctionDefinition main () return ()
23 (LetPrim (v0 (Constant (Int 42))) 23 (LetPrim (v0 (Constant (Int 42)))
24 (LetPrim (v1 (Constant (Int 0))) 24 (LetPrim (v1 (Constant (Int 0)))
25 (LetCont 25 (LetCont* (k0 (v2 v3)
26 ((rec k0 (v2 v3) 26 (LetCont (k1 ()
27 (LetCont 27 (LetPrim (v4 (Constant (Null)))
28 ((k1 () 28 (InvokeContinuation return (v4))))
29 (LetPrim (v4 (Constant (Null))) 29 (LetCont (k2 ()
30 (InvokeContinuation return (v4)))) 30 (LetCont (k3 (v5)
31 (k2 () 31 (LetCont (k4 (v6)
32 (LetCont 32 (LetPrim (v7 (Constant (Int 1)))
33 ((k3 (v5) 33 (LetCont (k5 (v8)
34 (LetCont 34 (InvokeContinuation* k0 (v2 v8)))
35 ((k4 (v6) 35 (InvokeMethod v3 + (v7) k5))))
36 (LetPrim (v7 (Constant (Int 1))) 36 (InvokeStatic print (v5) k4)))
37 (LetCont 37 (InvokeMethod v2 toString () k3)))
38 ((k5 (v8) 38 (LetPrim (v9 (Constant (Int 2)))
39 (InvokeContinuation* k0 (v2 v8)))) 39 (LetCont (k6 (v10)
40 (InvokeMethod v3 + (v7) k5))))) 40 (Branch (IsTrue v10) k2 k1))
41 (InvokeStatic print (v5) k4)))) 41 (InvokeMethod v3 < (v9) k6))))))
42 (InvokeMethod v2 toString () k3))))
43 (LetPrim (v9 (Constant (Int 2)))
44 (LetCont
45 ((k6 (v10)
46 (Branch (IsTrue v10) k2 k1)))
47 (InvokeMethod v3 < (v9) k6))))))
48 (InvokeContinuation k0 (v0 v1)))))) 42 (InvokeContinuation k0 (v0 v1))))))
49 """; 43 """;
50 44
51 String READ_IN_LOOP_OUT = """ 45 String READ_IN_LOOP_OUT = """
52 (FunctionDefinition main () return () 46 (FunctionDefinition main () return ()
53 (LetPrim (v0 (Constant (Int 42))) 47 (LetPrim (v0 (Constant (Int 42)))
54 (LetPrim (v1 (Constant (Int 0))) 48 (LetPrim (v1 (Constant (Int 0)))
55 (LetCont 49 (LetCont* (k0 (v2)
56 ((rec k0 (v2) 50 (LetCont (k1 ()
57 (LetCont 51 (LetPrim (v3 (Constant (Null)))
58 ((k1 () 52 (InvokeContinuation return (v3))))
59 (LetPrim (v3 (Constant (Null))) 53 (LetCont (k2 ()
60 (InvokeContinuation return (v3)))) 54 (LetCont (k3 (v4)
61 (k2 () 55 (LetCont (k4 (v5)
62 (LetCont 56 (LetPrim (v6 (Constant (Int 1)))
63 ((k3 (v4) 57 (LetCont (k5 (v7)
64 (LetCont 58 (InvokeContinuation* k0 (v7)))
65 ((k4 (v5) 59 (InvokeMethod v2 + (v6) k5))))
66 (LetPrim (v6 (Constant (Int 1))) 60 (InvokeStatic print (v4) k4)))
67 (LetCont 61 (InvokeMethod v0 toString () k3)))
68 ((k5 (v7) 62 (LetPrim (v8 (Constant (Int 2)))
69 (InvokeContinuation* k0 (v7)))) 63 (LetCont (k6 (v9)
70 (InvokeMethod v2 + (v6) k5))))) 64 (Branch (IsTrue v9) k2 k1))
71 (InvokeStatic print (v4) k4)))) 65 (InvokeMethod v2 < (v8) k6))))))
72 (InvokeMethod v0 toString () k3))))
73 (LetPrim (v8 (Constant (Int 2)))
74 (LetCont
75 ((k6 (v9)
76 (Branch (IsTrue v9) k2 k1)))
77 (InvokeMethod v2 < (v8) k6))))))
78 (InvokeContinuation k0 (v1)))))) 66 (InvokeContinuation k0 (v1))))))
79 """; 67 """;
80 68
81 // The 'inner loop' IR represents the following source code: 69 // The 'inner loop' IR represents the following source code:
82 // 70 //
83 // void main() { 71 // void main() {
84 // int j = 42; 72 // int j = 42;
85 // for (int i = 0; i < 2; i++) { 73 // for (int i = 0; i < 2; i++) {
86 // for (int k = 0; k < 2; k++) { 74 // for (int k = 0; k < 2; k++) {
87 // print(i.toString()); 75 // print(i.toString());
88 // } 76 // }
89 // } 77 // }
90 // print(j.toString()); 78 // print(j.toString());
91 // } 79 // }
92 // 80 //
93 // This test case ensures that iterative optimization works: first, v8 and v9 81 // This test case ensures that iterative optimization works: first, v8 and v9
94 // are removed from k5, and only then can k0 be optimized as well. 82 // are removed from k5, and only then can k0 be optimized as well.
95 83
96 const String INNER_LOOP_IN = """ 84 const String INNER_LOOP_IN = """
97 (FunctionDefinition main () return () 85 (FunctionDefinition main () return ()
98 (LetPrim (v0 (Constant (Int 42))) 86 (LetPrim (v0 (Constant (Int 42)))
99 (LetPrim (v1 (Constant (Int 0))) 87 (LetPrim (v1 (Constant (Int 0)))
100 (LetCont 88 (LetCont* (k0 (v2 v3)
101 ((rec k0 (v2 v3) 89 (LetCont (k1 ()
102 (LetCont 90 (LetCont (k2 (v4)
103 ((k1 () 91 (LetCont (k3 (v5)
104 (LetCont 92 (LetPrim (v6 (Constant (Null)))
105 ((k2 (v4) 93 (InvokeContinuation return (v6))))
106 (LetCont 94 (InvokeStatic print (v4) k3)))
107 ((k3 (v5) 95 (InvokeMethod v2 toString () k2)))
108 (LetPrim (v6 (Constant (Null))) 96 (LetCont (k4 ()
109 (InvokeContinuation return (v6))))) 97 (LetPrim (v7 (Constant (Int 0)))
110 (InvokeStatic print (v4) k3)))) 98 (LetCont* (k5 (v8 v9 v10)
111 (InvokeMethod v2 toString () k2))) 99 (LetCont (k6 ()
112 (k4 () 100 (LetPrim (v11 (Constant (Int 1)))
113 (LetPrim (v7 (Constant (Int 0))) 101 (LetCont (k7 (v12)
114 (LetCont 102 (InvokeContinuation* k0 (v8 v12)))
115 ((rec k5 (v8 v9 v10) 103 (InvokeMethod v9 + (v11) k7))))
116 (LetCont 104 (LetCont (k8 ()
117 ((k6 () 105 (LetCont (k9 (v13)
118 (LetPrim (v11 (Constant (Int 1))) 106 (LetCont (k10 (v14)
119 (LetCont 107 (LetPrim (v15 (Constant (Int 1)))
120 ((k7 (v12) 108 (LetCont (k11 (v16)
121 (InvokeContinuation* k0 (v8 v12)))) 109 (InvokeContinuation* k5 (v8 v9 v16)))
122 (InvokeMethod v9 + (v11) k7)))) 110 (InvokeMethod v10 + (v15) k11))))
123 (k8 () 111 (InvokeStatic print (v13) k10)))
124 (LetCont 112 (InvokeMethod v9 toString () k9)))
125 ((k9 (v13) 113 (LetPrim (v17 (Constant (Int 2)))
126 (LetCont 114 (LetCont (k12 (v18)
127 ((k10 (v14) 115 (Branch (IsTrue v18) k8 k6))
128 (LetPrim (v15 (Constant (Int 1 ))) 116 (InvokeMethod v10 < (v17) k12))))))
129 (LetCont 117 (InvokeContinuation k5 (v2 v3 v7)))))
130 ((k11 (v16) 118 (LetPrim (v19 (Constant (Int 2)))
131 (InvokeContinuation* k5 (v8 v9 v16)))) 119 (LetCont (k13 (v20)
132 (InvokeMethod v10 + (v15) k11))))) 120 (Branch (IsTrue v20) k4 k1))
133 (InvokeStatic print (v13) k10)))) 121 (InvokeMethod v3 < (v19) k13))))))
134 (InvokeMethod v9 toString () k9))))
135 (LetPrim (v17 (Constant (Int 2)))
136 (LetCont
137 ((k12 (v18)
138 (Branch (IsTrue v18) k8 k6)))
139 (InvokeMethod v10 < (v17) k12))))))
140 (InvokeContinuation k5 (v2 v3 v7))))))
141 (LetPrim (v19 (Constant (Int 2)))
142 (LetCont
143 ((k13 (v20)
144 (Branch (IsTrue v20) k4 k1)))
145 (InvokeMethod v3 < (v19) k13))))))
146 (InvokeContinuation k0 (v0 v1)))))) 122 (InvokeContinuation k0 (v0 v1))))))
147 """; 123 """;
148 124
149 const String INNER_LOOP_OUT = """ 125 const String INNER_LOOP_OUT = """
150 (FunctionDefinition main () return () 126 (FunctionDefinition main () return ()
151 (LetPrim (v0 (Constant (Int 42))) 127 (LetPrim (v0 (Constant (Int 42)))
152 (LetPrim (v1 (Constant (Int 0))) 128 (LetPrim (v1 (Constant (Int 0)))
153 (LetCont 129 (LetCont* (k0 (v2)
154 ((rec k0 (v2) 130 (LetCont (k1 ()
155 (LetCont 131 (LetCont (k2 (v3)
156 ((k1 () 132 (LetCont (k3 (v4)
157 (LetCont 133 (LetPrim (v5 (Constant (Null)))
158 ((k2 (v3) 134 (InvokeContinuation return (v5))))
159 (LetCont 135 (InvokeStatic print (v3) k3)))
160 ((k3 (v4) 136 (InvokeMethod v0 toString () k2)))
161 (LetPrim (v5 (Constant (Null))) 137 (LetCont (k4 ()
162 (InvokeContinuation return (v5))))) 138 (LetPrim (v6 (Constant (Int 0)))
163 (InvokeStatic print (v3) k3)))) 139 (LetCont* (k5 (v7)
164 (InvokeMethod v0 toString () k2))) 140 (LetCont (k6 ()
165 (k4 () 141 (LetPrim (v8 (Constant (Int 1)))
166 (LetPrim (v6 (Constant (Int 0))) 142 (LetCont (k7 (v9)
167 (LetCont 143 (InvokeContinuation* k0 (v9)))
168 ((rec k5 (v7) 144 (InvokeMethod v2 + (v8) k7))))
169 (LetCont 145 (LetCont (k8 ()
170 ((k6 () 146 (LetCont (k9 (v10)
171 (LetPrim (v8 (Constant (Int 1))) 147 (LetCont (k10 (v11)
172 (LetCont 148 (LetPrim (v12 (Constant (Int 1)))
173 ((k7 (v9) 149 (LetCont (k11 (v13)
174 (InvokeContinuation* k0 (v9)))) 150 (InvokeContinuation* k5 (v13)))
175 (InvokeMethod v2 + (v8) k7)))) 151 (InvokeMethod v7 + (v12) k11))))
176 (k8 () 152 (InvokeStatic print (v10) k10)))
177 (LetCont 153 (InvokeMethod v2 toString () k9)))
178 ((k9 (v10) 154 (LetPrim (v14 (Constant (Int 2)))
179 (LetCont 155 (LetCont (k12 (v15)
180 ((k10 (v11) 156 (Branch (IsTrue v15) k8 k6))
181 (LetPrim (v12 (Constant (Int 1 ))) 157 (InvokeMethod v7 < (v14) k12))))))
182 (LetCont 158 (InvokeContinuation k5 (v6)))))
183 ((k11 (v13) 159 (LetPrim (v16 (Constant (Int 2)))
184 (InvokeContinuation* k5 (v13)))) 160 (LetCont (k13 (v17)
185 (InvokeMethod v7 + (v12) k 11))))) 161 (Branch (IsTrue v17) k4 k1))
186 (InvokeStatic print (v10) k10)))) 162 (InvokeMethod v2 < (v16) k13))))))
187 (InvokeMethod v2 toString () k9))))
188 (LetPrim (v14 (Constant (Int 2)))
189 (LetCont
190 ((k12 (v15)
191 (Branch (IsTrue v15) k8 k6)))
192 (InvokeMethod v7 < (v14) k12))))))
193 (InvokeContinuation k5 (v6))))))
194 (LetPrim (v16 (Constant (Int 2)))
195 (LetCont
196 ((k13 (v17)
197 (Branch (IsTrue v17) k4 k1)))
198 (InvokeMethod v2 < (v16) k13))))))
199 (InvokeContinuation k0 (v1)))))) 163 (InvokeContinuation k0 (v1))))))
200 """; 164 """;
201 165
202 // There are no redundant phis in the 'basic loop' IR, and this test ensures 166 // There are no redundant phis in the 'basic loop' IR, and this test ensures
203 // simply that the optimization does not alter the IR. It represents the 167 // simply that the optimization does not alter the IR. It represents the
204 // following program: 168 // following program:
205 // 169 //
206 // void main() { 170 // void main() {
207 // for (int i = 0; i < 2; i++) { 171 // for (int i = 0; i < 2; i++) {
208 // print(i.toString()); 172 // print(i.toString());
209 // } 173 // }
210 // } 174 // }
211 175
212 String BASIC_LOOP_IN = """ 176 String BASIC_LOOP_IN = """
213 (FunctionDefinition main () return () 177 (FunctionDefinition main () return ()
214 (LetPrim (v0 (Constant (Int 0))) 178 (LetPrim (v0 (Constant (Int 0)))
215 (LetCont 179 (LetCont* (k0 (v1)
216 ((rec k0 (v1) 180 (LetCont (k1 ()
217 (LetCont 181 (LetPrim (v2 (Constant (Null)))
218 ((k1 () 182 (InvokeContinuation return (v2))))
219 (LetPrim (v2 (Constant (Null))) 183 (LetCont (k2 ()
220 (InvokeContinuation return (v2)))) 184 (LetCont (k3 (v3)
221 (k2 () 185 (LetCont (k4 (v4)
222 (LetCont 186 (LetPrim (v5 (Constant (Int 1)))
223 ((k3 (v3) 187 (LetCont (k5 (v6)
224 (LetCont 188 (InvokeContinuation* k0 (v6)))
225 ((k4 (v4) 189 (InvokeMethod v1 + (v5) k5))))
226 (LetPrim (v5 (Constant (Int 1))) 190 (InvokeStatic print (v3) k4)))
227 (LetCont 191 (InvokeMethod v1 toString () k3)))
228 ((k5 (v6)
229 (InvokeContinuation* k0 (v6))))
230 (InvokeMethod v1 + (v5) k5)))))
231 (InvokeStatic print (v3) k4))))
232 (InvokeMethod v1 toString () k3))))
233 (LetPrim (v7 (Constant (Int 2))) 192 (LetPrim (v7 (Constant (Int 2)))
234 (LetCont 193 (LetCont (k6 (v8)
235 ((k6 (v8) 194 (Branch (IsTrue v8) k2 k1))
236 (Branch (IsTrue v8) k2 k1)))
237 (InvokeMethod v1 < (v7) k6)))))) 195 (InvokeMethod v1 < (v7) k6))))))
238 (InvokeContinuation k0 (v0))))) 196 (InvokeContinuation k0 (v0)))))
239 """; 197 """;
240 198
241 String BASIC_LOOP_OUT = BASIC_LOOP_IN; 199 String BASIC_LOOP_OUT = BASIC_LOOP_IN;
242 200
243 // Ensures that proper scoping is preserved, i.e. that the optimized 201 // Ensures that proper scoping is preserved, i.e. that the optimized
244 // continuation body does reference out of scope primitives. 202 // continuation body does reference out of scope primitives.
245 // IR written by hand since this case is currently not being generated. 203 // IR written by hand since this case is currently not being generated.
246 204
247 String SCOPING_IN = """ 205 String SCOPING_IN = """
248 (FunctionDefinition main () return () 206 (FunctionDefinition main () return ()
249 (LetCont 207 (LetCont (k0 (v1)
250 ((k0 (v1) 208 (InvokeStatic print (v1) return))
251 (InvokeStatic print (v1) return)))
252 (LetPrim (v0 (Constant (Int 0))) 209 (LetPrim (v0 (Constant (Int 0)))
253 (LetPrim (v2 (Constant (Null))) 210 (LetPrim (v2 (Constant (Null)))
254 (InvokeContinuation k0 (v0)))))) 211 (InvokeContinuation k0 (v0))))))
255 """; 212 """;
256 213
257 String SCOPING_OUT = """ 214 String SCOPING_OUT = """
258 (FunctionDefinition main () return () 215 (FunctionDefinition main () return ()
259 (LetPrim (v0 (Constant (Int 0))) 216 (LetPrim (v0 (Constant (Int 0)))
260 (LetCont 217 (LetCont (k0 ()
261 ((k0 () 218 (InvokeStatic print (v0) return))
262 (InvokeStatic print (v0) return)))
263 (LetPrim (v1 (Constant (Null))) 219 (LetPrim (v1 (Constant (Null)))
264 (InvokeContinuation k0 ()))))) 220 (InvokeContinuation k0 ())))))
265 """; 221 """;
266 222
267 // Ensures that continuations which are never invoked are not optimized. 223 // Ensures that continuations which are never invoked are not optimized.
268 // IR written by hand. 224 // IR written by hand.
269 225
270 String NEVER_INVOKED_IN = """ 226 String NEVER_INVOKED_IN = """
271 (FunctionDefinition main () return () 227 (FunctionDefinition main () return ()
272 (LetPrim (v0 (Constant (Int 0))) 228 (LetPrim (v0 (Constant (Int 0)))
273 (LetCont 229 (LetCont (k0 (v1)
274 ((k0 (v1) 230 (InvokeStatic print (v1) return))
275 (InvokeStatic print (v1) return)))
276 (InvokeContinuation return (v0))))) 231 (InvokeContinuation return (v0)))))
277 """; 232 """;
278 233
279 String NEVER_INVOKED_OUT = NEVER_INVOKED_IN; 234 String NEVER_INVOKED_OUT = NEVER_INVOKED_IN;
280 235
281 /// Normalizes whitespace by replacing all whitespace sequences by a single 236 /// Normalizes whitespace by replacing all whitespace sequences by a single
282 /// space and trimming leading and trailing whitespace. 237 /// space and trimming leading and trailing whitespace.
283 String normalizeSExpr(String input) { 238 String normalizeSExpr(String input) {
284 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); 239 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim();
285 } 240 }
(...skipping 14 matching lines...) Expand all
300 Expect.equals(expected, actual, "Actual:\n$actual"); 255 Expect.equals(expected, actual, "Actual:\n$actual");
301 } 256 }
302 257
303 void main() { 258 void main() {
304 testRedundantPhi(READ_IN_LOOP_IN, READ_IN_LOOP_OUT); 259 testRedundantPhi(READ_IN_LOOP_IN, READ_IN_LOOP_OUT);
305 testRedundantPhi(INNER_LOOP_IN, INNER_LOOP_OUT); 260 testRedundantPhi(INNER_LOOP_IN, INNER_LOOP_OUT);
306 testRedundantPhi(BASIC_LOOP_IN, BASIC_LOOP_OUT); 261 testRedundantPhi(BASIC_LOOP_IN, BASIC_LOOP_OUT);
307 testRedundantPhi(SCOPING_IN, SCOPING_OUT); 262 testRedundantPhi(SCOPING_IN, SCOPING_OUT);
308 testRedundantPhi(NEVER_INVOKED_IN, NEVER_INVOKED_OUT); 263 testRedundantPhi(NEVER_INVOKED_IN, NEVER_INVOKED_OUT);
309 } 264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698