| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 workSet.add(thatCont); | 131 workSet.add(thatCont); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Replace individual parameters: | 136 // Replace individual parameters: |
| 137 // * In the continuation body, replace occurrence of param with value, | 137 // * In the continuation body, replace occurrence of param with value, |
| 138 // * and implicitly remove param from continuation signature and | 138 // * and implicitly remove param from continuation signature and |
| 139 // invocations by not incrementing `dst`. References of removed | 139 // invocations by not incrementing `dst`. References of removed |
| 140 // arguments are unlinked to keep definition usages up to date. | 140 // arguments are unlinked to keep definition usages up to date. |
| 141 uniqueDefinition.substituteFor(oldDefinition); | 141 oldDefinition.replaceUsesWith(uniqueDefinition); |
| 142 for (InvokeContinuation invoke in invokes) { | 142 for (InvokeContinuation invoke in invokes) { |
| 143 invoke.arguments[src].unlink(); | 143 invoke.arguments[src].unlink(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Finally, if the substituted definition is not in scope of the affected | 146 // Finally, if the substituted definition is not in scope of the affected |
| 147 // continuation, move the continuation binding. This is safe to do since | 147 // continuation, move the continuation binding. This is safe to do since |
| 148 // the continuation is referenced only as the target in continuation | 148 // the continuation is referenced only as the target in continuation |
| 149 // invokes, and all such invokes must be within the scope of | 149 // invokes, and all such invokes must be within the scope of |
| 150 // [uniqueDefinition]. Note that this is linear in the depth of | 150 // [uniqueDefinition]. Note that this is linear in the depth of |
| 151 // the binding of [uniqueDefinition]. | 151 // the binding of [uniqueDefinition]. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 void _moveIntoScopeOf(LetCont letCont, Definition definition) { | 184 void _moveIntoScopeOf(LetCont letCont, Definition definition) { |
| 185 if (_isInScopeOf(letCont, definition)) return; | 185 if (_isInScopeOf(letCont, definition)) return; |
| 186 | 186 |
| 187 InteriorNode binding = definition.parent; | 187 InteriorNode binding = definition.parent; |
| 188 letCont.remove(); | 188 letCont.remove(); |
| 189 letCont.insertBelow(binding); | 189 letCont.insertBelow(binding); |
| 190 } | 190 } |
| 191 | 191 |
| 192 /// Ensures [continuation] has its own LetCont binding by creating | 192 /// Ensures [continuation] has its own LetCont binding by creating |
| 193 /// a new LetCont below its current binding, if necessary. | 193 /// a new LetCont below its current binding, if necessary. |
| 194 /// | 194 /// |
| 195 /// Returns the LetCont that now binds [continuation]. | 195 /// Returns the LetCont that now binds [continuation]. |
| 196 LetCont _makeUniqueBinding(Continuation continuation) { | 196 LetCont _makeUniqueBinding(Continuation continuation) { |
| 197 LetCont letCont = continuation.parent; | 197 LetCont letCont = continuation.parent; |
| 198 if (letCont.continuations.length == 1) return letCont; | 198 if (letCont.continuations.length == 1) return letCont; |
| 199 letCont.continuations.remove(continuation); | 199 letCont.continuations.remove(continuation); |
| 200 LetCont newBinding = new LetCont(continuation, null); | 200 LetCont newBinding = new LetCont(continuation, null); |
| 201 continuation.parent = newBinding; | 201 continuation.parent = newBinding; |
| 202 newBinding.insertBelow(letCont); | 202 newBinding.insertBelow(letCont); |
| 203 return newBinding; | 203 return newBinding; |
| 204 } | 204 } |
| OLD | NEW |