| OLD | NEW |
| 1 library dart2js.cps_ir.backward_null_check_remover; | 1 library dart2js.cps_ir.backward_null_check_remover; |
| 2 | 2 |
| 3 import 'cps_ir_nodes.dart'; | 3 import 'cps_ir_nodes.dart'; |
| 4 import 'optimizers.dart' show Pass; | 4 import 'optimizers.dart'; |
| 5 import '../common/names.dart'; | 5 import '../common/names.dart'; |
| 6 import '../universe/selector.dart'; | 6 import '../universe/selector.dart'; |
| 7 import 'type_mask_system.dart'; | 7 import 'type_mask_system.dart'; |
| 8 import 'cps_fragment.dart'; | 8 import 'cps_fragment.dart'; |
| 9 | 9 |
| 10 /// Removes null checks that are follwed by another instruction that will | 10 /// Removes null checks that are follwed by another instruction that will |
| 11 /// perform the same check. | 11 /// perform the same check. |
| 12 /// | 12 /// |
| 13 /// For example: | 13 /// For example: |
| 14 /// | 14 /// |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 /// Returns a reference to an operand of [prim], where [prim] throws if null | 53 /// Returns a reference to an operand of [prim], where [prim] throws if null |
| 54 /// is passed into that operand. | 54 /// is passed into that operand. |
| 55 Reference<Primitive> getNullCheckedOperand(Primitive prim) { | 55 Reference<Primitive> getNullCheckedOperand(Primitive prim) { |
| 56 if (prim is NullCheck) return prim.value; | 56 if (prim is NullCheck) return prim.value; |
| 57 if (prim is GetLength) return prim.object; | 57 if (prim is GetLength) return prim.object; |
| 58 if (prim is GetField) return prim.object; | 58 if (prim is GetField) return prim.object; |
| 59 if (prim is GetIndex) return prim.object; | 59 if (prim is GetIndex) return prim.object; |
| 60 if (prim is SetField) return prim.object; | 60 if (prim is SetField) return prim.object; |
| 61 if (prim is SetIndex) return prim.object; | 61 if (prim is SetIndex) return prim.object; |
| 62 if (prim is InvokeMethod && !nullSelectors.contains(prim.selector)) { | 62 if (prim is InvokeMethod && !selectorsOnNull.contains(prim.selector)) { |
| 63 return prim.dartReceiverReference; | 63 return prim.dartReceiverReference; |
| 64 } | 64 } |
| 65 return null; | 65 return null; |
| 66 } | 66 } |
| 67 | 67 |
| 68 static final List<Selector> nullSelectors = <Selector>[ | |
| 69 Selectors.equals, Selectors.hashCode_, Selectors.noSuchMethod_, | |
| 70 Selectors.runtimeType_]; | |
| 71 | |
| 72 /// It has been determined that the null check in [prim] made redundant by | 68 /// It has been determined that the null check in [prim] made redundant by |
| 73 /// [newNullCheck]. Eliminate [prim] if it is not needed any more. | 69 /// [newNullCheck]. Eliminate [prim] if it is not needed any more. |
| 74 void tryEliminateRedundantNullCheck(Primitive prim, Primitive newNullCheck) { | 70 void tryEliminateRedundantNullCheck(Primitive prim, Primitive newNullCheck) { |
| 75 if (prim is NullCheck) { | 71 if (prim is NullCheck) { |
| 76 Primitive value = prim.value.definition; | 72 Primitive value = prim.value.definition; |
| 77 LetPrim let = prim.parent; | 73 LetPrim let = prim.parent; |
| 78 prim..replaceUsesWith(value)..destroy(); | 74 prim..replaceUsesWith(value)..destroy(); |
| 79 let.remove(); | 75 let.remove(); |
| 80 } else if (prim is GetLength || prim is GetField || prim is GetIndex) { | 76 } else if (prim is GetLength || prim is GetField || prim is GetIndex) { |
| 81 if (prim.hasNoEffectiveUses) { | 77 if (prim.hasNoEffectiveUses) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 void visitLetHandler(LetHandler node) { | 117 void visitLetHandler(LetHandler node) { |
| 122 nullCheckedValue = null; | 118 nullCheckedValue = null; |
| 123 } | 119 } |
| 124 | 120 |
| 125 visitInvokeContinuation(InvokeContinuation node) { | 121 visitInvokeContinuation(InvokeContinuation node) { |
| 126 if (!node.isRecursive) { | 122 if (!node.isRecursive) { |
| 127 nullCheckedValue = nullCheckedValueAt[node.continuation.definition]; | 123 nullCheckedValue = nullCheckedValueAt[node.continuation.definition]; |
| 128 } | 124 } |
| 129 } | 125 } |
| 130 } | 126 } |
| OLD | NEW |