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 dart2js.cps_ir.redundant_refinement; | 5 library dart2js.cps_ir.redundant_refinement; |
6 | 6 |
7 import 'cps_ir_nodes.dart'; | 7 import 'cps_ir_nodes.dart'; |
8 import 'optimizers.dart' show Pass; | 8 import 'optimizers.dart' show Pass; |
9 import 'type_mask_system.dart'; | 9 import 'type_mask_system.dart'; |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 /// class B extends A {} | 21 /// class B extends A {} |
22 /// | 22 /// |
23 /// var x = getA(); // Return type is subclass of A. | 23 /// var x = getA(); // Return type is subclass of A. |
24 /// while (x is B) { // Refinement to B is not redundant. | 24 /// while (x is B) { // Refinement to B is not redundant. |
25 /// x.field.baz++; // x.field is safe for hoisting, | 25 /// x.field.baz++; // x.field is safe for hoisting, |
26 /// } // but blocked by the refinement node. | 26 /// } // but blocked by the refinement node. |
27 /// | 27 /// |
28 /// Ideally, this pass should go away and GVN should handle refinements | 28 /// Ideally, this pass should go away and GVN should handle refinements |
29 /// directly. | 29 /// directly. |
30 class RedundantRefinementEliminator extends TrampolineRecursiveVisitor | 30 class RedundantRefinementEliminator extends TrampolineRecursiveVisitor |
31 implements Pass { | 31 implements Pass { |
32 String get passName => 'Redundant refinement elimination'; | 32 String get passName => 'Redundant refinement elimination'; |
33 | 33 |
34 TypeMaskSystem typeSystem; | 34 TypeMaskSystem typeSystem; |
35 | 35 |
36 RedundantRefinementEliminator(this.typeSystem); | 36 RedundantRefinementEliminator(this.typeSystem); |
37 | 37 |
38 void rewrite(FunctionDefinition node) { | 38 void rewrite(FunctionDefinition node) { |
39 visit(node); | 39 visit(node); |
40 } | 40 } |
41 | 41 |
42 Expression traverseLetPrim(LetPrim node) { | 42 Expression traverseLetPrim(LetPrim node) { |
43 Expression next = node.body; | 43 Expression next = node.body; |
44 if (node.primitive is Refinement) { | 44 if (node.primitive is Refinement) { |
45 Refinement refinement = node.primitive; | 45 Refinement refinement = node.primitive; |
46 Primitive value = refinement.value.definition; | 46 Primitive value = refinement.value.definition; |
47 if (typeSystem.isMorePreciseOrEqual(value.type, refinement.refineType)) { | 47 if (typeSystem.isMorePreciseOrEqual(value.type, refinement.refineType)) { |
48 refinement..replaceUsesWith(value)..destroy(); | 48 refinement |
| 49 ..replaceUsesWith(value) |
| 50 ..destroy(); |
49 node.remove(); | 51 node.remove(); |
50 return next; | 52 return next; |
51 } | 53 } |
52 } | 54 } |
53 return next; | 55 return next; |
54 } | 56 } |
55 } | 57 } |
OLD | NEW |