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

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

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

Powered by Google App Engine
This is Rietveld 408576698