OLD | NEW |
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 cps_ir.optimization.remove_refinements; | 5 library cps_ir.optimization.remove_refinements; |
6 | 6 |
7 import 'optimizers.dart' show Pass; | 7 import 'optimizers.dart' show Pass; |
8 import 'shrinking_reductions.dart' show ParentVisitor; | |
9 import 'cps_ir_nodes.dart'; | 8 import 'cps_ir_nodes.dart'; |
10 | 9 |
11 /// Removes all [Refinement] nodes from the IR. | 10 /// Removes all [Refinement] nodes from the IR. |
12 /// | 11 /// |
13 /// This simplifies subsequent passes that don't rely on path-sensitive | 12 /// This simplifies subsequent passes that don't rely on path-sensitive |
14 /// type information but depend on equality between primitives. | 13 /// type information but depend on equality between primitives. |
15 class RemoveRefinements extends RecursiveVisitor implements Pass { | 14 class RemoveRefinements extends TrampolineRecursiveVisitor implements Pass { |
16 String get passName => 'Remove refinement nodes'; | 15 String get passName => 'Remove refinement nodes'; |
17 | 16 |
18 void rewrite(FunctionDefinition node) { | 17 void rewrite(FunctionDefinition node) { |
19 new ParentVisitor().visit(node); | |
20 visit(node); | 18 visit(node); |
21 } | 19 } |
22 | 20 |
23 @override | 21 @override |
24 Expression traverseLetPrim(LetPrim node) { | 22 Expression traverseLetPrim(LetPrim node) { |
25 Expression next = node.body; | 23 Expression next = node.body; |
26 if (node.primitive is Refinement) { | 24 if (node.primitive is Refinement) { |
27 Refinement refinement = node.primitive; | 25 Refinement refinement = node.primitive; |
28 refinement.value.definition.substituteFor(refinement); | 26 refinement.value.definition.substituteFor(refinement); |
29 refinement.destroy(); | 27 refinement.destroy(); |
30 node.remove(); | 28 node.remove(); |
31 } | 29 } |
32 return next; | 30 return next; |
33 } | 31 } |
34 } | 32 } |
OLD | NEW |