| 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.insert_refinements; | 5 library cps_ir.optimization.insert_refinements; |
| 6 | 6 |
| 7 import 'optimizers.dart' show Pass; | 7 import 'optimizers.dart' show Pass; |
| 8 import 'shrinking_reductions.dart' show ParentVisitor; | 8 import 'shrinking_reductions.dart' show ParentVisitor; |
| 9 import 'cps_ir_nodes.dart'; | 9 import 'cps_ir_nodes.dart'; |
| 10 import '../types/types.dart'; | 10 import '../types/types.dart'; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 Primitive value = condition.value.definition; | 175 Primitive value = condition.value.definition; |
| 176 ClassElement classElement = condition.type.element; | 176 ClassElement classElement = condition.type.element; |
| 177 TypeMask type = new TypeMask.nonNullSubtype(classElement, world); | 177 TypeMask type = new TypeMask.nonNullSubtype(classElement, world); |
| 178 Primitive refinedValue = new Refinement(value, type); | 178 Primitive refinedValue = new Refinement(value, type); |
| 179 pushRefinement(trueCont, refinedValue); | 179 pushRefinement(trueCont, refinedValue); |
| 180 push(falseCont); | 180 push(falseCont); |
| 181 return; | 181 return; |
| 182 } | 182 } |
| 183 | 183 |
| 184 // If the condition is comparison with a constant, promote the other value. | 184 // If the condition is comparison with a constant, promote the other value. |
| 185 if (call is InvokeMethod && call.selector == Selectors.equals) { | 185 // This can happen either for calls to `==` or `identical` calls, such |
| 186 Primitive first = call.arguments[0].definition; | 186 // as the ones inserted by the unsugaring pass. |
| 187 Primitive second = call.arguments[1].definition; | 187 |
| 188 void refineEquality(Primitive first, |
| 189 Primitive second, |
| 190 Continuation trueCont, |
| 191 Continuation falseCont) { |
| 188 if (second is Constant && second.value.isNull) { | 192 if (second is Constant && second.value.isNull) { |
| 189 Refinement refinedTrue = new Refinement(first, nullType); | 193 Refinement refinedTrue = new Refinement(first, nullType); |
| 190 Refinement refinedFalse = new Refinement(first, nonNullType); | 194 Refinement refinedFalse = new Refinement(first, nonNullType); |
| 191 pushRefinement(trueCont, refinedTrue); | 195 pushRefinement(trueCont, refinedTrue); |
| 192 pushRefinement(falseCont, refinedFalse); | 196 pushRefinement(falseCont, refinedFalse); |
| 193 return; | 197 } else if (first is Constant && first.value.isNull) { |
| 194 } | |
| 195 if (first is Constant && first.value.isNull) { | |
| 196 Refinement refinedTrue = new Refinement(second, nullType); | 198 Refinement refinedTrue = new Refinement(second, nullType); |
| 197 Refinement refinedFalse = new Refinement(second, nonNullType); | 199 Refinement refinedFalse = new Refinement(second, nonNullType); |
| 198 pushRefinement(trueCont, refinedTrue); | 200 pushRefinement(trueCont, refinedTrue); |
| 199 pushRefinement(falseCont, refinedFalse); | 201 pushRefinement(falseCont, refinedFalse); |
| 200 return; | 202 } else { |
| 203 push(trueCont); |
| 204 push(falseCont); |
| 201 } | 205 } |
| 202 } | 206 } |
| 203 | 207 |
| 208 if (call is InvokeMethod && call.selector == Selectors.equals) { |
| 209 refineEquality(call.arguments[0].definition, |
| 210 call.arguments[1].definition, |
| 211 trueCont, |
| 212 falseCont); |
| 213 return; |
| 214 } |
| 215 |
| 216 if (condition is ApplyBuiltinOperator && |
| 217 condition.operator == BuiltinOperator.Identical) { |
| 218 refineEquality(condition.arguments[0].definition, |
| 219 condition.arguments[1].definition, |
| 220 trueCont, |
| 221 falseCont); |
| 222 return; |
| 223 } |
| 224 |
| 204 push(trueCont); | 225 push(trueCont); |
| 205 push(falseCont); | 226 push(falseCont); |
| 206 } | 227 } |
| 207 | 228 |
| 208 @override | 229 @override |
| 209 Expression traverseLetCont(LetCont node) { | 230 Expression traverseLetCont(LetCont node) { |
| 210 for (Continuation cont in node.continuations) { | 231 for (Continuation cont in node.continuations) { |
| 211 if (cont.hasExactlyOneUse && | 232 if (cont.hasExactlyOneUse && |
| 212 (cont.firstRef.parent is InvokeMethod || | 233 (cont.firstRef.parent is InvokeMethod || |
| 213 cont.firstRef.parent is Branch)) { | 234 cont.firstRef.parent is Branch)) { |
| 214 // Do not push the continuation here. | 235 // Do not push the continuation here. |
| 215 // visitInvokeMethod and visitBranch will do that. | 236 // visitInvokeMethod and visitBranch will do that. |
| 216 } else { | 237 } else { |
| 217 push(cont); | 238 push(cont); |
| 218 } | 239 } |
| 219 } | 240 } |
| 220 return node.body; | 241 return node.body; |
| 221 } | 242 } |
| 222 } | 243 } |
| OLD | NEW |