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 dart2js.cps_ir.mutable_ssa; | 5 library dart2js.cps_ir.mutable_ssa; |
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 /// Determines which mutable variables should be rewritten to phi assignments | 10 /// Determines which mutable variables should be rewritten to phi assignments |
(...skipping 19 matching lines...) Expand all Loading... |
30 ++currentDepth; | 30 ++currentDepth; |
31 visit(node.body); | 31 visit(node.body); |
32 --currentDepth; | 32 --currentDepth; |
33 visit(node.handler); | 33 visit(node.handler); |
34 } | 34 } |
35 | 35 |
36 void processLetMutable(LetMutable node) { | 36 void processLetMutable(LetMutable node) { |
37 variableDepth[node.variable] = currentDepth; | 37 variableDepth[node.variable] = currentDepth; |
38 } | 38 } |
39 | 39 |
40 void processSetMutableVariable(SetMutableVariable node) { | 40 void processSetMutable(SetMutable node) { |
41 MutableVariable variable = node.variable.definition; | 41 MutableVariable variable = node.variable.definition; |
42 if (currentDepth > variableDepth[variable]) { | 42 if (currentDepth > variableDepth[variable]) { |
43 hasAssignmentInTry.add(variable); | 43 hasAssignmentInTry.add(variable); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 /// True if there are no mutable variables or they are all assigned inside | 47 /// True if there are no mutable variables or they are all assigned inside |
48 /// a try block. In this case, there is nothing to do and the pass should | 48 /// a try block. In this case, there is nothing to do and the pass should |
49 /// be skipped. | 49 /// be skipped. |
50 bool get allMutablesAreAssignedInTryBlocks { | 50 bool get allMutablesAreAssignedInTryBlocks { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Put the initial value into the environment. | 148 // Put the initial value into the environment. |
149 Primitive value = node.value.definition; | 149 Primitive value = node.value.definition; |
150 environment[node.variable] = value; | 150 environment[node.variable] = value; |
151 | 151 |
152 // Preserve variable names. | 152 // Preserve variable names. |
153 mergeHints(node.variable, value); | 153 mergeHints(node.variable, value); |
154 | 154 |
155 // Remove the mutable variable binding. | 155 // Remove the mutable variable binding. |
156 node.value.unlink(); | 156 node.value.unlink(); |
157 removeNode(node); | 157 removeNode(node); |
158 } else if (node is SetMutableVariable && | 158 } else if (node is LetPrim && node.primitive is SetMutable) { |
159 shouldRewrite(node.variable.definition)) { | 159 SetMutable setter = node.primitive; |
160 // As above, update the environment, preserve variables and remove | 160 MutableVariable variable = setter.variable.definition; |
161 // the mutable variable assignment. | 161 if (shouldRewrite(variable)) { |
162 MutableVariable variable = node.variable.definition; | 162 // As above, update the environment, preserve variables and remove |
163 environment[variable] = node.value.definition; | 163 // the mutable variable assignment. |
164 mergeHints(variable, node.value.definition); | 164 environment[variable] = setter.value.definition; |
165 node.value.unlink(); | 165 mergeHints(variable, setter.value.definition); |
166 removeNode(node); | 166 setter.value.unlink(); |
167 } else if (node is LetPrim && node.primitive is GetMutableVariable) { | 167 removeNode(node); |
168 GetMutableVariable getter = node.primitive; | 168 } |
| 169 } else if (node is LetPrim && node.primitive is GetMutable) { |
| 170 GetMutable getter = node.primitive; |
169 MutableVariable variable = getter.variable.definition; | 171 MutableVariable variable = getter.variable.definition; |
170 if (shouldRewrite(variable)) { | 172 if (shouldRewrite(variable)) { |
171 // Replace with the reaching definition from the environment. | 173 // Replace with the reaching definition from the environment. |
172 Primitive value = environment[variable]; | 174 Primitive value = environment[variable]; |
173 value.substituteFor(getter); | 175 value.substituteFor(getter); |
174 mergeHints(variable, value); | 176 mergeHints(variable, value); |
175 removeNode(node); | 177 removeNode(node); |
176 } | 178 } |
177 } else if (node is LetCont) { | 179 } else if (node is LetCont) { |
178 // Create phi parameters for each join continuation bound here, and put | 180 // Create phi parameters for each join continuation bound here, and put |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 class VariableItem extends StackItem {} | 245 class VariableItem extends StackItem {} |
244 | 246 |
245 /// Represents a yet unprocessed continuation together with the | 247 /// Represents a yet unprocessed continuation together with the |
246 /// environment in which to process it. | 248 /// environment in which to process it. |
247 class ContinuationItem extends StackItem { | 249 class ContinuationItem extends StackItem { |
248 final Continuation continuation; | 250 final Continuation continuation; |
249 final Map<MutableVariable, Primitive> environment; | 251 final Map<MutableVariable, Primitive> environment; |
250 | 252 |
251 ContinuationItem(this.continuation, this.environment); | 253 ContinuationItem(this.continuation, this.environment); |
252 } | 254 } |
OLD | NEW |