| 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. |
| 190 InteriorNode binding = definition.parent; | 196 InteriorNode binding = definition.parent; |
| 191 letCont.remove(); | 197 |
| 192 letCont.insertBelow(binding); | 198 letCont.body = binding.body; |
| 199 binding.body.parent = letCont; |
| 200 |
| 201 binding.body = letCont; |
| 202 letCont.parent = binding; |
| 193 } | 203 } |
| 194 | 204 |
| 195 /// Ensures [continuation] has its own LetCont binding by creating | 205 /// Ensures [continuation] has its own LetCont binding by creating |
| 196 /// a new LetCont below its current binding, if necessary. | 206 /// a new LetCont below its current binding, if necessary. |
| 197 /// | 207 /// |
| 198 /// Returns the LetCont that now binds [continuation]. | 208 /// Returns the LetCont that now binds [continuation]. |
| 199 LetCont _makeUniqueBinding(Continuation continuation) { | 209 LetCont _makeUniqueBinding(Continuation continuation) { |
| 200 LetCont letCont = continuation.parent; | 210 LetCont letCont = continuation.parent; |
| 201 if (letCont.continuations.length == 1) return letCont; | 211 if (letCont.continuations.length == 1) return letCont; |
| 202 letCont.continuations.remove(continuation); | 212 letCont.continuations.remove(continuation); |
| 203 LetCont newBinding = new LetCont(continuation, letCont.body); | 213 LetCont newBinding = new LetCont(continuation, letCont.body); |
| 214 newBinding.body.parent = newBinding; |
| 215 newBinding.parent = letCont; |
| 216 letCont.body = newBinding; |
| 204 continuation.parent = newBinding; | 217 continuation.parent = newBinding; |
| 205 newBinding.insertBelow(letCont); | |
| 206 return newBinding; | 218 return newBinding; |
| 207 } | 219 } |
| OLD | NEW |