Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Side by Side Diff: lib/compiler/implementation/ssa/builder.dart

Issue 10384027: Wrap block-informations when embedding them in the graph. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 * Creates a new loop-header block. The previous [current] block 1133 * Creates a new loop-header block. The previous [current] block
1134 * is closed with an [HGoto] and replaced by the newly created block. 1134 * is closed with an [HGoto] and replaced by the newly created block.
1135 * Also notifies the locals handler that we're entering a loop. 1135 * Also notifies the locals handler that we're entering a loop.
1136 */ 1136 */
1137 JumpHandler beginLoopHeader(Node node) { 1137 JumpHandler beginLoopHeader(Node node) {
1138 assert(!isAborted()); 1138 assert(!isAborted());
1139 HBasicBlock previousBlock = close(new HGoto()); 1139 HBasicBlock previousBlock = close(new HGoto());
1140 1140
1141 JumpHandler jumpHandler = createJumpHandler(node); 1141 JumpHandler jumpHandler = createJumpHandler(node);
1142 HBasicBlock loopEntry = graph.addNewLoopHeaderBlock( 1142 HBasicBlock loopEntry = graph.addNewLoopHeaderBlock(
1143 HLoopInformation.loopType(node),
1144 jumpHandler.target, 1143 jumpHandler.target,
1145 jumpHandler.labels()); 1144 jumpHandler.labels());
1146 previousBlock.addSuccessor(loopEntry); 1145 previousBlock.addSuccessor(loopEntry);
1147 open(loopEntry); 1146 open(loopEntry);
1148 1147
1149 localsHandler.beginLoopHeader(node, loopEntry); 1148 localsHandler.beginLoopHeader(node, loopEntry);
1150 return jumpHandler; 1149 return jumpHandler;
1151 } 1150 }
1152 1151
1153 /** 1152 /**
(...skipping 17 matching lines...) Expand all
1171 open(loopExitBlock); 1170 open(loopExitBlock);
1172 localsHandler.endLoop(loopEntry); 1171 localsHandler.endLoop(loopEntry);
1173 if (!breakLocals.isEmpty()) { 1172 if (!breakLocals.isEmpty()) {
1174 breakLocals.add(savedLocals); 1173 breakLocals.add(savedLocals);
1175 localsHandler = savedLocals.mergeMultiple(breakLocals, loopExitBlock); 1174 localsHandler = savedLocals.mergeMultiple(breakLocals, loopExitBlock);
1176 } else { 1175 } else {
1177 localsHandler = savedLocals; 1176 localsHandler = savedLocals;
1178 } 1177 }
1179 } 1178 }
1180 1179
1180 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) {
1181 if (statements === null) return null;
1182 return new HSubGraphBlockInformation(statements);
1183 }
1184
1185 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) {
1186 if (expression === null) return null;
1187 return new HSubExpressionBlockInformation(expression);
1188 }
1189
1181 // For while loops, initializer and update are null. 1190 // For while loops, initializer and update are null.
1182 // The condition function must return a boolean result. 1191 // The condition function must return a boolean result.
1183 // None of the functions must leave anything on the stack. 1192 // None of the functions must leave anything on the stack.
1184 handleLoop(Node loop, 1193 handleLoop(Node loop,
1185 void initialize(), 1194 void initialize(),
1186 HInstruction condition(), 1195 HInstruction condition(),
1187 void update(), 1196 void update(),
1188 void body()) { 1197 void body()) {
1189 // Generate: 1198 // Generate:
1190 // <initializer> 1199 // <initializer>
1191 // loop-entry: 1200 // loop-entry:
1192 // if (!<condition>) goto loop-exit; 1201 // if (!<condition>) goto loop-exit;
1193 // <body> 1202 // <body>
1194 // <updates> 1203 // <updates>
1195 // goto loop-entry; 1204 // goto loop-entry;
1196 // loop-exit: 1205 // loop-exit:
1197 1206
1198 localsHandler.startLoop(loop); 1207 localsHandler.startLoop(loop);
1199 1208
1200 // The initializer. 1209 // The initializer.
1201 HBasicBlock initializerBlock = openNewBlock(); 1210 SubExpression initializerGraph = null;
1202 initialize(); 1211 HBasicBlock startBlock;
1203 assert(!isAborted()); 1212 if (initialize !== null) {
1204 SubExpression initializerGraph = 1213 HBasicBlock initializerBlock = openNewBlock();
1205 new SubExpression(initializerBlock, current); 1214 startBlock = initializerBlock;
1215 initialize();
1216 assert(!isAborted());
1217 initializerGraph =
1218 new SubExpression(initializerBlock, current);
1219 }
1206 1220
1207 JumpHandler jumpHandler = beginLoopHeader(loop); 1221 JumpHandler jumpHandler = beginLoopHeader(loop);
1222 HLoopInformation loopInfo = current.loopInformation;
1208 HBasicBlock conditionBlock = current; 1223 HBasicBlock conditionBlock = current;
1209 HLoopInformation loopInfo = current.blockInformation; 1224 if (startBlock === null) startBlock = conditionBlock;
1210 // The initializer graph is currently unused due to the way we
1211 // generate code.
1212 loopInfo.initializer = new HSubExpressionBlockInformation(initializerGraph);
1213 1225
1214 HInstruction conditionInstruction = condition(); 1226 HInstruction conditionInstruction = condition();
1215 HBasicBlock conditionExitBlock = 1227 HBasicBlock conditionExitBlock =
1216 close(new HLoopBranch(conditionInstruction)); 1228 close(new HLoopBranch(conditionInstruction));
1217 SubExpression conditionExpression = 1229 SubExpression conditionExpression =
1218 new SubExpression(conditionBlock, conditionExitBlock); 1230 new SubExpression(conditionBlock, conditionExitBlock);
1219 loopInfo.condition =
1220 new HSubExpressionBlockInformation(conditionExpression);
1221 1231
1222 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 1232 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
1223 1233
1224 // The body. 1234 // The body.
1225 HBasicBlock beginBodyBlock = addNewBlock(); 1235 HBasicBlock beginBodyBlock = addNewBlock();
1226 conditionExitBlock.addSuccessor(beginBodyBlock); 1236 conditionExitBlock.addSuccessor(beginBodyBlock);
1227 open(beginBodyBlock); 1237 open(beginBodyBlock);
1228 1238
1229 localsHandler.enterLoopBody(loop); 1239 localsHandler.enterLoopBody(loop);
1230 hackAroundPossiblyAbortingBody(loop, body); 1240 hackAroundPossiblyAbortingBody(loop, body);
1231 1241
1232 SubGraph bodyGraph = new SubGraph(beginBodyBlock, current); 1242 SubGraph bodyGraph = new SubGraph(beginBodyBlock, current);
1233 HBasicBlock bodyBlock = close(new HGoto()); 1243 HBasicBlock bodyBlock = close(new HGoto());
1234 loopInfo.body = new HSubGraphBlockInformation(bodyGraph);
1235 1244
1236 // Update. 1245 // Update.
1237 // We create an update block, even when we are in a while loop. There the 1246 // We create an update block, even when we are in a while loop. There the
1238 // update block is the jump-target for continue statements. We could avoid 1247 // update block is the jump-target for continue statements. We could avoid
1239 // the creation if there is no continue, but for now we always create it. 1248 // the creation if there is no continue, but for now we always create it.
1240 HBasicBlock updateBlock = addNewBlock(); 1249 HBasicBlock updateBlock = addNewBlock();
1241 1250
1242 List<LocalsHandler> continueLocals = <LocalsHandler>[]; 1251 List<LocalsHandler> continueLocals = <LocalsHandler>[];
1243 jumpHandler.forEachContinue((HContinue instruction, LocalsHandler locals) { 1252 jumpHandler.forEachContinue((HContinue instruction, LocalsHandler locals) {
1244 instruction.block.addSuccessor(updateBlock); 1253 instruction.block.addSuccessor(updateBlock);
1245 continueLocals.add(locals); 1254 continueLocals.add(locals);
1246 }); 1255 });
1247 bodyBlock.addSuccessor(updateBlock); 1256 bodyBlock.addSuccessor(updateBlock);
1248 continueLocals.add(localsHandler); 1257 continueLocals.add(localsHandler);
1249 1258
1250 open(updateBlock); 1259 open(updateBlock);
1251 1260
1252 localsHandler = localsHandler.mergeMultiple(continueLocals, updateBlock); 1261 localsHandler = localsHandler.mergeMultiple(continueLocals, updateBlock);
1253 1262
1254 HLabeledBlockInformation labelInfo; 1263 HLabeledBlockInformation labelInfo;
1255 List<LabelElement> labels = jumpHandler.labels(); 1264 List<LabelElement> labels = jumpHandler.labels();
1256 TargetElement target = elements[loop]; 1265 TargetElement target = elements[loop];
1257 if (!labels.isEmpty()) { 1266 if (!labels.isEmpty()) {
1258 beginBodyBlock.blockInformation = new HLabeledBlockInformation( 1267 beginBodyBlock.setBlockInfo(
1259 new HSubGraphBlockInformation(bodyGraph), 1268 new HLabeledBlockInformation(
1260 updateBlock, 1269 new HSubGraphBlockInformation(bodyGraph),
1261 jumpHandler.labels(), 1270 jumpHandler.labels(),
1262 isContinue: true); 1271 isContinue: true),
1272 updateBlock);
1263 } else if (target !== null && target.isContinueTarget) { 1273 } else if (target !== null && target.isContinueTarget) {
1264 beginBodyBlock.blockInformation = new HLabeledBlockInformation.implicit( 1274 beginBodyBlock.setBlockInfo(
1265 new HSubGraphBlockInformation(bodyGraph), 1275 new HLabeledBlockInformation.implicit(
1266 updateBlock, 1276 new HSubGraphBlockInformation(bodyGraph),
1267 target, 1277 target,
1268 isContinue: true); 1278 isContinue: true),
1279 updateBlock);
1269 } 1280 }
1270 1281
1271 localsHandler.enterLoopUpdates(loop); 1282 localsHandler.enterLoopUpdates(loop);
1272 1283
1273 update(); 1284 update();
1274 1285
1275 HBasicBlock updateEndBlock = close(new HGoto()); 1286 HBasicBlock updateEndBlock = close(new HGoto());
1276 // The back-edge completing the cycle. 1287 // The back-edge completing the cycle.
1277 updateEndBlock.addSuccessor(conditionBlock); 1288 updateEndBlock.addSuccessor(conditionBlock);
1278 conditionBlock.postProcessLoopHeader(); 1289 conditionBlock.postProcessLoopHeader();
1279 SubExpression updateGraph = new SubExpression(updateBlock, updateEndBlock); 1290 SubExpression updateGraph = new SubExpression(updateBlock, updateEndBlock);
1280 loopInfo.updates = new HSubExpressionBlockInformation(updateGraph);
1281 1291
1282 endLoop(conditionBlock, conditionExitBlock, jumpHandler, savedLocals); 1292 endLoop(conditionBlock, conditionExitBlock, jumpHandler, savedLocals);
1283 loopInfo.joinBlock = current; 1293 HLoopBlockInformation info =
1284 initializerBlock.blockInformation = loopInfo; 1294 new HLoopBlockInformation(
1295 HLoopBlockInformation.loopType(loop),
1296 wrapExpressionGraph(initializerGraph),
1297 wrapExpressionGraph(conditionExpression),
1298 wrapStatementGraph(bodyGraph),
1299 wrapExpressionGraph(updateGraph),
1300 conditionBlock.loopInformation.target,
1301 conditionBlock.loopInformation.labels);
1302
1303 startBlock.setBlockInfo(info, current);
1304 loopInfo.loopBlockInformation = info;
1285 } 1305 }
1286 1306
1287 visitFor(For node) { 1307 visitFor(For node) {
1288 assert(node.body !== null); 1308 assert(node.body !== null);
1289 void buildInitializer() { 1309 void buildInitializer() {
1290 if (node.initializer === null) return; 1310 if (node.initializer === null) return;
1291 Node initializer = node.initializer; 1311 Node initializer = node.initializer;
1292 if (initializer !== null) { 1312 if (initializer !== null) {
1293 visit(initializer); 1313 visit(initializer);
1294 if (initializer.asExpression() !== null) { 1314 if (initializer.asExpression() !== null) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 () {}, 1347 () {},
1328 buildCondition, 1348 buildCondition,
1329 () {}, 1349 () {},
1330 () { visit(node.body); }); 1350 () { visit(node.body); });
1331 } 1351 }
1332 1352
1333 visitDoWhile(DoWhile node) { 1353 visitDoWhile(DoWhile node) {
1334 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 1354 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
1335 localsHandler.startLoop(node); 1355 localsHandler.startLoop(node);
1336 JumpHandler jumpHandler = beginLoopHeader(node); 1356 JumpHandler jumpHandler = beginLoopHeader(node);
1337 HLoopInformation loopInfo = current.blockInformation; 1357 HLoopInformation loopInfo = current.loopInformation;
1338 HBasicBlock loopEntryBlock = current; 1358 HBasicBlock loopEntryBlock = current;
1339 HBasicBlock bodyEntryBlock = current; 1359 HBasicBlock bodyEntryBlock = current;
1340 TargetElement target = elements[node]; 1360 TargetElement target = elements[node];
1341 bool hasContinues = target !== null && target.isContinueTarget; 1361 bool hasContinues = target !== null && target.isContinueTarget;
1342 if (hasContinues) { 1362 if (hasContinues) {
1343 // Add extra block to hang labels on. 1363 // Add extra block to hang labels on.
1344 // It doesn't currently work if they are on the same block as the 1364 // It doesn't currently work if they are on the same block as the
1345 // HLoopInfo. The handling of HLabeledBlockInformation will visit a 1365 // HLoopInfo. The handling of HLabeledBlockInformation will visit a
1346 // SubGraph that starts at the same block again, so the HLoopInfo is 1366 // SubGraph that starts at the same block again, so the HLoopInfo is
1347 // either handled twice, or it's handled after the labeled block info, 1367 // either handled twice, or it's handled after the labeled block info,
(...skipping 14 matching lines...) Expand all
1362 instruction.block.addSuccessor(conditionBlock); 1382 instruction.block.addSuccessor(conditionBlock);
1363 continueLocals.add(locals); 1383 continueLocals.add(locals);
1364 }); 1384 });
1365 bodyExitBlock.addSuccessor(conditionBlock); 1385 bodyExitBlock.addSuccessor(conditionBlock);
1366 if (!continueLocals.isEmpty()) { 1386 if (!continueLocals.isEmpty()) {
1367 continueLocals.add(localsHandler); 1387 continueLocals.add(localsHandler);
1368 localsHandler = savedLocals.mergeMultiple(continueLocals, conditionBlock); 1388 localsHandler = savedLocals.mergeMultiple(continueLocals, conditionBlock);
1369 SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock); 1389 SubGraph bodyGraph = new SubGraph(bodyEntryBlock, bodyExitBlock);
1370 List<LabelElement> labels = jumpHandler.labels(); 1390 List<LabelElement> labels = jumpHandler.labels();
1371 if (!labels.isEmpty()) { 1391 if (!labels.isEmpty()) {
1372 bodyEntryBlock.blockInformation = new HLabeledBlockInformation( 1392 bodyEntryBlock.setBlockInfo(
1393 new HLabeledBlockInformation(
Lasse Reichstein Nielsen 2012/05/08 11:40:34 Made this easier to read too.
1373 new HSubGraphBlockInformation(bodyGraph), 1394 new HSubGraphBlockInformation(bodyGraph),
1374 conditionBlock,
1375 labels, 1395 labels,
1376 isContinue: true); 1396 isContinue: true),
1397 conditionBlock);
1377 } else { 1398 } else {
1378 bodyEntryBlock.blockInformation = new HLabeledBlockInformation.implicit( 1399 bodyEntryBlock.setBlockInfo(
1379 new HSubGraphBlockInformation(bodyGraph), 1400 new HLabeledBlockInformation.implicit(
1380 conditionBlock, 1401 new HSubGraphBlockInformation(bodyGraph),
1381 target, 1402 target,
1382 isContinue: true); 1403 isContinue: true),
1404 conditionBlock);
1383 } 1405 }
1384 } 1406 }
1385 open(conditionBlock); 1407 open(conditionBlock);
1386 1408
1387 visit(node.condition); 1409 visit(node.condition);
1388 assert(!isAborted()); 1410 assert(!isAborted());
1389 HInstruction conditionInstruction = popBoolified(); 1411 HInstruction conditionInstruction = popBoolified();
1390 HBasicBlock conditionEndBlock = 1412 HBasicBlock conditionEndBlock =
1391 close(new HLoopBranch(conditionInstruction, HLoopBranch.DO_WHILE_LOOP)); 1413 close(new HLoopBranch(conditionInstruction, HLoopBranch.DO_WHILE_LOOP));
1392 1414
1393 conditionEndBlock.addSuccessor(loopEntryBlock); // The back-edge. 1415 conditionEndBlock.addSuccessor(loopEntryBlock); // The back-edge.
1394 loopEntryBlock.postProcessLoopHeader(); 1416 loopEntryBlock.postProcessLoopHeader();
1395 1417
1396 endLoop(loopEntryBlock, conditionEndBlock, jumpHandler, localsHandler); 1418 endLoop(loopEntryBlock, conditionEndBlock, jumpHandler, localsHandler);
1397 jumpHandler.close(); 1419 jumpHandler.close();
1398 1420
1399 loopInfo.body = new HSubGraphBlockInformation( 1421 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.
1400 new SubGraph(bodyEntryBlock, bodyExitBlock)); 1422 HLoopBlockInformation.DO_WHILE_LOOP,
1401 loopInfo.condition = new HSubExpressionBlockInformation( 1423 null,
1402 new SubExpression(conditionBlock, conditionEndBlock)); 1424 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.
1403 loopInfo.joinBlock = current; 1425 conditionEndBlock)),
1426 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.
1427 null,
1428 loopEntryBlock.loopInformation.target,
1429 loopEntryBlock.loopInformation.labels);
1430 loopEntryBlock.setBlockInfo(loopBlockInfo, current);
1431 loopInfo.loopBlockInformation = loopBlockInfo;
1404 } 1432 }
1405 1433
1406 visitFunctionExpression(FunctionExpression node) { 1434 visitFunctionExpression(FunctionExpression node) {
1407 ClosureData nestedClosureData = compiler.builder.closureDataCache[node]; 1435 ClosureData nestedClosureData = compiler.builder.closureDataCache[node];
1408 if (nestedClosureData === null) { 1436 if (nestedClosureData === null) {
1409 // TODO(floitsch): we can only assume that the reason for not having a 1437 // TODO(floitsch): we can only assume that the reason for not having a
1410 // closure data here is, because the function is inside an initializer. 1438 // closure data here is, because the function is inside an initializer.
1411 compiler.unimplemented("Closures inside initializers", node: node); 1439 compiler.unimplemented("Closures inside initializers", node: node);
1412 } 1440 }
1413 assert(nestedClosureData !== null); 1441 assert(nestedClosureData !== null);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 if (joinBlock.predecessors.length == 2) { 1533 if (joinBlock.predecessors.length == 2) {
1506 localsHandler.mergeWith(thenLocals, joinBlock); 1534 localsHandler.mergeWith(thenLocals, joinBlock);
1507 } else if (thenBlock !== null) { 1535 } else if (thenBlock !== null) {
1508 // The only predecessor is the then branch. 1536 // The only predecessor is the then branch.
1509 localsHandler = thenLocals; 1537 localsHandler = thenLocals;
1510 } 1538 }
1511 } 1539 }
1512 HIfBlockInformation info = new HIfBlockInformation( 1540 HIfBlockInformation info = new HIfBlockInformation(
1513 new HSubExpressionBlockInformation(conditionGraph), 1541 new HSubExpressionBlockInformation(conditionGraph),
1514 new HSubGraphBlockInformation(thenGraph), 1542 new HSubGraphBlockInformation(thenGraph),
1515 (elseGraph === null) ? null : new HSubGraphBlockInformation(elseGraph), 1543 (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.
1516 joinBlock); 1544 conditionStartBlock.setBlockInfo(info, joinBlock);
1517 conditionStartBlock.blockInformation = info; 1545 branch.blockInformation = conditionStartBlock.blockInformation;
1518 branch.blockInformation = info;
1519 } 1546 }
1520 1547
1521 void visitLogicalAndOr(Send node, Operator op) { 1548 void visitLogicalAndOr(Send node, Operator op) {
1522 handleLogicalAndOr(() { visit(node.receiver); }, 1549 handleLogicalAndOr(() { visit(node.receiver); },
1523 () { visit(node.argumentsNode); }, 1550 () { visit(node.argumentsNode); },
1524 isAnd: (const SourceString("&&") == op.source)); 1551 isAnd: (const SourceString("&&") == op.source));
1525 } 1552 }
1526 1553
1527 1554
1528 void handleLogicalAndOr(void left(), void right(), [bool isAnd = true]) { 1555 void handleLogicalAndOr(void left(), void right(), [bool isAnd = true]) {
(...skipping 30 matching lines...) Expand all
1559 HInstruction boolifiedRight = popBoolified(); 1586 HInstruction boolifiedRight = popBoolified();
1560 SubExpression rightGraph = 1587 SubExpression rightGraph =
1561 new SubExpression(rightBlock, current); 1588 new SubExpression(rightBlock, current);
1562 rightBlock = close(new HGoto()); 1589 rightBlock = close(new HGoto());
1563 1590
1564 HBasicBlock joinBlock = addNewBlock(); 1591 HBasicBlock joinBlock = addNewBlock();
1565 leftBlock.addSuccessor(joinBlock); 1592 leftBlock.addSuccessor(joinBlock);
1566 rightBlock.addSuccessor(joinBlock); 1593 rightBlock.addSuccessor(joinBlock);
1567 open(joinBlock); 1594 open(joinBlock);
1568 1595
1569 leftGraph.start.blockInformation = new HAndOrBlockInformation( 1596 leftGraph.start.setBlockInfo(
1570 isAnd, 1597 new HAndOrBlockInformation(
1571 new HSubExpressionBlockInformation(leftGraph), 1598 isAnd,
1572 new HSubExpressionBlockInformation(rightGraph), 1599 new HSubExpressionBlockInformation(leftGraph),
1600 new HSubExpressionBlockInformation(rightGraph)),
1573 joinBlock); 1601 joinBlock);
1574 // Fallback until we handle and-or-information better. 1602 // Fallback until we handle and-or-information better.
1575 branch.blockInformation = new HIfBlockInformation( 1603 branch.blockInformation = new HBlockFlow(
1576 new HSubExpressionBlockInformation(leftGraph), 1604 new HIfBlockInformation(
1577 new HSubGraphBlockInformation(rightGraph), 1605 new HSubExpressionBlockInformation(leftGraph),
1578 null, 1606 new HSubGraphBlockInformation(rightGraph),
1579 joinBlock 1607 null
1580 ); 1608 ), joinBlock);
1581 1609
1582 localsHandler.mergeWith(savedLocals, joinBlock); 1610 localsHandler.mergeWith(savedLocals, joinBlock);
1583 HPhi result = new HPhi.manyInputs(null, 1611 HPhi result = new HPhi.manyInputs(null,
1584 <HInstruction>[boolifiedLeft, boolifiedRight]); 1612 <HInstruction>[boolifiedLeft, boolifiedRight]);
1585 joinBlock.addPhi(result); 1613 joinBlock.addPhi(result);
1586 stack.add(result); 1614 stack.add(result);
1587 } 1615 }
1588 1616
1589 void visitLogicalNot(Send node) { 1617 void visitLogicalNot(Send node) {
1590 assert(node.argumentsNode is Prefix); 1618 assert(node.argumentsNode is Prefix);
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 visit(node.elseExpression); 2643 visit(node.elseExpression);
2616 HInstruction elseInstruction = pop(); 2644 HInstruction elseInstruction = pop();
2617 SubGraph elseGraph = new SubGraph(elseBlock, current); 2645 SubGraph elseGraph = new SubGraph(elseBlock, current);
2618 elseBlock = close(new HGoto()); 2646 elseBlock = close(new HGoto());
2619 2647
2620 HBasicBlock joinBlock = addNewBlock(); 2648 HBasicBlock joinBlock = addNewBlock();
2621 thenBlock.addSuccessor(joinBlock); 2649 thenBlock.addSuccessor(joinBlock);
2622 elseBlock.addSuccessor(joinBlock); 2650 elseBlock.addSuccessor(joinBlock);
2623 2651
2624 // TODO(lrn): Handle expressions better. 2652 // TODO(lrn): Handle expressions better.
2625 condition.blockInformation = new HIfBlockInformation( 2653 condition.blockInformation = new HBlockFlow(
2626 new HSubExpressionBlockInformation(conditionGraph), 2654 new HIfBlockInformation(
2627 new HSubGraphBlockInformation(thenGraph), 2655 new HSubExpressionBlockInformation(conditionGraph),
2628 new HSubGraphBlockInformation(elseGraph), 2656 new HSubGraphBlockInformation(thenGraph),
2657 new HSubGraphBlockInformation(elseGraph)),
2629 joinBlock); 2658 joinBlock);
2630 open(joinBlock); 2659 open(joinBlock);
2631 2660
2632 localsHandler.mergeWith(thenLocals, joinBlock); 2661 localsHandler.mergeWith(thenLocals, joinBlock);
2633 HPhi phi = new HPhi.manyInputs(null, 2662 HPhi phi = new HPhi.manyInputs(null,
2634 <HInstruction>[thenInstruction, elseInstruction]); 2663 <HInstruction>[thenInstruction, elseInstruction]);
2635 joinBlock.addPhi(phi); 2664 joinBlock.addPhi(phi);
2636 stack.add(phi); 2665 stack.add(phi);
2637 } 2666 }
2638 2667
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 bool hasBreak = breakLocals.length > 0; 2809 bool hasBreak = breakLocals.length > 0;
2781 if (!isAborted()) { 2810 if (!isAborted()) {
2782 goto(current, joinBlock); 2811 goto(current, joinBlock);
2783 breakLocals.add(localsHandler); 2812 breakLocals.add(localsHandler);
2784 } 2813 }
2785 open(joinBlock); 2814 open(joinBlock);
2786 localsHandler = beforeLocals.mergeMultiple(breakLocals, joinBlock); 2815 localsHandler = beforeLocals.mergeMultiple(breakLocals, joinBlock);
2787 2816
2788 if (hasBreak) { 2817 if (hasBreak) {
2789 // There was at least one reachable break, so the label is needed. 2818 // There was at least one reachable break, so the label is needed.
2790 entryBlock.blockInformation = 2819 entryBlock.setBlockInfo(
2791 new HLabeledBlockInformation(new HSubGraphBlockInformation(bodyGraph), 2820 new HLabeledBlockInformation(new HSubGraphBlockInformation(bodyGraph),
2792 joinBlock, handler.labels()); 2821 handler.labels()),
2822 joinBlock);
2793 } 2823 }
2794 handler.close(); 2824 handler.close();
2795 } 2825 }
2796 2826
2797 visitLiteralMap(LiteralMap node) { 2827 visitLiteralMap(LiteralMap node) {
2798 if (node.isConst()) { 2828 if (node.isConst()) {
2799 ConstantHandler handler = compiler.constantHandler; 2829 ConstantHandler handler = compiler.constantHandler;
2800 Constant constant = handler.compileNodeWithDefinitions(node, elements); 2830 Constant constant = handler.compileNodeWithDefinitions(node, elements);
2801 stack.add(graph.addConstant(constant)); 2831 stack.add(graph.addConstant(constant));
2802 return; 2832 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2862 open(joinBlock); 2892 open(joinBlock);
2863 if (caseLocals.length == 1) { 2893 if (caseLocals.length == 1) {
2864 localsHandler = caseLocals[0]; 2894 localsHandler = caseLocals[0];
2865 } else { 2895 } else {
2866 localsHandler = savedLocals.mergeMultiple(caseLocals, joinBlock); 2896 localsHandler = savedLocals.mergeMultiple(caseLocals, joinBlock);
2867 } 2897 }
2868 } else { 2898 } else {
2869 // The joinblock is not used. 2899 // The joinblock is not used.
2870 joinBlock = null; 2900 joinBlock = null;
2871 } 2901 }
2872 startBlock.blockInformation = new HLabeledBlockInformation.implicit( 2902 startBlock.setBlockInfo(
2873 new HSubGraphBlockInformation(new SubGraph(startBlock, lastBlock)), 2903 new HLabeledBlockInformation.implicit(
2874 joinBlock, 2904 new HSubGraphBlockInformation(new SubGraph(startBlock, lastBlock)),
2875 elements[node]); 2905 elements[node]),
2906 joinBlock);
2876 jumpHandler.close(); 2907 jumpHandler.close();
2877 } 2908 }
2878 2909
2879 2910
2880 // Recursively build an if/else structure to match the cases. 2911 // Recursively build an if/else structure to match the cases.
2881 buildSwitchCases(Link<Node> cases, HInstruction expression) { 2912 buildSwitchCases(Link<Node> cases, HInstruction expression) {
2882 SwitchCase node = cases.head; 2913 SwitchCase node = cases.head;
2883 2914
2884 // Called for the statements on all but the last case block. 2915 // Called for the statements on all but the last case block.
2885 // Ensures that a user expecting a fallthrough gets an error. 2916 // Ensures that a user expecting a fallthrough gets an error.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 finallyGraph = new SubGraph(finallyBlock, lastOpenedBlock); 3083 finallyGraph = new SubGraph(finallyBlock, lastOpenedBlock);
3053 } 3084 }
3054 3085
3055 HBasicBlock exitBlock = graph.addNewBlock(); 3086 HBasicBlock exitBlock = graph.addNewBlock();
3056 3087
3057 for (HBasicBlock block in blocks) { 3088 for (HBasicBlock block in blocks) {
3058 block.addSuccessor(exitBlock); 3089 block.addSuccessor(exitBlock);
3059 } 3090 }
3060 3091
3061 open(exitBlock); 3092 open(exitBlock);
3062 enterBlock.blockInformation = new HTryBlockInformation( 3093 enterBlock.setBlockInfo(
3063 new HSubGraphBlockInformation(bodyGraph), 3094 new HTryBlockInformation(
3064 exception, 3095 new HSubGraphBlockInformation(bodyGraph),
3065 catchGraph == null ? null : new HSubGraphBlockInformation(catchGraph), 3096 exception,
3066 finallyGraph == null ? null : new HSubGraphBlockInformation(finallyGraph), 3097 catchGraph == null ? null
karlklose 2012/05/08 08:02:46 use wrapStatementGraph
Lasse Reichstein Nielsen 2012/05/08 11:40:34 Done.
3067 exitBlock); 3098 : new HSubGraphBlockInformation(catchGraph),
3099 finallyGraph == null ? null
karlklose 2012/05/08 08:02:46 ditto.
Lasse Reichstein Nielsen 2012/05/08 11:40:34 Done.
3100 : new HSubGraphBlockInformation(finallyGraph)),
3101 exitBlock);
3068 } 3102 }
3069 3103
3070 visitScriptTag(ScriptTag node) { 3104 visitScriptTag(ScriptTag node) {
3071 compiler.unimplemented('SsaBuilder.visitScriptTag', node: node); 3105 compiler.unimplemented('SsaBuilder.visitScriptTag', node: node);
3072 } 3106 }
3073 3107
3074 visitCatchBlock(CatchBlock node) { 3108 visitCatchBlock(CatchBlock node) {
3075 visit(node.block); 3109 visit(node.block);
3076 } 3110 }
3077 3111
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3244 <HInstruction>[target, input], 3278 <HInstruction>[target, input],
3245 HType.STRING)); 3279 HType.STRING));
3246 return builder.pop(); 3280 return builder.pop();
3247 } 3281 }
3248 3282
3249 HInstruction result() { 3283 HInstruction result() {
3250 flushLiterals(); 3284 flushLiterals();
3251 return prefix; 3285 return prefix;
3252 } 3286 }
3253 } 3287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698