# HG changeset patch # User Thomas Wuerthinger # Date 1306326824 -7200 # Node ID df4c5254c5ccd9d6ac0460b833dd989327947aec # Parent 847dcd4dbd4c3fb63364d3535b8cb35b14c9a4a9 Towards goto removal. diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Wed May 25 14:33:44 2011 +0200 @@ -253,6 +253,10 @@ } } } + if (block.blockSuccessors().size() == 1 && !(block.getInstructions().get(block.getInstructions().size() - 1) instanceof BlockEnd)) { + moveToPhi(); + block.lir().jump(block.blockSuccessors().get(0)); + } if (C1XOptions.TraceLIRGeneratorLevel >= 1) { TTY.println("END Generating LIR for block B" + block.blockID()); diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java Wed May 25 14:33:44 2011 +0200 @@ -108,7 +108,10 @@ newSucc.getInstructions().add(e); // link predecessor to new block - ((BlockEnd) source.getInstructions().get(source.getInstructions().size() - 1)).successors().replace(target.getInstructions().get(0), newSucc.getInstructions().get(0)); +// if (source.getInstructions().size() > 0) { + source.getInstructions().get(source.getInstructions().size() - 1).successors().replace(target.getInstructions().get(0), newSucc.getInstructions().get(0)); +// } + source.substituteSuccessor(target, newSucc); target.substitutePredecessor(source, newSucc); diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Wed May 25 14:33:44 2011 +0200 @@ -290,8 +290,7 @@ private void finishStartBlock(Block startBlock) { assert bci() == 0; Instruction target = createTargetAt(0, frameState); - Goto base = new Goto(target, graph); - appendWithBCI(base); + appendGoto(target); } public void mergeOrClone(Block target, FrameStateAccess newState) { @@ -319,6 +318,8 @@ } else { if (!C1XOptions.AssumeVerifiedBytecode && !existingState.isCompatibleWith(newState)) { // stacks or locks do not match--bytecodes would not verify + TTY.println(existingState.toString()); + TTY.println(newState.duplicate(0).toString()); throw new CiBailout("stack or locks do not match"); } assert existingState.localsSize() == newState.localsSize(); @@ -427,6 +428,7 @@ FrameState stateWithException = entryState.duplicateModified(bci, CiKind.Void, exception); Instruction successor = createTarget(dispatchBlock, stateWithException); + //exception.appendNext(successor); BlockEnd end = new Goto(successor, graph); exception.appendNext(end); @@ -610,7 +612,7 @@ } private void genGoto(int fromBCI, int toBCI) { - append(new Goto(createTargetAt(toBCI, frameState), graph)); + appendGoto(createTargetAt(toBCI, frameState)); } private void ifNode(Value x, Condition cond, Value y) { @@ -1065,6 +1067,10 @@ assert block != null && stateAfter != null; assert block.isLoopHeader || block.firstInstruction == null || block.firstInstruction.next() == null : "non-loop block must be iterated after all its predecessors"; + if (block.isExceptionEntry) { + assert stateAfter.stackSize() == 1; + } + if (block.firstInstruction == null) { if (block.isLoopHeader) { block.firstInstruction = new BlockBegin(block.startBci, block.blockID, block.isLoopHeader, graph); @@ -1165,17 +1171,26 @@ deopt.setMessage("unresolved " + block.handler.catchType().name()); append(deopt); Instruction nextDispatch = createTarget(block.next, frameState); - append(new Goto(nextDispatch, graph)); + appendGoto(nextDispatch); } } } + private void appendGoto(Instruction target) { + //lastInstr.appendNext(target); + append(new Goto(target, graph)); + } + + private void appendGoto2(Instruction target) { + lastInstr.appendNext(target); + //append(new Goto(target, graph)); + } + private void iterateBytecodesForBlock(Block block) { assert frameState != null; stream.setBCI(block.startBci); - BlockEnd end = null; int endBCI = stream.endBCI(); boolean blockStart = true; @@ -1183,10 +1198,10 @@ while (bci < endBCI) { Block nextBlock = blockFromBci[bci]; if (nextBlock != null && nextBlock != block) { + assert !nextBlock.isExceptionEntry; // we fell through to the next block, add a goto and break Instruction next = createTarget(nextBlock, frameState); - end = new Goto(next, graph); - lastInstr = lastInstr.appendNext(end); + appendGoto(next); break; } // read the opcode @@ -1196,10 +1211,10 @@ traceInstruction(bci, opcode, blockStart); processBytecode(bci, opcode); - if (lastInstr instanceof BlockEnd) { - end = (BlockEnd) lastInstr; + if (lastInstr instanceof BlockEnd || lastInstr.next() != null) { break; } + stream.next(); bci = stream.currentBCI(); if (lastInstr instanceof StateSplit) { diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Wed May 25 14:33:44 2011 +0200 @@ -124,7 +124,13 @@ } startBlock = valueToBlock.get(getHIRStartBlock()); assert startBlock != null; - verifyAndPrint("After linear scan order"); + + if (startBlock.blockPredecessors().size() > 0) { + LIRBlock oldStartBlock = startBlock; + startBlock = new LIRBlock(orderedBlocks.size()); + startBlock.blockSuccessors().add(oldStartBlock); + orderedBlocks.add(startBlock); + } ComputeLinearScanOrder clso = new ComputeLinearScanOrder(lirBlocks.size(), startBlock); orderedBlocks = clso.linearScanOrder(); @@ -135,7 +141,7 @@ b.setLinearScanNumber(z++); } - + verifyAndPrint("After linear scan order"); if (C1XOptions.PrintTimers) { C1XTimers.HIR_OPTIMIZE.stop(); diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Wed May 25 14:33:44 2011 +0200 @@ -174,12 +174,12 @@ if (end() != null) { builder.append(" -> "); boolean hasSucc = false; - for (BlockBegin s : end().blockSuccessors()) { + for (Instruction s : end().blockSuccessors()) { if (hasSucc) { builder.append(", "); } builder.append("#"); - builder.append(s.blockID); + builder.append(s.id()); hasSucc = true; } } diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Wed May 25 14:33:44 2011 +0200 @@ -35,8 +35,7 @@ private static final int INPUT_COUNT = 0; - private static final int SUCCESSOR_COUNT = 1; - private static final int SUCCESSOR_STATE_AFTER = 0; + private static final int SUCCESSOR_COUNT = 0; private final int blockSuccessorCount; @Override diff -r 847dcd4dbd4c -r df4c5254c5cc graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java Wed May 25 12:20:08 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ComputeLinearScanOrder.java Wed May 25 14:33:44 2011 +0200 @@ -461,9 +461,9 @@ // the start block is always the first block in the linear scan order linearScanOrder = new ArrayList(numBlocks); - appendBlock(startBlock); +// appendBlock(startBlock); - LIRBlock stdEntry = startBlock.suxAt(0); + LIRBlock stdEntry = startBlock; //.suxAt(0); // start processing with standard entry block assert workList.isEmpty() : "list must be empty before processing";