| 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 'cps_ir_nodes.dart'; | 8 import 'cps_ir_nodes.dart'; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../types/types.dart' show TypeMask; | 10 import '../types/types.dart' show TypeMask; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 void sinkContinuationToUse(Continuation cont, Expression use) { | 53 void sinkContinuationToUse(Continuation cont, Expression use) { |
| 54 assert(cont.hasExactlyOneUse && cont.firstRef.parent == use); | 54 assert(cont.hasExactlyOneUse && cont.firstRef.parent == use); |
| 55 assert(!cont.isRecursive); | 55 assert(!cont.isRecursive); |
| 56 LetCont let = cont.parent; | 56 LetCont let = cont.parent; |
| 57 InteriorNode useParent = use.parent; | 57 InteriorNode useParent = use.parent; |
| 58 if (useParent == let) return; | 58 if (useParent == let) return; |
| 59 if (let.continuations.length > 1) { | 59 if (let.continuations.length > 1) { |
| 60 // Create a new LetCont binding only this continuation. | 60 // Create a new LetCont binding only this continuation. |
| 61 let.continuations.remove(cont); | 61 let.continuations.remove(cont); |
| 62 let = new LetCont(cont, null); | 62 let = new LetCont(cont, null); |
| 63 cont.parent = let; | |
| 64 } else { | 63 } else { |
| 65 let.remove(); // Reuse the existing LetCont. | 64 let.remove(); // Reuse the existing LetCont. |
| 66 } | 65 } |
| 67 let.insertAbove(use); | 66 let.insertAbove(use); |
| 68 } | 67 } |
| 69 | 68 |
| 70 Primitive unfoldInterceptor(Primitive prim) { | 69 Primitive unfoldInterceptor(Primitive prim) { |
| 71 return prim is Interceptor ? prim.input.definition : prim; | 70 return prim is Interceptor ? prim.input.definition : prim; |
| 72 } | 71 } |
| 73 | 72 |
| 74 /// Enqueues [cont] for processing in a context where [refined] is the | 73 /// Enqueues [cont] for processing in a context where [refined] is the |
| 75 /// current refinement for its value. | 74 /// current refinement for its value. |
| 76 void pushRefinement(Continuation cont, Refinement refined) { | 75 void pushRefinement(Continuation cont, Refinement refined) { |
| 77 Primitive value = refined.effectiveDefinition; | 76 Primitive value = refined.effectiveDefinition; |
| 78 Primitive currentRefinement = refinementFor[value]; | 77 Primitive currentRefinement = refinementFor[value]; |
| 79 pushAction(() { | 78 pushAction(() { |
| 80 refinementFor[value] = currentRefinement; | 79 refinementFor[value] = currentRefinement; |
| 81 if (refined.hasNoUses) { | 80 if (refined.hasNoUses) { |
| 82 // Clean up refinements that are not used. | 81 // Clean up refinements that are not used. |
| 83 refined.destroy(); | 82 refined.destroy(); |
| 84 } else { | 83 } else { |
| 85 LetPrim let = new LetPrim(refined); | 84 LetPrim let = new LetPrim(refined); |
| 86 refined.parent = let; | |
| 87 let.insertBelow(cont); | 85 let.insertBelow(cont); |
| 88 } | 86 } |
| 89 }); | 87 }); |
| 90 push(cont); | 88 push(cont); |
| 91 pushAction(() { | 89 pushAction(() { |
| 92 refinementFor[value] = refined; | 90 refinementFor[value] = refined; |
| 93 }); | 91 }); |
| 94 } | 92 } |
| 95 | 93 |
| 96 void visitInvokeMethod(InvokeMethod node) { | 94 void visitInvokeMethod(InvokeMethod node) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 cont.firstRef.parent is Branch)) { | 208 cont.firstRef.parent is Branch)) { |
| 211 // Do not push the continuation here. | 209 // Do not push the continuation here. |
| 212 // visitInvokeMethod and visitBranch will do that. | 210 // visitInvokeMethod and visitBranch will do that. |
| 213 } else { | 211 } else { |
| 214 push(cont); | 212 push(cont); |
| 215 } | 213 } |
| 216 } | 214 } |
| 217 return node.body; | 215 return node.body; |
| 218 } | 216 } |
| 219 } | 217 } |
| OLD | NEW |