Chromium Code Reviews| 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 String generate(WorkItem work, HGraph graph) { | 9 String generate(WorkItem work, HGraph graph) { |
| 10 return measure(() { | 10 return measure(() { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 final Map<Element, String> parameterNames; | 94 final Map<Element, String> parameterNames; |
| 95 final Map<int, String> names; | 95 final Map<int, String> names; |
| 96 final Map<String, int> prefixes; | 96 final Map<String, int> prefixes; |
| 97 | 97 |
| 98 Element equalsNullElement; | 98 Element equalsNullElement; |
| 99 int indent = 0; | 99 int indent = 0; |
| 100 int expectedPrecedence = JSPrecedence.STATEMENT_PRECEDENCE; | 100 int expectedPrecedence = JSPrecedence.STATEMENT_PRECEDENCE; |
| 101 HGraph currentGraph; | 101 HGraph currentGraph; |
| 102 HBasicBlock currentBlock; | 102 HBasicBlock currentBlock; |
| 103 | 103 |
| 104 // Records a block-information that is being handled specially. | |
| 105 // Used to break bad recursion. | |
| 106 HLabeledBlockInformation currentBlockInformation; | |
| 107 // Restriction on the block traversal. | |
|
floitsch
2012/03/06 10:12:13
That comment doesn't work for me. Maybe (if that's
Lasse Reichstein Nielsen
2012/03/06 10:20:44
Reworded.
| |
| 104 SubGraph subGraph; | 108 SubGraph subGraph; |
| 105 | 109 |
| 106 SsaCodeGenerator(this.compiler, | 110 SsaCodeGenerator(this.compiler, |
| 107 this.work, | 111 this.work, |
| 108 this.buffer, | 112 this.buffer, |
| 109 this.parameters, | 113 this.parameters, |
| 110 this.parameterNames) | 114 this.parameterNames) |
| 111 : names = new Map<int, String>(), | 115 : names = new Map<int, String>(), |
| 112 prefixes = new Map<String, int>() { | 116 prefixes = new Map<String, int>() { |
| 113 for (final name in parameterNames.getValues()) { | 117 for (final name in parameterNames.getValues()) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 } | 230 } |
| 227 } | 231 } |
| 228 | 232 |
| 229 visit(HInstruction node, int expectedPrecedence) { | 233 visit(HInstruction node, int expectedPrecedence) { |
| 230 int oldPrecedence = this.expectedPrecedence; | 234 int oldPrecedence = this.expectedPrecedence; |
| 231 this.expectedPrecedence = expectedPrecedence; | 235 this.expectedPrecedence = expectedPrecedence; |
| 232 node.accept(this); | 236 node.accept(this); |
| 233 this.expectedPrecedence = oldPrecedence; | 237 this.expectedPrecedence = oldPrecedence; |
| 234 } | 238 } |
| 235 | 239 |
| 236 void handleLabeledBlock(HBasicBlock node) { | 240 void handleLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 237 HLabeledBlockInformation labeledBlockInfo = node.labeledBlockInformation; | 241 addIndentation(); |
| 238 if (labeledBlockInfo.start === node) { | 242 for (SourceString label in labeledBlockInfo.labels) { |
| 239 addIndentation(); | 243 addLabel(label); |
| 240 for (SourceString label in labeledBlockInfo.labels) { | 244 buffer.add(":"); |
| 241 addLabel(label); | |
| 242 buffer.add(":"); | |
| 243 } | |
| 244 buffer.add("{\n"); | |
| 245 indent++; | |
| 246 } else { | |
| 247 assert(labeledBlockInfo.end === node); | |
| 248 assert((){ | |
| 249 // Check that this block is (transitively) dominated by the start block. | |
| 250 HBasicBlock block = node; | |
| 251 while (block.dominator !== null) { | |
| 252 block = block.dominator; | |
| 253 if (block === labeledBlockInfo.start) return true; | |
| 254 } | |
| 255 return false; | |
| 256 }); | |
| 257 indent--; | |
| 258 addIndentation(); | |
| 259 buffer.add("}\n"); | |
| 260 } | 245 } |
| 246 buffer.add("{\n"); | |
| 247 indent++; | |
| 248 | |
| 249 visitSubGraph(labeledBlockInfo.body); | |
| 250 | |
| 251 indent--; | |
| 252 addIndentation(); | |
| 253 buffer.add("}\n"); | |
| 254 | |
| 255 visitBasicBlock(labeledBlockInfo.joinBlock); | |
| 261 } | 256 } |
| 262 | 257 |
| 263 | 258 |
| 264 visitBasicBlock(HBasicBlock node) { | 259 visitBasicBlock(HBasicBlock node) { |
| 260 // Abort traversal if we are leaving the currently active sub-graph. | |
| 265 if (!subGraph.contains(node)) return; | 261 if (!subGraph.contains(node)) return; |
| 266 | 262 |
| 263 // If this node has special behavior attached, handle it. | |
| 264 // If we reach here again while handling the attached information, | |
| 265 // e.g., because we call visitSubGraph on a subgraph starting here, | |
| 266 // don't handle it again. | |
| 267 if (node.hasLabeledBlockInformation() && | |
| 268 node.labeledBlockInformation !== currentBlockInformation) { | |
| 269 HLabeledBlockInformation oldBlockInformation = currentBlockInformation; | |
| 270 currentBlockInformation = node.labeledBlockInformation; | |
| 271 handleLabeledBlock(currentBlockInformation); | |
| 272 currentBlockInformation = oldBlockInformation; | |
| 273 return; | |
| 274 } | |
| 275 | |
| 267 currentBlock = node; | 276 currentBlock = node; |
| 268 | 277 if (node.isLoopHeader()) { |
| 269 if (node.hasLabeledBlockInformation()) { | |
| 270 handleLabeledBlock(node); | |
| 271 } else if (currentBlock.isLoopHeader()) { | |
| 272 // While loop will be closed by the conditional loop-branch. | 278 // While loop will be closed by the conditional loop-branch. |
| 273 // TODO(floitsch): HACK HACK HACK. | 279 // TODO(floitsch): HACK HACK HACK. |
| 274 beginLoop(node); | 280 beginLoop(node); |
| 275 } | 281 } |
| 276 | |
| 277 HInstruction instruction = node.first; | 282 HInstruction instruction = node.first; |
| 278 while (instruction != null) { | 283 while (instruction != null) { |
| 279 if (instruction is HGoto || instruction is HExit || instruction is HTry) { | 284 if (instruction is HGoto || instruction is HExit || instruction is HTry) { |
| 280 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); | 285 visit(instruction, JSPrecedence.STATEMENT_PRECEDENCE); |
| 281 return; | 286 return; |
| 282 } else if (!instruction.generateAtUseSite()) { | 287 } else if (!instruction.generateAtUseSite()) { |
| 283 if (instruction is !HIf && instruction is !HBailoutTarget) { | 288 if (instruction is !HIf && instruction is !HBailoutTarget) { |
| 284 addIndentation(); | 289 addIndentation(); |
| 285 } | 290 } |
| 286 if (instruction.usedBy.isEmpty() || instruction is HLocal) { | 291 if (instruction.usedBy.isEmpty() || instruction is HLocal) { |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1395 startBailoutSwitch(); | 1400 startBailoutSwitch(); |
| 1396 } | 1401 } |
| 1397 } | 1402 } |
| 1398 | 1403 |
| 1399 void endElse(HIf node) { | 1404 void endElse(HIf node) { |
| 1400 if (node.elseBlock.hasBailouts()) { | 1405 if (node.elseBlock.hasBailouts()) { |
| 1401 endBailoutSwitch(); | 1406 endBailoutSwitch(); |
| 1402 } | 1407 } |
| 1403 } | 1408 } |
| 1404 } | 1409 } |
| OLD | NEW |