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 final JavaScriptBackend backend; | 6 final JavaScriptBackend backend; |
| 7 SsaCodeGeneratorTask(JavaScriptBackend backend) | 7 SsaCodeGeneratorTask(JavaScriptBackend backend) |
| 8 : this.backend = backend, | 8 : this.backend = backend, |
| 9 super(backend.compiler); | 9 super(backend.compiler); |
| 10 String get name() => 'SSA code generator'; | 10 String get name() => 'SSA code generator'; |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 542 } |
| 543 } else { | 543 } else { |
| 544 generateStatements(info.condition); | 544 generateStatements(info.condition); |
| 545 addIndented("if ("); | 545 addIndented("if ("); |
| 546 use(condition, JSPrecedence.EXPRESSION_PRECEDENCE); | 546 use(condition, JSPrecedence.EXPRESSION_PRECEDENCE); |
| 547 buffer.add(") {\n"); | 547 buffer.add(") {\n"); |
| 548 indent++; | 548 indent++; |
| 549 generateStatements(info.thenGraph); | 549 generateStatements(info.thenGraph); |
| 550 indent--; | 550 indent--; |
| 551 addIndented("}"); | 551 addIndented("}"); |
| 552 if (info.elseGraph !== null) { | 552 HSubGraphBlockInformation elseGraph = info.elseGraph; |
| 553 HIf ifInstruction = info.thenGraph.start.predecessors[0].last; | |
|
Lasse Reichstein Nielsen
2012/05/31 11:57:28
Or:
HIf ifInstruction = info.condition.conditionE
ngeoffray
2012/05/31 12:27:38
Done.
| |
| 554 if (elseGraph !== null | |
| 555 && hasCodeUntil(elseGraph.start, ifInstruction.joinBlock)) { | |
|
Lasse Reichstein Nielsen
2012/05/31 11:57:28
I really, really don't like using the ifInstructio
ngeoffray
2012/05/31 12:27:38
Done.
| |
| 553 buffer.add(" else {\n"); | 556 buffer.add(" else {\n"); |
| 554 indent++; | 557 indent++; |
| 555 generateStatements(info.elseGraph); | 558 generateStatements(info.elseGraph); |
|
kasperl
2012/05/31 11:26:34
info.elseGraph -> elseGraph
ngeoffray
2012/05/31 11:51:29
Done.
| |
| 556 indent--; | 559 indent--; |
| 557 addIndented("}"); | 560 addIndented("}"); |
| 558 } | 561 } |
| 559 buffer.add("\n"); | 562 buffer.add("\n"); |
| 560 } | 563 } |
| 561 return true; | 564 return true; |
| 562 } | 565 } |
| 563 | 566 |
| 564 bool visitSequenceInfo(HStatementSequenceInformation info) { | 567 bool visitSequenceInfo(HStatementSequenceInformation info) { |
| 565 return false; | 568 return false; |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1244 } | 1247 } |
| 1245 } | 1248 } |
| 1246 | 1249 |
| 1247 visitTry(HTry node) { | 1250 visitTry(HTry node) { |
| 1248 // We should never get here. Try/catch/finally is always handled using block | 1251 // We should never get here. Try/catch/finally is always handled using block |
| 1249 // information in [visitTryInfo], or not at all, in the case of the bailout | 1252 // information in [visitTryInfo], or not at all, in the case of the bailout |
| 1250 // generator. | 1253 // generator. |
| 1251 compiler.internalError('visitTry should not be called', instruction: node); | 1254 compiler.internalError('visitTry should not be called', instruction: node); |
| 1252 } | 1255 } |
| 1253 | 1256 |
| 1257 bool hasCodeUntil(HBasicBlock block, HBasicBlock successor) { | |
|
kasperl
2012/05/31 11:26:34
Not sure I like the name. Maybe negate it and make
ngeoffray
2012/05/31 11:51:29
Done.
| |
| 1258 if (block.last is !HGoto) return true; | |
|
kasperl
2012/05/31 11:26:34
If the last instruction is a goto can the block ha
ngeoffray
2012/05/31 11:51:29
Good point! Check removed.
Lasse Reichstein Nielsen
2012/05/31 11:57:28
Sadly, HBreak and HContinue are subclasses of HGot
ngeoffray
2012/05/31 12:27:38
+1
| |
| 1259 if (block.successors.length != 1) return true; | |
| 1260 if (block.successors[0] !== successor) return true; | |
| 1261 HInstruction instruction = block.first; | |
|
kasperl
2012/05/31 11:26:34
Add a comment saying that we generate at use site
ngeoffray
2012/05/31 11:51:29
Done.
| |
| 1262 while (instruction != block.last) { | |
|
Lasse Reichstein Nielsen
2012/05/31 11:57:28
for-loop?
ngeoffray
2012/05/31 12:27:38
Done.
| |
| 1263 if (!isGenerateAtUseSite(instruction)) return true; | |
| 1264 instruction = instruction.next; | |
| 1265 } | |
| 1266 CopyHandler handler = variableNames.getCopyHandler(block); | |
| 1267 if (handler == null || handler.isEmpty()) return false; | |
| 1268 if (!handler.assignments.isEmpty()) return true; | |
| 1269 for (Copy copy in handler.copies) { | |
|
kasperl
2012/05/31 11:26:34
Add a comment that briefly explains what this loop
ngeoffray
2012/05/31 11:51:29
Done.
| |
| 1270 String sourceName = variableNames.getName(copy.source); | |
| 1271 String destinationName = variableNames.getName(copy.destination); | |
| 1272 if (sourceName != destinationName) return true; | |
|
Lasse Reichstein Nielsen
2012/05/31 11:57:28
Would it make sense to remove these "identity-copi
ngeoffray
2012/05/31 12:27:38
At the time where we create the copies of HInstruc
| |
| 1273 } | |
| 1274 return false; | |
| 1275 } | |
| 1276 | |
| 1254 visitIf(HIf node) { | 1277 visitIf(HIf node) { |
| 1255 if (subGraph !== null && node.block === subGraph.end) { | 1278 if (subGraph !== null && node.block === subGraph.end) { |
| 1256 if (isGeneratingExpression()) { | 1279 if (isGeneratingExpression()) { |
| 1257 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); | 1280 use(node.inputs[0], JSPrecedence.EXPRESSION_PRECEDENCE); |
| 1258 } | 1281 } |
| 1259 return; | 1282 return; |
| 1260 } | 1283 } |
| 1261 HInstruction condition = node.inputs[0]; | 1284 HInstruction condition = node.inputs[0]; |
| 1262 int preVisitedBlocks = 0; | 1285 int preVisitedBlocks = 0; |
| 1263 List<HBasicBlock> dominated = node.block.dominatedBlocks; | 1286 List<HBasicBlock> dominated = node.block.dominatedBlocks; |
| 1264 HIfBlockInformation info = node.blockInformation.body; | 1287 HIfBlockInformation info = node.blockInformation.body; |
| 1265 if (condition.isConstant()) { | 1288 if (condition.isConstant()) { |
| 1266 HConstant constant = condition; | 1289 HConstant constant = condition; |
| 1267 if (constant.constant.isTrue()) { | 1290 if (constant.constant.isTrue()) { |
| 1268 generateStatements(info.thenGraph); | 1291 generateStatements(info.thenGraph); |
| 1269 } else if (node.hasElse) { | 1292 } else if (node.hasElse) { |
| 1270 generateStatements(info.elseGraph); | 1293 generateStatements(info.elseGraph); |
| 1271 } | 1294 } |
| 1272 // We ignore the other branch, even if it isn't visited. | 1295 // We ignore the other branch, even if it isn't visited. |
| 1273 preVisitedBlocks = node.hasElse ? 2 : 1; | 1296 preVisitedBlocks = node.hasElse ? 2 : 1; |
| 1274 } else { | 1297 } else { |
| 1275 startIf(node); | 1298 startIf(node); |
| 1276 assert(!isGenerateAtUseSite(node)); | 1299 assert(!isGenerateAtUseSite(node)); |
| 1277 startThen(node); | 1300 startThen(node); |
| 1278 assert(node.thenBlock === dominated[0]); | 1301 assert(node.thenBlock === dominated[0]); |
| 1279 generateStatements(info.thenGraph); | 1302 generateStatements(info.thenGraph); |
| 1280 preVisitedBlocks++; | 1303 preVisitedBlocks++; |
| 1281 endThen(node); | 1304 endThen(node); |
| 1282 if (node.hasElse) { | 1305 if (node.hasElse && hasCodeUntil(node.elseBlock, node.joinBlock)) { |
| 1283 startElse(node); | 1306 startElse(node); |
| 1284 assert(node.elseBlock === dominated[1]); | 1307 assert(node.elseBlock === dominated[1]); |
| 1285 generateStatements(info.elseGraph); | 1308 generateStatements(info.elseGraph); |
| 1286 preVisitedBlocks++; | 1309 preVisitedBlocks++; |
| 1287 endElse(node); | 1310 endElse(node); |
| 1288 } | 1311 } |
| 1289 endIf(node); | 1312 endIf(node); |
| 1290 } | 1313 } |
| 1291 HBasicBlock joinBlock = node.joinBlock; | 1314 HBasicBlock joinBlock = node.joinBlock; |
| 1292 if (joinBlock !== null && joinBlock.dominator !== node.block) { | 1315 if (joinBlock !== null && joinBlock.dominator !== node.block) { |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2469 startBailoutSwitch(); | 2492 startBailoutSwitch(); |
| 2470 } | 2493 } |
| 2471 } | 2494 } |
| 2472 | 2495 |
| 2473 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { | 2496 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { |
| 2474 if (labeledBlockInfo.body.start.hasGuards()) { | 2497 if (labeledBlockInfo.body.start.hasGuards()) { |
| 2475 endBailoutSwitch(); | 2498 endBailoutSwitch(); |
| 2476 } | 2499 } |
| 2477 } | 2500 } |
| 2478 } | 2501 } |
| OLD | NEW |