Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2788:df4c5254c5cc
Towards goto removal.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 25 May 2011 14:33:44 +0200 |
parents | 847dcd4dbd4c |
children | aeccd2af4e9e |
comparison
equal
deleted
inserted
replaced
2785:847dcd4dbd4c | 2788:df4c5254c5cc |
---|---|
288 } | 288 } |
289 | 289 |
290 private void finishStartBlock(Block startBlock) { | 290 private void finishStartBlock(Block startBlock) { |
291 assert bci() == 0; | 291 assert bci() == 0; |
292 Instruction target = createTargetAt(0, frameState); | 292 Instruction target = createTargetAt(0, frameState); |
293 Goto base = new Goto(target, graph); | 293 appendGoto(target); |
294 appendWithBCI(base); | |
295 } | 294 } |
296 | 295 |
297 public void mergeOrClone(Block target, FrameStateAccess newState) { | 296 public void mergeOrClone(Block target, FrameStateAccess newState) { |
298 Instruction first = target.firstInstruction; | 297 Instruction first = target.firstInstruction; |
299 assert first instanceof StateSplit; | 298 assert first instanceof StateSplit; |
317 ((StateSplit) first).setStateBefore(duplicate); | 316 ((StateSplit) first).setStateBefore(duplicate); |
318 } | 317 } |
319 } else { | 318 } else { |
320 if (!C1XOptions.AssumeVerifiedBytecode && !existingState.isCompatibleWith(newState)) { | 319 if (!C1XOptions.AssumeVerifiedBytecode && !existingState.isCompatibleWith(newState)) { |
321 // stacks or locks do not match--bytecodes would not verify | 320 // stacks or locks do not match--bytecodes would not verify |
321 TTY.println(existingState.toString()); | |
322 TTY.println(newState.duplicate(0).toString()); | |
322 throw new CiBailout("stack or locks do not match"); | 323 throw new CiBailout("stack or locks do not match"); |
323 } | 324 } |
324 assert existingState.localsSize() == newState.localsSize(); | 325 assert existingState.localsSize() == newState.localsSize(); |
325 assert existingState.stackSize() == newState.stackSize(); | 326 assert existingState.stackSize() == newState.stackSize(); |
326 | 327 |
425 ExceptionObject exception = new ExceptionObject(graph); | 426 ExceptionObject exception = new ExceptionObject(graph); |
426 entry.appendNext(exception); | 427 entry.appendNext(exception); |
427 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); | 428 FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); |
428 | 429 |
429 Instruction successor = createTarget(dispatchBlock, stateWithException); | 430 Instruction successor = createTarget(dispatchBlock, stateWithException); |
431 //exception.appendNext(successor); | |
430 BlockEnd end = new Goto(successor, graph); | 432 BlockEnd end = new Goto(successor, graph); |
431 exception.appendNext(end); | 433 exception.appendNext(end); |
432 | 434 |
433 if (x instanceof Invoke) { | 435 if (x instanceof Invoke) { |
434 ((Invoke) x).setExceptionEdge(entry); | 436 ((Invoke) x).setExceptionEdge(entry); |
608 Value y = append(Constant.forInt(delta, graph)); | 610 Value y = append(Constant.forInt(delta, graph)); |
609 frameState.storeLocal(index, append(new ArithmeticOp(IADD, CiKind.Int, x, y, isStrict(method().accessFlags()), false, graph))); | 611 frameState.storeLocal(index, append(new ArithmeticOp(IADD, CiKind.Int, x, y, isStrict(method().accessFlags()), false, graph))); |
610 } | 612 } |
611 | 613 |
612 private void genGoto(int fromBCI, int toBCI) { | 614 private void genGoto(int fromBCI, int toBCI) { |
613 append(new Goto(createTargetAt(toBCI, frameState), graph)); | 615 appendGoto(createTargetAt(toBCI, frameState)); |
614 } | 616 } |
615 | 617 |
616 private void ifNode(Value x, Condition cond, Value y) { | 618 private void ifNode(Value x, Condition cond, Value y) { |
617 assert !x.isDeleted() && !y.isDeleted(); | 619 assert !x.isDeleted() && !y.isDeleted(); |
618 If ifNode = new If(x, cond, y, graph); | 620 If ifNode = new If(x, cond, y, graph); |
1063 | 1065 |
1064 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { | 1066 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { |
1065 assert block != null && stateAfter != null; | 1067 assert block != null && stateAfter != null; |
1066 assert block.isLoopHeader || block.firstInstruction == null || block.firstInstruction.next() == null : "non-loop block must be iterated after all its predecessors"; | 1068 assert block.isLoopHeader || block.firstInstruction == null || block.firstInstruction.next() == null : "non-loop block must be iterated after all its predecessors"; |
1067 | 1069 |
1070 if (block.isExceptionEntry) { | |
1071 assert stateAfter.stackSize() == 1; | |
1072 } | |
1073 | |
1068 if (block.firstInstruction == null) { | 1074 if (block.firstInstruction == null) { |
1069 if (block.isLoopHeader) { | 1075 if (block.isLoopHeader) { |
1070 block.firstInstruction = new BlockBegin(block.startBci, block.blockID, block.isLoopHeader, graph); | 1076 block.firstInstruction = new BlockBegin(block.startBci, block.blockID, block.isLoopHeader, graph); |
1071 } else { | 1077 } else { |
1072 block.firstInstruction = new Placeholder(graph); | 1078 block.firstInstruction = new Placeholder(graph); |
1163 } else { | 1169 } else { |
1164 Deoptimize deopt = new Deoptimize(graph); | 1170 Deoptimize deopt = new Deoptimize(graph); |
1165 deopt.setMessage("unresolved " + block.handler.catchType().name()); | 1171 deopt.setMessage("unresolved " + block.handler.catchType().name()); |
1166 append(deopt); | 1172 append(deopt); |
1167 Instruction nextDispatch = createTarget(block.next, frameState); | 1173 Instruction nextDispatch = createTarget(block.next, frameState); |
1168 append(new Goto(nextDispatch, graph)); | 1174 appendGoto(nextDispatch); |
1169 } | 1175 } |
1170 } | 1176 } |
1177 } | |
1178 | |
1179 private void appendGoto(Instruction target) { | |
1180 //lastInstr.appendNext(target); | |
1181 append(new Goto(target, graph)); | |
1182 } | |
1183 | |
1184 private void appendGoto2(Instruction target) { | |
1185 lastInstr.appendNext(target); | |
1186 //append(new Goto(target, graph)); | |
1171 } | 1187 } |
1172 | 1188 |
1173 private void iterateBytecodesForBlock(Block block) { | 1189 private void iterateBytecodesForBlock(Block block) { |
1174 assert frameState != null; | 1190 assert frameState != null; |
1175 | 1191 |
1176 stream.setBCI(block.startBci); | 1192 stream.setBCI(block.startBci); |
1177 | 1193 |
1178 BlockEnd end = null; | |
1179 int endBCI = stream.endBCI(); | 1194 int endBCI = stream.endBCI(); |
1180 boolean blockStart = true; | 1195 boolean blockStart = true; |
1181 | 1196 |
1182 int bci = block.startBci; | 1197 int bci = block.startBci; |
1183 while (bci < endBCI) { | 1198 while (bci < endBCI) { |
1184 Block nextBlock = blockFromBci[bci]; | 1199 Block nextBlock = blockFromBci[bci]; |
1185 if (nextBlock != null && nextBlock != block) { | 1200 if (nextBlock != null && nextBlock != block) { |
1201 assert !nextBlock.isExceptionEntry; | |
1186 // we fell through to the next block, add a goto and break | 1202 // we fell through to the next block, add a goto and break |
1187 Instruction next = createTarget(nextBlock, frameState); | 1203 Instruction next = createTarget(nextBlock, frameState); |
1188 end = new Goto(next, graph); | 1204 appendGoto(next); |
1189 lastInstr = lastInstr.appendNext(end); | |
1190 break; | 1205 break; |
1191 } | 1206 } |
1192 // read the opcode | 1207 // read the opcode |
1193 int opcode = stream.currentBC(); | 1208 int opcode = stream.currentBC(); |
1194 | 1209 |
1195 traceState(); | 1210 traceState(); |
1196 traceInstruction(bci, opcode, blockStart); | 1211 traceInstruction(bci, opcode, blockStart); |
1197 processBytecode(bci, opcode); | 1212 processBytecode(bci, opcode); |
1198 | 1213 |
1199 if (lastInstr instanceof BlockEnd) { | 1214 if (lastInstr instanceof BlockEnd || lastInstr.next() != null) { |
1200 end = (BlockEnd) lastInstr; | |
1201 break; | 1215 break; |
1202 } | 1216 } |
1217 | |
1203 stream.next(); | 1218 stream.next(); |
1204 bci = stream.currentBCI(); | 1219 bci = stream.currentBCI(); |
1205 if (lastInstr instanceof StateSplit) { | 1220 if (lastInstr instanceof StateSplit) { |
1206 StateSplit stateSplit = (StateSplit) lastInstr; | 1221 StateSplit stateSplit = (StateSplit) lastInstr; |
1207 if (stateSplit.stateAfter() == null && stateSplit.needsStateAfter()) { | 1222 if (stateSplit.stateAfter() == null && stateSplit.needsStateAfter()) { |