| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); | 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA code generator'; | 7 String get name() => 'SSA code generator'; |
| 8 | 8 |
| 9 | 9 |
| 10 String generateMethod(WorkItem work, HGraph graph) { | 10 String generateMethod(WorkItem work, HGraph graph) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 generateAtUseSite = new Set<HInstruction>(), | 148 generateAtUseSite = new Set<HInstruction>(), |
| 149 logicalOperations = new Map<HPhi, String>(), | 149 logicalOperations = new Map<HPhi, String>(), |
| 150 breakAction = new Map<Element, ElementAction>(), | 150 breakAction = new Map<Element, ElementAction>(), |
| 151 continueAction = new Map<Element, ElementAction>(), | 151 continueAction = new Map<Element, ElementAction>(), |
| 152 phiEquivalence = new Equivalence<HPhi>() { | 152 phiEquivalence = new Equivalence<HPhi>() { |
| 153 | 153 |
| 154 for (final name in parameterNames.getValues()) { | 154 for (final name in parameterNames.getValues()) { |
| 155 prefixes[name] = 0; | 155 prefixes[name] = 0; |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Create a namespace for temporaries. |
| 159 prefixes['t'] = 0; |
| 160 |
| 158 equalsNullElement = | 161 equalsNullElement = |
| 159 compiler.builder.interceptors.getEqualsNullInterceptor(); | 162 compiler.builder.interceptors.getEqualsNullInterceptor(); |
| 160 } | 163 } |
| 161 | 164 |
| 162 abstract visitTypeGuard(HTypeGuard node); | 165 abstract visitTypeGuard(HTypeGuard node); |
| 163 | 166 |
| 164 abstract beginGraph(HGraph graph); | 167 abstract beginGraph(HGraph graph); |
| 165 abstract endGraph(HGraph graph); | 168 abstract endGraph(HGraph graph); |
| 166 | 169 |
| 167 abstract beginLoop(HBasicBlock block); | 170 abstract beginLoop(HBasicBlock block); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 270 |
| 268 void visitConditionGraph(SubGraph conditionSubGraph) { | 271 void visitConditionGraph(SubGraph conditionSubGraph) { |
| 269 visitExpressionGraph(conditionSubGraph); | 272 visitExpressionGraph(conditionSubGraph); |
| 270 } | 273 } |
| 271 | 274 |
| 272 String temporary(HInstruction instruction) { | 275 String temporary(HInstruction instruction) { |
| 273 int id = instruction.id; | 276 int id = instruction.id; |
| 274 String name = names[id]; | 277 String name = names[id]; |
| 275 if (name !== null) return name; | 278 if (name !== null) return name; |
| 276 | 279 |
| 277 String prefix; | 280 String prefix = 't'; |
| 278 if (instruction.sourceElement !== null) { | 281 if (instruction.sourceElement !== null) { |
| 279 Element element = instruction.sourceElement; | 282 Element element = instruction.sourceElement; |
| 280 if (element !== null && !element.name.isEmpty()) { | 283 if (element !== null && !element.name.isEmpty()) { |
| 281 prefix = element.name.slowToString(); | 284 prefix = element.name.slowToString(); |
| 282 } else { | 285 // If we've never seen that prefix before, try to use it |
| 283 prefix = 'v'; | 286 // directly. |
| 287 if (!prefixes.containsKey(prefix)) { |
| 288 // Make sure the variable name does not conflict with our mangling. |
| 289 while (usedNames.contains(prefix)) { |
| 290 prefix = '${prefix}_'; |
| 291 } |
| 292 prefixes[prefix] = 0; |
| 293 return newName(id, prefix); |
| 294 } |
| 284 } | 295 } |
| 285 } else { | |
| 286 prefix = 't'; | |
| 287 } | |
| 288 | |
| 289 while (usedNames.contains(prefix)) { | |
| 290 prefix = '${prefix}_'; | |
| 291 } | 296 } |
| 292 | 297 |
| 293 if (!prefixes.containsKey(prefix)) { | 298 name = '${prefix}${prefixes[prefix]++}'; |
| 294 prefixes[prefix] = 0; | 299 while (usedNames.contains(name)) { |
| 295 return newName(id, prefix); | |
| 296 } else { | |
| 297 name = '${prefix}${prefixes[prefix]++}'; | 300 name = '${prefix}${prefixes[prefix]++}'; |
| 298 while (usedNames.contains(name)) { | |
| 299 name = '${prefix}${prefixes[prefix]++}'; | |
| 300 } | |
| 301 return newName(id, name); | |
| 302 } | 301 } |
| 302 return newName(id, name); |
| 303 } | 303 } |
| 304 | 304 |
| 305 bool temporaryExists(HInstruction instruction) { | 305 bool temporaryExists(HInstruction instruction) { |
| 306 return names.containsKey(instruction.id); | 306 return names.containsKey(instruction.id); |
| 307 } | 307 } |
| 308 | 308 |
| 309 String newName(int id, String name) { | 309 String newName(int id, String name) { |
| 310 String result = JsNames.getValid(name); | 310 String result = JsNames.getValid(name); |
| 311 names[id] = result; | 311 names[id] = result; |
| 312 usedNames.add(result); | 312 usedNames.add(result); |
| (...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 startBailoutSwitch(); | 1928 startBailoutSwitch(); |
| 1929 } | 1929 } |
| 1930 } | 1930 } |
| 1931 | 1931 |
| 1932 void endElse(HIf node) { | 1932 void endElse(HIf node) { |
| 1933 if (node.elseBlock.hasGuards()) { | 1933 if (node.elseBlock.hasGuards()) { |
| 1934 endBailoutSwitch(); | 1934 endBailoutSwitch(); |
| 1935 } | 1935 } |
| 1936 } | 1936 } |
| 1937 } | 1937 } |
| OLD | NEW |