Index: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart |
=================================================================== |
--- sdk/lib/_internal/compiler/implementation/ssa/codegen.dart (revision 14614) |
+++ sdk/lib/_internal/compiler/implementation/ssa/codegen.dart (working copy) |
@@ -1029,6 +1029,8 @@ |
} |
break; |
case HLoopBlockInformation.DO_WHILE_LOOP: |
+ CopyHandler handler = variableNames.getCopyHandler(info.end); |
floitsch
2012/11/07 09:59:04
Add comment explaining why this is necessary.
ngeoffray
2012/11/07 10:04:49
Done.
|
+ if (handler != null && !handler.isEmpty) return false; |
// Generate do-while loop in all cases. |
floitsch
2012/11/07 09:59:04
Remove comment or:
Generate do-while loop in all o
ngeoffray
2012/11/07 10:04:49
Comment removed.
|
if (info.initializer != null) { |
generateStatements(info.initializer); |
@@ -1326,7 +1328,16 @@ |
} |
instruction = instruction.next; |
} |
- assignPhisOfSuccessors(node); |
+ if (instruction is HLoopBranch) { |
+ HLoopBranch branch = instruction; |
+ // If the loop is a do/while loop, the phi updates must happen |
+ // after the evaluation of the condition. |
+ if (!branch.isDoWhile()) { |
+ assignPhisOfSuccessors(node); |
+ } |
+ } else { |
+ assignPhisOfSuccessors(node); |
+ } |
visit(instruction); |
} |
@@ -1921,6 +1932,10 @@ |
// For a do while loop, the body has already been visited. |
if (!node.isDoWhile()) { |
floitsch
2012/11/07 09:59:04
Invert the test, so that we don't have the "!".
ngeoffray
2012/11/07 10:04:49
Done.
|
visitBasicBlock(dominated[0]); |
+ } else { |
+ // Now that the condition has been evaluated, we can update the |
+ // phis of a do/while loop. |
+ assignPhisOfSuccessors(node.block); |
} |
endLoop(node.block); |
@@ -2781,7 +2796,8 @@ |
body = unwrapStatement(body); |
js.While loop = new js.While(newLiteralBool(true), body); |
- HLoopInformation info = block.loopInformation; |
+ HBasicBlock header = block.isLoopHeader() ? block : block.parentLoopHeader; |
+ HLoopInformation info = header.loopInformation; |
attachLocationRange(loop, |
info.loopBlockInformation.sourcePosition, |
info.loopBlockInformation.endSourcePosition); |
@@ -2790,7 +2806,9 @@ |
void handleLoopCondition(HLoopBranch node) { |
use(node.inputs[0]); |
- pushStatement(new js.If.noElse(pop(), new js.Break(null)), node); |
+ js.Expression test = new js.Prefix('!', pop()); |
+ js.Statement then = new js.Break(null); |
+ pushStatement(new js.If.noElse(test, then), node); |
} |