OLD | NEW |
1 library dart2js.cps_ir.update_refinements; | 1 library dart2js.cps_ir.update_refinements; |
2 | 2 |
3 import 'cps_ir_nodes.dart'; | 3 import 'cps_ir_nodes.dart'; |
4 import 'optimizers.dart' show Pass; | 4 import 'optimizers.dart' show Pass; |
5 import 'type_mask_system.dart'; | 5 import 'type_mask_system.dart'; |
6 import '../world.dart'; | 6 import '../world.dart'; |
7 | 7 |
8 /// Updates all references to use the most refined version in scope. | 8 /// Updates all references to use the most refined version in scope. |
9 /// | 9 /// |
10 /// [GVN] and [RedundantJoinElimination], and possibly other passes, can create | 10 /// [GVN] and [RedundantJoinElimination], and possibly other passes, can create |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 visitReceiverCheck(ReceiverCheck node) { | 39 visitReceiverCheck(ReceiverCheck node) { |
40 if (refine(node.valueRef)) { | 40 if (refine(node.valueRef)) { |
41 // Update the type if the input has changed. | 41 // Update the type if the input has changed. |
42 Primitive value = node.value; | 42 Primitive value = node.value; |
43 if (value.type.needsNoSuchMethodHandling(node.selector, classWorld)) { | 43 if (value.type.needsNoSuchMethodHandling(node.selector, classWorld)) { |
44 node.type = typeSystem.receiverTypeFor(node.selector, value.type); | 44 node.type = typeSystem.receiverTypeFor(node.selector, value.type); |
45 } else { | 45 } else { |
46 // Check is no longer needed. | 46 // Check is no longer needed. |
47 node..replaceUsesWith(value)..destroy(); | 47 node |
| 48 ..replaceUsesWith(value) |
| 49 ..destroy(); |
48 LetPrim letPrim = node.parent; | 50 LetPrim letPrim = node.parent; |
49 letPrim.remove(); | 51 letPrim.remove(); |
50 return; | 52 return; |
51 } | 53 } |
52 } | 54 } |
53 // Use the ReceiverCheck as a refinement. | 55 // Use the ReceiverCheck as a refinement. |
54 Primitive value = node.effectiveDefinition; | 56 Primitive value = node.effectiveDefinition; |
55 Primitive old = refinementFor[value]; | 57 Primitive old = refinementFor[value]; |
56 refinementFor[value] = node; | 58 refinementFor[value] = node; |
57 pushAction(() { | 59 pushAction(() { |
58 refinementFor[value] = old; | 60 refinementFor[value] = old; |
59 }); | 61 }); |
60 } | 62 } |
61 | 63 |
62 visitRefinement(Refinement node) { | 64 visitRefinement(Refinement node) { |
63 if (refine(node.value)) { | 65 if (refine(node.value)) { |
64 // Update the type if the input has changed. | 66 // Update the type if the input has changed. |
65 node.type = typeSystem.intersection(node.value.definition.type, | 67 node.type = |
66 node.refineType); | 68 typeSystem.intersection(node.value.definition.type, node.refineType); |
67 } | 69 } |
68 Primitive value = node.effectiveDefinition; | 70 Primitive value = node.effectiveDefinition; |
69 Primitive old = refinementFor[value]; | 71 Primitive old = refinementFor[value]; |
70 refinementFor[value] = node; | 72 refinementFor[value] = node; |
71 pushAction(() { | 73 pushAction(() { |
72 refinementFor[value] = old; | 74 refinementFor[value] = old; |
73 }); | 75 }); |
74 } | 76 } |
75 | 77 |
76 visitBoundsCheck(BoundsCheck node) { | 78 visitBoundsCheck(BoundsCheck node) { |
77 super.visitBoundsCheck(node); | 79 super.visitBoundsCheck(node); |
78 if (node.hasIntegerCheck && | 80 if (node.hasIntegerCheck && typeSystem.isDefinitelyInt(node.index.type)) { |
79 typeSystem.isDefinitelyInt(node.index.type)) { | |
80 node.checks &= ~BoundsCheck.INTEGER; | 81 node.checks &= ~BoundsCheck.INTEGER; |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 processReference(Reference ref) { | 85 processReference(Reference ref) { |
85 refine(ref); | 86 refine(ref); |
86 } | 87 } |
87 | 88 |
88 bool refine(Reference ref) { | 89 bool refine(Reference ref) { |
89 Definition def = ref.definition; | 90 Definition def = ref.definition; |
90 if (def is Primitive) { | 91 if (def is Primitive) { |
91 Primitive refinement = refinementFor[def.effectiveDefinition]; | 92 Primitive refinement = refinementFor[def.effectiveDefinition]; |
92 if (refinement != null && refinement != ref.definition) { | 93 if (refinement != null && refinement != ref.definition) { |
93 ref.changeTo(refinement); | 94 ref.changeTo(refinement); |
94 return true; | 95 return true; |
95 } | 96 } |
96 } | 97 } |
97 return false; | 98 return false; |
98 } | 99 } |
99 } | 100 } |
OLD | NEW |