Chromium Code Reviews| Index: lib/compiler/implementation/ssa/builder.dart |
| diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart |
| index 965c0b5f95bdccb4253dcfc7f876687f1262fb6e..e6f5c9eef7c17928887f6a93b643b19eb33f2429 100644 |
| --- a/lib/compiler/implementation/ssa/builder.dart |
| +++ b/lib/compiler/implementation/ssa/builder.dart |
| @@ -1140,7 +1140,6 @@ class SsaBuilder implements Visitor { |
| JumpHandler jumpHandler = createJumpHandler(node); |
| HBasicBlock loopEntry = graph.addNewLoopHeaderBlock( |
| - HLoopInformation.loopType(node), |
| jumpHandler.target, |
| jumpHandler.labels()); |
| previousBlock.addSuccessor(loopEntry); |
| @@ -1178,6 +1177,16 @@ class SsaBuilder implements Visitor { |
| } |
| } |
| + HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) { |
| + if (statements === null) return null; |
| + return new HSubGraphBlockInformation(statements); |
| + } |
| + |
| + HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) { |
| + if (expression === null) return null; |
| + return new HSubExpressionBlockInformation(expression); |
| + } |
| + |
| // For while loops, initializer and update are null. |
| // The condition function must return a boolean result. |
| // None of the functions must leave anything on the stack. |
| @@ -1198,26 +1207,27 @@ class SsaBuilder implements Visitor { |
| localsHandler.startLoop(loop); |
| // The initializer. |
| - HBasicBlock initializerBlock = openNewBlock(); |
| - initialize(); |
| - assert(!isAborted()); |
| - SubExpression initializerGraph = |
| - new SubExpression(initializerBlock, current); |
| + SubExpression initializerGraph = null; |
| + HBasicBlock startBlock; |
| + if (initialize !== null) { |
| + HBasicBlock initializerBlock = openNewBlock(); |
| + startBlock = initializerBlock; |
| + initialize(); |
| + assert(!isAborted()); |
| + initializerGraph = |
| + new SubExpression(initializerBlock, current); |
| + } |
| JumpHandler jumpHandler = beginLoopHeader(loop); |
| + HLoopInformation loopInfo = current.loopInformation; |
| HBasicBlock conditionBlock = current; |
| - HLoopInformation loopInfo = current.blockInformation; |
| - // The initializer graph is currently unused due to the way we |
| - // generate code. |
| - loopInfo.initializer = new HSubExpressionBlockInformation(initializerGraph); |
| + if (startBlock === null) startBlock = conditionBlock; |
| HInstruction conditionInstruction = condition(); |
| HBasicBlock conditionExitBlock = |
| close(new HLoopBranch(conditionInstruction)); |
| SubExpression conditionExpression = |
| new SubExpression(conditionBlock, conditionExitBlock); |
| - loopInfo.condition = |
| - new HSubExpressionBlockInformation(conditionExpression); |
| LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); |
| @@ -1231,7 +1241,6 @@ class SsaBuilder implements Visitor { |
| SubGraph bodyGraph = new SubGraph(beginBodyBlock, current); |
| HBasicBlock bodyBlock = close(new HGoto()); |
| - loopInfo.body = new HSubGraphBlockInformation(bodyGraph); |
| // Update. |
| // We create an update block, even when we are in a while loop. There the |
| @@ -1255,17 +1264,19 @@ class SsaBuilder implements Visitor { |
| List<LabelElement> labels = jumpHandler.labels(); |
| TargetElement target = elements[loop]; |
| if (!labels.isEmpty()) { |
| - beginBodyBlock.blockInformation = new HLabeledBlockInformation( |
| - new HSubGraphBlockInformation(bodyGraph), |
| - updateBlock, |
| - jumpHandler.labels(), |
| - isContinue: true); |
| + beginBodyBlock.setBlockInfo( |
| + new HLabeledBlockInformation( |
| + new HSubGraphBlockInformation(bodyGraph), |
| + jumpHandler.labels(), |
| + isContinue: true), |
| + updateBlock); |
| } else if (target !== null && target.isContinueTarget) { |
| - beginBodyBlock.blockInformation = new HLabeledBlockInformation.implicit( |
| - new HSubGraphBlockInformation(bodyGraph), |
| - updateBlock, |
| - target, |
| - isContinue: true); |
| + beginBodyBlock.setBlockInfo( |
| + new HLabeledBlockInformation.implicit( |
| + new HSubGraphBlockInformation(bodyGraph), |
| + target, |
| + isContinue: true), |
| + updateBlock); |
| } |
| localsHandler.enterLoopUpdates(loop); |
| @@ -1277,11 +1288,20 @@ class SsaBuilder implements Visitor { |
| updateEndBlock.addSuccessor(conditionBlock); |
| conditionBlock.postProcessLoopHeader(); |
| SubExpression updateGraph = new SubExpression(updateBlock, updateEndBlock); |
| - loopInfo.updates = new HSubExpressionBlockInformation(updateGraph); |
| endLoop(conditionBlock, conditionExitBlock, jumpHandler, savedLocals); |
| - loopInfo.joinBlock = current; |
| - initializerBlock.blockInformation = loopInfo; |
| + HLoopBlockInformation info = |
| + new HLoopBlockInformation( |
| + HLoopBlockInformation.loopType(loop), |
| + wrapExpressionGraph(initializerGraph), |
| + wrapExpressionGraph(conditionExpression), |
| + wrapStatementGraph(bodyGraph), |
| + wrapExpressionGraph(updateGraph), |
| + conditionBlock.loopInformation.target, |
| + conditionBlock.loopInformation.labels); |
| + |
| + startBlock.setBlockInfo(info, current); |
| + loopInfo.loopBlockInformation = info; |
| } |
| visitFor(For node) { |
| @@ -1334,7 +1354,7 @@ class SsaBuilder implements Visitor { |
| LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); |
| localsHandler.startLoop(node); |
| JumpHandler jumpHandler = beginLoopHeader(node); |
| - HLoopInformation loopInfo = current.blockInformation; |
| + HLoopInformation loopInfo = current.loopInformation; |
| HBasicBlock loopEntryBlock = current; |
| HBasicBlock bodyEntryBlock = current; |
| TargetElement target = elements[node]; |
| @@ -1369,17 +1389,19 @@ class SsaBuilder implements Visitor { |
| SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock); |
| List<LabelElement> labels = jumpHandler.labels(); |
| if (!labels.isEmpty()) { |
| - bodyEntryBlock.blockInformation = new HLabeledBlockInformation( |
| + bodyEntryBlock.setBlockInfo( |
| + new HLabeledBlockInformation( |
|
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Made this easier to read too.
|
| new HSubGraphBlockInformation(bodyGraph), |
| - conditionBlock, |
| labels, |
| - isContinue: true); |
| + isContinue: true), |
| + conditionBlock); |
| } else { |
| - bodyEntryBlock.blockInformation = new HLabeledBlockInformation.implicit( |
| - new HSubGraphBlockInformation(bodyGraph), |
| - conditionBlock, |
| - target, |
| - isContinue: true); |
| + bodyEntryBlock.setBlockInfo( |
| + new HLabeledBlockInformation.implicit( |
| + new HSubGraphBlockInformation(bodyGraph), |
| + target, |
| + isContinue: true), |
| + conditionBlock); |
| } |
| } |
| open(conditionBlock); |
| @@ -1396,11 +1418,17 @@ class SsaBuilder implements Visitor { |
| endLoop(loopEntryBlock, conditionEndBlock, jumpHandler, localsHandler); |
| jumpHandler.close(); |
| - loopInfo.body = new HSubGraphBlockInformation( |
| - new SubGraph(bodyEntryBlock, bodyExitBlock)); |
| - loopInfo.condition = new HSubExpressionBlockInformation( |
| - new SubExpression(conditionBlock, conditionEndBlock)); |
| - loopInfo.joinBlock = current; |
| + HLoopBlockInformation loopBlockInfo = new HLoopBlockInformation( |
|
karlklose
2012/05/08 08:02:46
This constructor call is hard to read. Could you p
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Done.
|
| + HLoopBlockInformation.DO_WHILE_LOOP, |
| + null, |
| + wrapExpressionGraph(new SubExpression(conditionBlock, |
|
karlklose
2012/05/08 08:02:46
Store the subexpression in a local variable?
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Done.
|
| + conditionEndBlock)), |
| + wrapStatementGraph(new SubGraph(bodyEntryBlock, bodyExitBlock)), |
|
karlklose
2012/05/08 08:02:46
Ditto for the subgraph?
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Done.
|
| + null, |
| + loopEntryBlock.loopInformation.target, |
| + loopEntryBlock.loopInformation.labels); |
| + loopEntryBlock.setBlockInfo(loopBlockInfo, current); |
| + loopInfo.loopBlockInformation = loopBlockInfo; |
| } |
| visitFunctionExpression(FunctionExpression node) { |
| @@ -1512,10 +1540,9 @@ class SsaBuilder implements Visitor { |
| HIfBlockInformation info = new HIfBlockInformation( |
| new HSubExpressionBlockInformation(conditionGraph), |
| new HSubGraphBlockInformation(thenGraph), |
| - (elseGraph === null) ? null : new HSubGraphBlockInformation(elseGraph), |
| - joinBlock); |
| - conditionStartBlock.blockInformation = info; |
| - branch.blockInformation = info; |
| + (elseGraph === null) ? null : new HSubGraphBlockInformation(elseGraph)); |
|
karlklose
2012/05/08 08:02:46
wrapStatmentGraph(elseGraph)
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Done.
|
| + conditionStartBlock.setBlockInfo(info, joinBlock); |
| + branch.blockInformation = conditionStartBlock.blockInformation; |
| } |
| void visitLogicalAndOr(Send node, Operator op) { |
| @@ -1566,18 +1593,19 @@ class SsaBuilder implements Visitor { |
| rightBlock.addSuccessor(joinBlock); |
| open(joinBlock); |
| - leftGraph.start.blockInformation = new HAndOrBlockInformation( |
| - isAnd, |
| - new HSubExpressionBlockInformation(leftGraph), |
| - new HSubExpressionBlockInformation(rightGraph), |
| + leftGraph.start.setBlockInfo( |
| + new HAndOrBlockInformation( |
| + isAnd, |
| + new HSubExpressionBlockInformation(leftGraph), |
| + new HSubExpressionBlockInformation(rightGraph)), |
| joinBlock); |
| // Fallback until we handle and-or-information better. |
| - branch.blockInformation = new HIfBlockInformation( |
| - new HSubExpressionBlockInformation(leftGraph), |
| - new HSubGraphBlockInformation(rightGraph), |
| - null, |
| - joinBlock |
| - ); |
| + branch.blockInformation = new HBlockFlow( |
| + new HIfBlockInformation( |
| + new HSubExpressionBlockInformation(leftGraph), |
| + new HSubGraphBlockInformation(rightGraph), |
| + null |
| + ), joinBlock); |
| localsHandler.mergeWith(savedLocals, joinBlock); |
| HPhi result = new HPhi.manyInputs(null, |
| @@ -2622,10 +2650,11 @@ class SsaBuilder implements Visitor { |
| elseBlock.addSuccessor(joinBlock); |
| // TODO(lrn): Handle expressions better. |
| - condition.blockInformation = new HIfBlockInformation( |
| - new HSubExpressionBlockInformation(conditionGraph), |
| - new HSubGraphBlockInformation(thenGraph), |
| - new HSubGraphBlockInformation(elseGraph), |
| + condition.blockInformation = new HBlockFlow( |
| + new HIfBlockInformation( |
| + new HSubExpressionBlockInformation(conditionGraph), |
| + new HSubGraphBlockInformation(thenGraph), |
| + new HSubGraphBlockInformation(elseGraph)), |
| joinBlock); |
| open(joinBlock); |
| @@ -2787,9 +2816,10 @@ class SsaBuilder implements Visitor { |
| if (hasBreak) { |
| // There was at least one reachable break, so the label is needed. |
| - entryBlock.blockInformation = |
| + entryBlock.setBlockInfo( |
| new HLabeledBlockInformation(new HSubGraphBlockInformation(bodyGraph), |
| - joinBlock, handler.labels()); |
| + handler.labels()), |
| + joinBlock); |
| } |
| handler.close(); |
| } |
| @@ -2869,10 +2899,11 @@ class SsaBuilder implements Visitor { |
| // The joinblock is not used. |
| joinBlock = null; |
| } |
| - startBlock.blockInformation = new HLabeledBlockInformation.implicit( |
| - new HSubGraphBlockInformation(new SubGraph(startBlock, lastBlock)), |
| - joinBlock, |
| - elements[node]); |
| + startBlock.setBlockInfo( |
| + new HLabeledBlockInformation.implicit( |
| + new HSubGraphBlockInformation(new SubGraph(startBlock, lastBlock)), |
| + elements[node]), |
| + joinBlock); |
| jumpHandler.close(); |
| } |
| @@ -3059,12 +3090,15 @@ class SsaBuilder implements Visitor { |
| } |
| open(exitBlock); |
| - enterBlock.blockInformation = new HTryBlockInformation( |
| - new HSubGraphBlockInformation(bodyGraph), |
| - exception, |
| - catchGraph == null ? null : new HSubGraphBlockInformation(catchGraph), |
| - finallyGraph == null ? null : new HSubGraphBlockInformation(finallyGraph), |
| - exitBlock); |
| + enterBlock.setBlockInfo( |
| + new HTryBlockInformation( |
| + new HSubGraphBlockInformation(bodyGraph), |
| + exception, |
| + catchGraph == null ? null |
|
karlklose
2012/05/08 08:02:46
use wrapStatementGraph
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Done.
|
| + : new HSubGraphBlockInformation(catchGraph), |
| + finallyGraph == null ? null |
|
karlklose
2012/05/08 08:02:46
ditto.
Lasse Reichstein Nielsen
2012/05/08 11:40:34
Done.
|
| + : new HSubGraphBlockInformation(finallyGraph)), |
| + exitBlock); |
| } |
| visitScriptTag(ScriptTag node) { |