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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/redundant_join.dart

Issue 1251083002: dart2js cps: Avoid deep recursion using trampolines and basic blocks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebase Created 5 years, 5 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart2js.cps_ir.redundant_join_elimination; 5 library dart2js.cps_ir.redundant_join_elimination;
6 6
7 import 'cps_ir_nodes.dart'; 7 import 'cps_ir_nodes.dart';
8 import 'optimizers.dart'; 8 import 'optimizers.dart';
9 9
10 /// Eliminates redundant join points. 10 /// Eliminates redundant join points.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 /// 227 ///
228 /// After lifting LetConts in the main pass above, parameter objects can have 228 /// After lifting LetConts in the main pass above, parameter objects can have
229 /// multiple bindings. Each reference implicitly refers to the binding that 229 /// multiple bindings. Each reference implicitly refers to the binding that
230 /// is currently in scope. 230 /// is currently in scope.
231 /// 231 ///
232 /// This returns the IR to its normal form after redundant joins have been 232 /// This returns the IR to its normal form after redundant joins have been
233 /// eliminated. 233 /// eliminated.
234 class AlphaRenamer extends RecursiveVisitor { 234 class AlphaRenamer extends RecursiveVisitor {
235 Map<Parameter, Parameter> renaming = <Parameter, Parameter>{}; 235 Map<Parameter, Parameter> renaming = <Parameter, Parameter>{};
236 236
237 visitContinuation(Continuation cont) { 237 processContinuation(Continuation cont) {
238 if (cont.isReturnContinuation) return; 238 if (cont.isReturnContinuation) return;
239 239
240 List<Parameter> shadowedKeys = <Parameter>[]; 240 List<Parameter> shadowedKeys = <Parameter>[];
241 List<Parameter> shadowedValues = <Parameter>[]; 241 List<Parameter> shadowedValues = <Parameter>[];
242 242
243 // Create new parameters and update the environment. 243 // Create new parameters and update the environment.
244 for (int i = 0; i < cont.parameters.length; ++i) { 244 for (int i = 0; i < cont.parameters.length; ++i) {
245 Parameter param = cont.parameters[i]; 245 Parameter param = cont.parameters[i];
246 shadowedKeys.add(param); 246 shadowedKeys.add(param);
247 shadowedValues.add(renaming.remove(param)); 247 shadowedValues.add(renaming.remove(param));
248 // If the parameter appears to belong to another continuation, 248 // If the parameter appears to belong to another continuation,
249 // create a new parameter object for this continuation. 249 // create a new parameter object for this continuation.
250 if (param.parent != cont) { 250 if (param.parent != cont) {
251 Parameter newParam = new Parameter(param.hint); 251 Parameter newParam = new Parameter(param.hint);
252 renaming[param] = newParam; 252 renaming[param] = newParam;
253 cont.parameters[i] = newParam; 253 cont.parameters[i] = newParam;
254 newParam.parent = cont; 254 newParam.parent = cont;
255 } 255 }
256 } 256 }
257 257
258 // Visit the body with the updated environment. 258 pushAction(() {
259 visit(cont.body); 259 // Restore the original environment.
260 260 for (int i = 0; i < cont.parameters.length; ++i) {
261 // Restore the original environment. 261 renaming.remove(cont.parameters[i]);
262 for (int i = 0; i < cont.parameters.length; ++i) { 262 if (shadowedValues[i] != null) {
263 renaming.remove(cont.parameters[i]); 263 renaming[shadowedKeys[i]] = shadowedValues[i];
264 if (shadowedValues[i] != null) { 264 }
265 renaming[shadowedKeys[i]] = shadowedValues[i];
266 } 265 }
267 } 266 });
268 } 267 }
269 268
270 processReference(Reference ref) { 269 processReference(Reference ref) {
271 Parameter target = renaming[ref.definition]; 270 Parameter target = renaming[ref.definition];
272 if (target != null) { 271 if (target != null) {
273 ref.changeTo(target); 272 ref.changeTo(target);
274 } 273 }
275 } 274 }
276 } 275 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/mutable_ssa.dart ('k') | pkg/compiler/lib/src/cps_ir/type_propagation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698