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

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

Issue 708993003: Revert "Revert "dart2js: Add a type parameter to class Reference...."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 (LetPrim v0 (Constant IntConstant(0))) 185 (LetPrim v0 (Constant IntConstant(0)))
186 (LetCont (k0) 186 (LetCont (k0)
187 (InvokeStatic print v0 return)) 187 (InvokeStatic print v0 return))
188 (LetPrim v1 (Constant NullConstant)) 188 (LetPrim v1 (Constant NullConstant))
189 (InvokeContinuation k0 )) 189 (InvokeContinuation k0 ))
190 """; 190 """;
191 191
192 // Ensures that continuations which are never invoked are not optimized. 192 // Ensures that continuations which are never invoked are not optimized.
193 // IR written by hand. 193 // IR written by hand.
194 194
195 String NEVER_INVOKED1_IN = """ 195 String NEVER_INVOKED_IN = """
196 (FunctionDefinition main ( return) 196 (FunctionDefinition main ( return)
197 (LetPrim v0 (Constant IntConstant(0))) 197 (LetPrim v0 (Constant IntConstant(0)))
198 (LetCont (k0 v1) 198 (LetCont (k0 v1)
199 (InvokeStatic print v1 return)) 199 (InvokeStatic print v1 return))
200 (InvokeContinuation return v0)) 200 (InvokeContinuation return v0))
201 """; 201 """;
202 202
203 String NEVER_INVOKED1_OUT = NEVER_INVOKED1_IN; 203 String NEVER_INVOKED_OUT = NEVER_INVOKED_IN;
204
205 // As in the previous test, except with the added wrinkle of higher order
206 // continuations.
207
208 String NEVER_INVOKED2_IN = """
209 (FunctionDefinition main ( return)
210 (LetCont (k0 v0)
211 (InvokeStatic print v0 return))
212 (InvokeContinuation return k0))
213 """;
214
215 String NEVER_INVOKED2_OUT = NEVER_INVOKED2_IN;
216
217 // As in the previous test, but the continuation is invoked as well as passed
218 // as an argument.
219
220 String AS_ARG_IN = """
221 (FunctionDefinition main ( return)
222 (LetCont (k0 v0)
223 (InvokeStatic print v0 return))
224 (InvokeContinuation k0 k0))
225 """;
226
227 String AS_ARG_OUT = AS_ARG_IN;
228 204
229 /// Normalizes whitespace by replacing all whitespace sequences by a single 205 /// Normalizes whitespace by replacing all whitespace sequences by a single
230 /// space and trimming leading and trailing whitespace. 206 /// space and trimming leading and trailing whitespace.
231 String normalizeSExpr(String input) { 207 String normalizeSExpr(String input) {
232 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); 208 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim();
233 } 209 }
234 210
235 /// Parses the given input IR, runs a redundant phi pass over it, and compares 211 /// Parses the given input IR, runs a redundant phi pass over it, and compares
236 /// the stringification of the result against the expected output. 212 /// the stringification of the result against the expected output.
237 void testRedundantPhi(String input, String expectedOutput) { 213 void testRedundantPhi(String input, String expectedOutput) {
238 final unstringifier = new SExpressionUnstringifier(); 214 final unstringifier = new SExpressionUnstringifier();
239 final stringifier = new SExpressionStringifier(); 215 final stringifier = new SExpressionStringifier();
240 final optimizer = new RedundantPhiEliminator(); 216 final optimizer = new RedundantPhiEliminator();
241 217
242 FunctionDefinition f = unstringifier.unstringify(input); 218 FunctionDefinition f = unstringifier.unstringify(input);
243 optimizer.rewrite(f); 219 optimizer.rewrite(f);
244 220
245 String expected = normalizeSExpr(expectedOutput); 221 String expected = normalizeSExpr(expectedOutput);
246 String actual = normalizeSExpr(stringifier.visit(f)); 222 String actual = normalizeSExpr(stringifier.visit(f));
247 223
248 Expect.equals(expected, actual, "Actual:\n$actual"); 224 Expect.equals(expected, actual, "Actual:\n$actual");
249 } 225 }
250 226
251 void main() { 227 void main() {
252 testRedundantPhi(READ_IN_LOOP_IN, READ_IN_LOOP_OUT); 228 testRedundantPhi(READ_IN_LOOP_IN, READ_IN_LOOP_OUT);
253 testRedundantPhi(INNER_LOOP_IN, INNER_LOOP_OUT); 229 testRedundantPhi(INNER_LOOP_IN, INNER_LOOP_OUT);
254 testRedundantPhi(BASIC_LOOP_IN, BASIC_LOOP_OUT); 230 testRedundantPhi(BASIC_LOOP_IN, BASIC_LOOP_OUT);
255 testRedundantPhi(SCOPING_IN, SCOPING_OUT); 231 testRedundantPhi(SCOPING_IN, SCOPING_OUT);
256 testRedundantPhi(NEVER_INVOKED1_IN, NEVER_INVOKED1_OUT); 232 testRedundantPhi(NEVER_INVOKED_IN, NEVER_INVOKED_OUT);
257 testRedundantPhi(NEVER_INVOKED2_IN, NEVER_INVOKED2_OUT);
258 testRedundantPhi(AS_ARG_IN, AS_ARG_OUT);
259 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698