comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2768:43ffa0e47a46

Towards removing stateAfter on BlockEnd.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 23 May 2011 19:21:53 +0200
parents 5e8a69041cd7
children dd6419f4bfe2
comparison
equal deleted inserted replaced
2767:cc2b98e2b832 2768:43ffa0e47a46
160 blockList[block.startBci] = block; 160 blockList[block.startBci] = block;
161 } 161 }
162 162
163 // 1. create the start block 163 // 1. create the start block
164 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); 164 Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI);
165 BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); 165 BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, false, graph);
166 startBlock.firstInstruction = startBlockBegin; 166 startBlock.firstInstruction = startBlockBegin;
167 167
168 graph.start().setStart(startBlockBegin); 168 graph.start().setStart(startBlockBegin);
169 169
170 RiExceptionHandler[] handlers = rootMethod.exceptionHandlers(); 170 RiExceptionHandler[] handlers = rootMethod.exceptionHandlers();
197 // 4A.2 finish the start block 197 // 4A.2 finish the start block
198 finishStartBlock(startBlock); 198 finishStartBlock(startBlock);
199 199
200 // 4A.3 setup an exception handler to unlock the root method synchronized object 200 // 4A.3 setup an exception handler to unlock the root method synchronized object
201 syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); 201 syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI);
202 syncHandler = new BlockBegin(Instruction.SYNCHRONIZATION_ENTRY_BCI, syncBlock.blockID, graph); 202 syncHandler = new BlockBegin(Instruction.SYNCHRONIZATION_ENTRY_BCI, syncBlock.blockID, false, graph);
203 syncBlock.firstInstruction = syncHandler; 203 syncBlock.firstInstruction = syncHandler;
204 markOnWorkList(syncBlock); 204 markOnWorkList(syncBlock);
205 205
206 ExceptionHandler h = new ExceptionHandler(new CiExceptionHandler(0, rootMethod.code().length, -1, 0, null)); 206 ExceptionHandler h = new ExceptionHandler(new CiExceptionHandler(0, rootMethod.code().length, -1, 0, null));
207 h.setEntryBlock(syncBlock); 207 h.setEntryBlock(syncBlock);
299 299
300 existingState.merge(block, stateAfter, blockAppended); 300 existingState.merge(block, stateAfter, blockAppended);
301 } 301 }
302 } else { 302 } else {
303 assert false; 303 assert false;
304 }
305
306
307
308
309 for (int j = 0; j < frameState.localsSize() + frameState.stackSize(); ++j) {
310 if (frameState.valueAt(j) != null) {
311 assert !frameState.valueAt(j).isDeleted();
312 }
304 } 313 }
305 } 314 }
306 315
307 private void insertLoopPhis(BlockBegin merge, FrameState newState) { 316 private void insertLoopPhis(BlockBegin merge, FrameState newState) {
308 int stackSize = newState.stackSize(); 317 int stackSize = newState.stackSize();
376 if (exceptionHandlers.get(current).isCatchAll()) { 385 if (exceptionHandlers.get(current).isCatchAll()) {
377 successor = createTarget(exceptionHandlers.get(current).entryBlock(), null); 386 successor = createTarget(exceptionHandlers.get(current).entryBlock(), null);
378 current--; 387 current--;
379 } else { 388 } else {
380 if (unwindBlock == null) { 389 if (unwindBlock == null) {
381 unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); 390 unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), false, graph);
382 Unwind unwind = new Unwind(null, graph); 391 Unwind unwind = new Unwind(null, graph);
383 unwindBlock.appendNext(unwind); 392 unwindBlock.appendNext(unwind);
384 } 393 }
385 successor = unwindBlock; 394 successor = unwindBlock;
386 } 395 }
399 } 408 }
400 } 409 }
401 if (newSucc != null) { 410 if (newSucc != null) {
402 successor = newSucc; 411 successor = newSucc;
403 } else { 412 } else {
404 BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); 413 BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), false, graph);
405 414
406 if (handler.handler.catchType().isResolved()) { 415 if (handler.handler.catchType().isResolved()) {
407 Instruction entry = createTarget(handler.entryBlock(), null); 416 Instruction entry = createTarget(handler.entryBlock(), null);
408 ExceptionDispatch end = new ExceptionDispatch(null, entry, null, handler, null, graph); 417 ExceptionDispatch end = new ExceptionDispatch(null, entry, null, handler, null, graph);
409 end.setBlockSuccessor(0, successor); 418 end.setBlockSuccessor(0, successor);
420 } 429 }
421 } 430 }
422 431
423 FrameState entryState = frameState.duplicateWithEmptyStack(bci); 432 FrameState entryState = frameState.duplicateWithEmptyStack(bci);
424 433
425 BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), graph); 434 BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), false, graph);
426 entry.setStateBefore(entryState); 435 entry.setStateBefore(entryState);
427 ExceptionObject exception = new ExceptionObject(graph); 436 ExceptionObject exception = new ExceptionObject(graph);
428 entry.appendNext(exception); 437 entry.appendNext(exception);
429 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); 438 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception);
430 BlockEnd end = new Goto(successor, stateWithException, graph); 439 BlockEnd end = new Goto(successor, stateWithException, graph);
670 private void genGoto(int fromBCI, int toBCI) { 679 private void genGoto(int fromBCI, int toBCI) {
671 append(new Goto(createTargetAt(toBCI, frameState), null, graph)); 680 append(new Goto(createTargetAt(toBCI, frameState), null, graph));
672 } 681 }
673 682
674 private void ifNode(Value x, Condition cond, Value y) { 683 private void ifNode(Value x, Condition cond, Value y) {
684 assert !x.isDeleted() && !y.isDeleted();
685 If ifNode = new If(x, cond, y, null, graph);
686 append(ifNode);
675 Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState); 687 Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState);
676 Instruction fsucc = createTargetAt(stream().nextBCI(), frameState); 688 Instruction fsucc = createTargetAt(stream().nextBCI(), frameState);
677 append(new If(x, cond, y, tsucc, fsucc, null, graph)); 689 ifNode.setBlockSuccessor(0, tsucc);
690 ifNode.setBlockSuccessor(1, fsucc);
678 } 691 }
679 692
680 private void genIfZero(Condition cond) { 693 private void genIfZero(Condition cond) {
681 Value y = appendConstant(CiConstant.INT_0); 694 Value y = appendConstant(CiConstant.INT_0);
682 Value x = frameState.ipop(); 695 Value x = frameState.ipop();
690 } 703 }
691 704
692 private void genIfSame(CiKind kind, Condition cond) { 705 private void genIfSame(CiKind kind, Condition cond) {
693 Value y = frameState.pop(kind); 706 Value y = frameState.pop(kind);
694 Value x = frameState.pop(kind); 707 Value x = frameState.pop(kind);
708 assert !x.isDeleted() && !y.isDeleted();
695 ifNode(x, cond, y); 709 ifNode(x, cond, y);
696 } 710 }
697 711
698 private void genThrow(int bci) { 712 private void genThrow(int bci) {
699 FrameState stateBefore = frameState.create(bci); 713 FrameState stateBefore = frameState.create(bci);
1120 return createTarget(blockList[bci], stateAfter); 1134 return createTarget(blockList[bci], stateAfter);
1121 } 1135 }
1122 1136
1123 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { 1137 private Instruction createTarget(Block block, FrameStateAccess stateAfter) {
1124 if (block.firstInstruction == null) { 1138 if (block.firstInstruction == null) {
1125 BlockBegin blockBegin = new BlockBegin(block.startBci, block.blockID, graph); 1139 BlockBegin blockBegin = new BlockBegin(block.startBci, block.blockID, block.isLoopHeader, graph);
1126 block.firstInstruction = blockBegin; 1140 block.firstInstruction = blockBegin;
1127 } 1141 }
1128 if (stateAfter != null) { 1142 if (stateAfter != null) {
1129 mergeOrClone(block, stateAfter); 1143 mergeOrClone(block, stateAfter);
1130 } 1144 }