| 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/constants.dart'; | 10 import '../types/constants.dart'; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 assert(!cont.isRecursive); | 61 assert(!cont.isRecursive); |
| 62 LetCont let = cont.parent; | 62 LetCont let = cont.parent; |
| 63 InteriorNode useParent = use.parent; | 63 InteriorNode useParent = use.parent; |
| 64 if (useParent == let) return; | 64 if (useParent == let) return; |
| 65 if (let.continuations.length > 1) { | 65 if (let.continuations.length > 1) { |
| 66 // Create a new LetCont binding only this continuation. | 66 // Create a new LetCont binding only this continuation. |
| 67 let.continuations.remove(cont); | 67 let.continuations.remove(cont); |
| 68 let = new LetCont(cont, null); | 68 let = new LetCont(cont, null); |
| 69 cont.parent = let; | 69 cont.parent = let; |
| 70 } else { | 70 } else { |
| 71 let.remove(); // Reuse the existing LetCont. | 71 // Remove LetCont from current position. |
| 72 InteriorNode letParent = let.parent; |
| 73 letParent.body = let.body; |
| 74 let.body.parent = letParent; |
| 72 } | 75 } |
| 73 let.insertAbove(use); | 76 |
| 77 // Insert LetCont before use. |
| 78 useParent.body = let; |
| 79 let.body = use; |
| 80 use.parent = let; |
| 81 let.parent = useParent; |
| 74 } | 82 } |
| 75 | 83 |
| 76 Primitive unfoldInterceptor(Primitive prim) { | 84 Primitive unfoldInterceptor(Primitive prim) { |
| 77 return prim is Interceptor ? prim.input.definition : prim; | 85 return prim is Interceptor ? prim.input.definition : prim; |
| 78 } | 86 } |
| 79 | 87 |
| 80 /// Enqueues [cont] for processing in a context where [refined] is the | 88 /// Enqueues [cont] for processing in a context where [refined] is the |
| 81 /// current refinement for its value. | 89 /// current refinement for its value. |
| 82 void pushRefinement(Continuation cont, Refinement refined) { | 90 void pushRefinement(Continuation cont, Refinement refined) { |
| 83 Primitive value = refined.effectiveDefinition; | 91 Primitive value = refined.effectiveDefinition; |
| 84 Primitive currentRefinement = refinementFor[value]; | 92 Primitive currentRefinement = refinementFor[value]; |
| 85 pushAction(() { | 93 pushAction(() { |
| 86 refinementFor[value] = currentRefinement; | 94 refinementFor[value] = currentRefinement; |
| 87 if (refined.hasNoUses) { | 95 if (refined.hasNoUses) { |
| 88 // Clean up refinements that are not used. | 96 // Clean up refinements that are not used. |
| 89 refined.destroy(); | 97 refined.value.unlink(); |
| 90 } else { | 98 } else { |
| 91 LetPrim let = new LetPrim(refined); | 99 cont.body = new LetPrim(refined, cont.body); |
| 92 refined.parent = let; | 100 refined.parent = cont.body; |
| 93 let.insertBelow(cont); | 101 refined.value.parent = refined; |
| 94 } | 102 } |
| 95 }); | 103 }); |
| 96 push(cont); | 104 push(cont); |
| 97 pushAction(() { | 105 pushAction(() { |
| 98 refinementFor[value] = refined; | 106 refinementFor[value] = refined; |
| 99 }); | 107 }); |
| 100 } | 108 } |
| 101 | 109 |
| 102 void visitInvokeMethod(InvokeMethod node) { | 110 void visitInvokeMethod(InvokeMethod node) { |
| 103 Continuation cont = node.continuation.definition; | 111 Continuation cont = node.continuation.definition; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 cont.firstRef.parent is Branch)) { | 223 cont.firstRef.parent is Branch)) { |
| 216 // Do not push the continuation here. | 224 // Do not push the continuation here. |
| 217 // visitInvokeMethod and visitBranch will do that. | 225 // visitInvokeMethod and visitBranch will do that. |
| 218 } else { | 226 } else { |
| 219 push(cont); | 227 push(cont); |
| 220 } | 228 } |
| 221 } | 229 } |
| 222 return node.body; | 230 return node.body; |
| 223 } | 231 } |
| 224 } | 232 } |
| OLD | NEW |