| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 | 182 |
| 183 /// Moves [letCont] below the binding of [definition] within the IR graph. | 183 /// Moves [letCont] below the binding of [definition] within the IR graph. |
| 184 /// Does nothing if [letCont] is already within the scope of [definition]. | 184 /// Does nothing if [letCont] is already within the scope of [definition]. |
| 185 /// Assumes that one argument is nested within the scope of the other | 185 /// Assumes that one argument is nested within the scope of the other |
| 186 /// when this method is called. | 186 /// when this method is called. |
| 187 void _moveIntoScopeOf(LetCont letCont, Definition definition) { | 187 void _moveIntoScopeOf(LetCont letCont, Definition definition) { |
| 188 if (_isInScopeOf(letCont, definition)) return; | 188 if (_isInScopeOf(letCont, definition)) return; |
| 189 | 189 |
| 190 // Remove the continuation binding from its current spot. | |
| 191 InteriorNode parent = letCont.parent; | |
| 192 parent.body = letCont.body; | |
| 193 letCont.body.parent = parent; | |
| 194 | |
| 195 // Insert it just below the binding of definition. | |
| 196 InteriorNode binding = definition.parent; | 190 InteriorNode binding = definition.parent; |
| 197 | 191 letCont.remove(); |
| 198 letCont.body = binding.body; | 192 letCont.insertBelow(binding); |
| 199 binding.body.parent = letCont; | |
| 200 | |
| 201 binding.body = letCont; | |
| 202 letCont.parent = binding; | |
| 203 } | 193 } |
| 204 | 194 |
| 205 /// Ensures [continuation] has its own LetCont binding by creating | 195 /// Ensures [continuation] has its own LetCont binding by creating |
| 206 /// a new LetCont below its current binding, if necessary. | 196 /// a new LetCont below its current binding, if necessary. |
| 207 /// | 197 /// |
| 208 /// Returns the LetCont that now binds [continuation]. | 198 /// Returns the LetCont that now binds [continuation]. |
| 209 LetCont _makeUniqueBinding(Continuation continuation) { | 199 LetCont _makeUniqueBinding(Continuation continuation) { |
| 210 LetCont letCont = continuation.parent; | 200 LetCont letCont = continuation.parent; |
| 211 if (letCont.continuations.length == 1) return letCont; | 201 if (letCont.continuations.length == 1) return letCont; |
| 212 letCont.continuations.remove(continuation); | 202 letCont.continuations.remove(continuation); |
| 213 LetCont newBinding = new LetCont(continuation, letCont.body); | 203 LetCont newBinding = new LetCont(continuation, null); |
| 214 newBinding.body.parent = newBinding; | |
| 215 newBinding.parent = letCont; | |
| 216 letCont.body = newBinding; | |
| 217 continuation.parent = newBinding; | 204 continuation.parent = newBinding; |
| 205 newBinding.insertBelow(letCont); |
| 218 return newBinding; | 206 return newBinding; |
| 219 } | 207 } |
| OLD | NEW |