Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 library dart2js.cps_ir.redundant_refinement; | |
| 2 | |
| 3 import 'cps_ir_nodes.dart'; | |
| 4 import 'optimizers.dart' show Pass; | |
| 5 import 'type_mask_system.dart'; | |
| 6 | |
| 7 /// Removes [Refinement] nodes where the input value is already known to | |
| 8 /// satisfy the refinement type. | |
| 9 /// | |
| 10 /// Note: This pass improves loop-invariant code motion in the GVN pass because | |
| 11 /// GVN will currently not hoist a primitive across a refinement guard. | |
| 12 /// But some opportunities for hoisting are still missed. Ideally, this pass | |
|
sra1
2015/11/17 05:41:15
Which are still missed?
asgerf
2015/11/17 12:43:43
Added example.
| |
| 13 /// should go away and GVN should handle refinements directly. | |
| 14 class RedundantRefinementEliminator extends TrampolineRecursiveVisitor | |
| 15 implements Pass { | |
| 16 String get passName => 'Redundant refinement elimination'; | |
| 17 | |
| 18 TypeMaskSystem typeSystem; | |
| 19 | |
| 20 RedundantRefinementEliminator(this.typeSystem); | |
| 21 | |
| 22 void rewrite(FunctionDefinition node) { | |
| 23 visit(node); | |
| 24 } | |
| 25 | |
| 26 Expression traverseLetPrim(LetPrim node) { | |
| 27 Expression next = node.body; | |
| 28 if (node.primitive is Refinement) { | |
| 29 Refinement refinement = node.primitive; | |
| 30 Primitive value = refinement.value.definition; | |
| 31 if (typeSystem.isMorePreciseOrEqual(value.type, refinement.refineType)) { | |
| 32 value.substituteFor(refinement); | |
| 33 refinement.destroy(); | |
| 34 node.remove(); | |
| 35 return next; | |
| 36 } | |
| 37 } | |
| 38 return next; | |
| 39 } | |
| 40 } | |
| OLD | NEW |