| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart2js.cps_ir.redundant_phi_elimination; | 5 library dart2js.cps_ir.redundant_phi_elimination; |
| 6 | 6 |
| 7 import 'cps_ir_nodes.dart'; | 7 import 'cps_ir_nodes.dart'; |
| 8 import 'optimizers.dart'; | 8 import 'optimizers.dart'; |
| 9 | 9 |
| 10 /// Eliminate redundant phis from the given [FunctionDefinition]. | 10 /// Eliminate redundant phis from the given [FunctionDefinition]. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 for (InvokeContinuation invoke in invokes) { | 145 for (InvokeContinuation invoke in invokes) { |
| 146 invoke.arguments[src].unlink(); | 146 invoke.arguments[src].unlink(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Finally, if the substituted definition is not in scope of the affected | 149 // Finally, if the substituted definition is not in scope of the affected |
| 150 // continuation, move the continuation binding. This is safe to do since | 150 // continuation, move the continuation binding. This is safe to do since |
| 151 // the continuation is referenced only as the target in continuation | 151 // the continuation is referenced only as the target in continuation |
| 152 // invokes, and all such invokes must be within the scope of | 152 // invokes, and all such invokes must be within the scope of |
| 153 // [uniqueDefinition]. Note that this is linear in the depth of | 153 // [uniqueDefinition]. Note that this is linear in the depth of |
| 154 // the binding of [uniqueDefinition]. | 154 // the binding of [uniqueDefinition]. |
| 155 assert(letCont != null); | 155 letCont = _makeUniqueBinding(cont); |
| 156 _moveIntoScopeOf(letCont, uniqueDefinition); | 156 _moveIntoScopeOf(letCont, uniqueDefinition); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Remove trailing items from parameter and argument lists. | 159 // Remove trailing items from parameter and argument lists. |
| 160 cont.parameters.length = dst; | 160 cont.parameters.length = dst; |
| 161 for (InvokeContinuation invoke in invokes) { | 161 for (InvokeContinuation invoke in invokes) { |
| 162 invoke.arguments.length = dst; | 162 invoke.arguments.length = dst; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 194 | 194 |
| 195 // Insert it just below the binding of definition. | 195 // Insert it just below the binding of definition. |
| 196 InteriorNode binding = definition.parent; | 196 InteriorNode binding = definition.parent; |
| 197 | 197 |
| 198 letCont.body = binding.body; | 198 letCont.body = binding.body; |
| 199 binding.body.parent = letCont; | 199 binding.body.parent = letCont; |
| 200 | 200 |
| 201 binding.body = letCont; | 201 binding.body = letCont; |
| 202 letCont.parent = binding; | 202 letCont.parent = binding; |
| 203 } | 203 } |
| 204 |
| 205 /// Ensures [continuation] has its own LetCont binding by creating |
| 206 /// a new LetCont below its current binding, if necessary. |
| 207 /// |
| 208 /// Returns the LetCont that now binds [continuation]. |
| 209 LetCont _makeUniqueBinding(Continuation continuation) { |
| 210 LetCont letCont = continuation.parent; |
| 211 if (letCont.continuations.length == 1) return letCont; |
| 212 letCont.continuations.remove(continuation); |
| 213 LetCont newBinding = new LetCont(continuation, letCont.body); |
| 214 newBinding.body.parent = newBinding; |
| 215 newBinding.parent = letCont; |
| 216 letCont.body = newBinding; |
| 217 continuation.parent = newBinding; |
| 218 return newBinding; |
| 219 } |
| OLD | NEW |