# HG changeset patch # User Thomas Wuerthinger # Date 1306171313 -7200 # Node ID 43ffa0e47a463fabe24d8fdaa7716f289e19cc0a # Parent cc2b98e2b832e0bfba3fdec6204d469e5fe276af Towards removing stateAfter on BlockEnd. diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Mon May 23 19:21:53 2011 +0200 @@ -29,6 +29,7 @@ import java.util.*; +import com.oracle.graal.graph.*; import com.oracle.max.asm.*; import com.sun.c1x.*; import com.sun.c1x.alloc.*; @@ -1263,6 +1264,22 @@ this.moveToPhi(lastState); } + private List getPhis(LIRBlock block) { + if (block.getInstructions().size() > 0) { + Instruction i = block.getInstructions().get(0); + if (i instanceof BlockBegin) { + List result = new ArrayList(); + for (Node n : i.usages()) { + if (n instanceof Phi) { + result.add((Phi) n); + } + } + return result; + } + } + return null; + } + protected void moveToPhi(FrameState curState) { // Moves all stack values into their phi position LIRBlock bb = currentBlock; @@ -1272,9 +1289,46 @@ // a block with only one predecessor never has phi functions if (sux.numberOfPreds() > 1) { - PhiResolver resolver = new PhiResolver(this); + FrameState suxState = sux.stateBefore(); + + + List phis = getPhis(sux); + if (phis != null) { + int predIndex = 0; + for (; predIndex < sux.numberOfPreds(); ++predIndex) { + if (sux.predAt(predIndex) == bb) { + break; + } + } + assert predIndex < sux.numberOfPreds(); + +// TTY.println("predIndex=" + predIndex + ", bb" + bb.blockID() + ", sux=" + sux.blockID()); +// for (int i = 0; i < sux.numberOfPreds(); ++i) { +// TTY.println("pred[" + i + "]=" + sux.predAt(i).blockID()); +// } - FrameState suxState = sux.stateBefore(); + PhiResolver resolver = new PhiResolver(this); + for (Phi phi : phis) { + if (!phi.isDeadPhi() && phi.valueCount() > predIndex) { + Value curVal = phi.valueAt(predIndex); + if (curVal != null) { + if (curVal instanceof Phi) { + operandForPhi((Phi) curVal); + } + CiValue operand = curVal.operand(); + if (operand.isIllegal()) { + // phi.print(TTY.out()); + assert curVal instanceof Constant || curVal instanceof Local : "these can be produced lazily" + curVal + "/" + phi; + operand = operandForInstruction(curVal); + } + resolver.move(operand, operandForPhi(phi)); + } + } + } + resolver.dispose(); + } + +/* PhiResolver resolver = new PhiResolver(this); for (int index = 0; index < suxState.stackSize(); index++) { moveToPhi(resolver, curState.stackAt(index), suxState.stackAt(index)); @@ -1283,7 +1337,7 @@ for (int index = 0; index < suxState.localsSize(); index++) { moveToPhi(resolver, curState.localAt(index), suxState.localAt(index)); } - resolver.dispose(); + resolver.dispose();*/ } } } diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Mon May 23 19:21:53 2011 +0200 @@ -162,7 +162,7 @@ // 1. create the start block Block startBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); - BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, graph); + BlockBegin startBlockBegin = new BlockBegin(0, startBlock.blockID, false, graph); startBlock.firstInstruction = startBlockBegin; graph.start().setStart(startBlockBegin); @@ -199,7 +199,7 @@ // 4A.3 setup an exception handler to unlock the root method synchronized object syncBlock = nextBlock(Instruction.SYNCHRONIZATION_ENTRY_BCI); - syncHandler = new BlockBegin(Instruction.SYNCHRONIZATION_ENTRY_BCI, syncBlock.blockID, graph); + syncHandler = new BlockBegin(Instruction.SYNCHRONIZATION_ENTRY_BCI, syncBlock.blockID, false, graph); syncBlock.firstInstruction = syncHandler; markOnWorkList(syncBlock); @@ -302,6 +302,15 @@ } else { assert false; } + + + + + for (int j = 0; j < frameState.localsSize() + frameState.stackSize(); ++j) { + if (frameState.valueAt(j) != null) { + assert !frameState.valueAt(j).isDeleted(); + } + } } private void insertLoopPhis(BlockBegin merge, FrameState newState) { @@ -378,7 +387,7 @@ current--; } else { if (unwindBlock == null) { - unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), graph); + unwindBlock = new BlockBegin(bci, ir.nextBlockNumber(), false, graph); Unwind unwind = new Unwind(null, graph); unwindBlock.appendNext(unwind); } @@ -401,7 +410,7 @@ if (newSucc != null) { successor = newSucc; } else { - BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), graph); + BlockBegin dispatchEntry = new BlockBegin(handler.handlerBCI(), ir.nextBlockNumber(), false, graph); if (handler.handler.catchType().isResolved()) { Instruction entry = createTarget(handler.entryBlock(), null); @@ -422,7 +431,7 @@ FrameState entryState = frameState.duplicateWithEmptyStack(bci); - BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), graph); + BlockBegin entry = new BlockBegin(bci, ir.nextBlockNumber(), false, graph); entry.setStateBefore(entryState); ExceptionObject exception = new ExceptionObject(graph); entry.appendNext(exception); @@ -672,9 +681,13 @@ } private void ifNode(Value x, Condition cond, Value y) { + assert !x.isDeleted() && !y.isDeleted(); + If ifNode = new If(x, cond, y, null, graph); + append(ifNode); Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState); Instruction fsucc = createTargetAt(stream().nextBCI(), frameState); - append(new If(x, cond, y, tsucc, fsucc, null, graph)); + ifNode.setBlockSuccessor(0, tsucc); + ifNode.setBlockSuccessor(1, fsucc); } private void genIfZero(Condition cond) { @@ -692,6 +705,7 @@ private void genIfSame(CiKind kind, Condition cond) { Value y = frameState.pop(kind); Value x = frameState.pop(kind); + assert !x.isDeleted() && !y.isDeleted(); ifNode(x, cond, y); } @@ -1122,7 +1136,7 @@ private Instruction createTarget(Block block, FrameStateAccess stateAfter) { if (block.firstInstruction == null) { - BlockBegin blockBegin = new BlockBegin(block.startBci, block.blockID, graph); + BlockBegin blockBegin = new BlockBegin(block.startBci, block.blockID, block.isLoopHeader, graph); block.firstInstruction = blockBegin; } if (stateAfter != null) { diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Mon May 23 19:21:53 2011 +0200 @@ -142,6 +142,7 @@ int z = 0; for (BlockBegin bb : blocks) { LIRBlock lirBlock = new LIRBlock(z); + lirBlock.getInstructions().add(bb); valueToBlock.put(bb, lirBlock); lirBlock.setLinearScanNumber(bb.linearScanNumber()); // TODO(tw): Initialize LIRBlock.linearScanLoopHeader and LIRBlock.linearScanLoopEnd @@ -221,7 +222,7 @@ int backEdgeIndex = target.predecessors().indexOf(source.end()); // create new successor and mark it for special block order treatment - BlockBegin newSucc = new BlockBegin(bci, nextBlockNumber(), compilation.graph); + BlockBegin newSucc = new BlockBegin(bci, nextBlockNumber(), false, compilation.graph); // This goto is not a safepoint. Goto e = new Goto(target, null, compilation.graph); diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Mon May 23 19:21:53 2011 +0200 @@ -73,6 +73,7 @@ */ public final int blockID; + public final boolean isLoopHeader; private int linearScanNumber; /** @@ -87,11 +88,12 @@ * @param blockID the ID of the block * @param graph */ - public BlockBegin(int bci, int blockID, Graph graph) { + public BlockBegin(int bci, int blockID, boolean isLoopHeader, Graph graph) { super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); this.blockID = blockID; linearScanNumber = -1; this.bci = bci; + this.isLoopHeader = isLoopHeader; } /** diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/ir/If.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/If.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/If.java Mon May 23 19:21:53 2011 +0200 @@ -80,19 +80,15 @@ * @param x the instruction producing the first input to the instruction * @param cond the condition (comparison operation) * @param y the instruction that produces the second input to this instruction - * @param trueSucc the block representing the true successor - * @param falseSucc the block representing the false successor * @param stateAfter the state before the branch but after the input values have been popped * @param graph */ - public If(Value x, Condition cond, Value y, Instruction trueSucc, Instruction falseSucc, FrameState stateAfter, Graph graph) { + public If(Value x, Condition cond, Value y, FrameState stateAfter, Graph graph) { super(CiKind.Illegal, stateAfter, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); assert Util.archKindsEqual(x, y); condition = cond; setX(x); setY(y); - setBlockSuccessor(0, trueSucc); - setBlockSuccessor(1, falseSucc); } /** diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Mon May 23 19:21:53 2011 +0200 @@ -26,6 +26,7 @@ import com.sun.c1x.debug.*; import com.sun.c1x.value.*; import com.sun.cri.ci.*; +import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*; /** * The {@code Phi} instruction represents the merging of dataflow @@ -33,7 +34,7 @@ */ public final class Phi extends Value { - private static final int DEFAULT_MAX_VALUES = 2; + private static final int DEFAULT_MAX_VALUES = 20; private static final int INPUT_COUNT = 1; private static final int INPUT_BLOCK = 0; @@ -109,7 +110,14 @@ @Override public void print(LogStream out) { - out.print("phi function"); + out.print("phi function ("); + for (int i = 0; i < inputs().size(); ++i) { + if (i != 0) { + out.print(' '); + } + out.print((Value) inputs().get(i)); + } + out.print(')'); } @Override diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/lir/LIRBlock.java --- a/graal/GraalCompiler/src/com/sun/c1x/lir/LIRBlock.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/lir/LIRBlock.java Mon May 23 19:21:53 2011 +0200 @@ -41,8 +41,9 @@ private LIRList lir; private final int blockID; private List instructions = new ArrayList(4); - private List predecessors = new ArrayList(); - private List successors = new ArrayList(); + private List predecessors = new ArrayList(4); + private List successors = new ArrayList(4); + private List phis = new ArrayList(4); /** * Bit map specifying which {@linkplain OperandPool operands} are live upon entry to this block. diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/util/Util.java --- a/graal/GraalCompiler/src/com/sun/c1x/util/Util.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/util/Util.java Mon May 23 19:21:53 2011 +0200 @@ -422,6 +422,6 @@ * @return the instruction representation as a string */ public static String valueString(Value value) { - return value == null ? "-" : "" + value.kind.typeChar + value.id(); + return (value == null) ? "-" : ("" + value.kind.typeChar + value.id()); } } diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Mon May 23 19:21:53 2011 +0200 @@ -331,7 +331,7 @@ Value x = valueAt(i); if (x != null) { Value y = other.valueAt(i); - if (x != y) { + if (x != y || ((x instanceof Phi) && ((Phi) x).block() == block)) { if (typeMismatch(x, y)) { if (x instanceof Phi) { Phi phi = (Phi) x; @@ -360,18 +360,20 @@ for (int j = 0; j < size; ++j) { phi = phi.addInput(x); } - phi = phi.addInput(y); + phi = phi.addInput((x == y) ? phi : y); } else { - phi = phi.addInput(y); + phi = phi.addInput((x == y) ? phi : y); } - if (originalPhi != phi) { + /*if (originalPhi != phi) { for (int j = 0; j < other.localsSize() + other.stackSize(); ++j) { if (other.valueAt(j) == originalPhi) { other.setValueAt(j, phi); } } - } - } + }*/ + + //assert phi.valueCount() == block.predecessors().size() + (blockAppended ? 0 : 1) : "valueCount=" + phi.valueCount() + " predSize= " + block.predecessors().size(); + } } } } diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java Mon May 23 19:21:53 2011 +0200 @@ -118,6 +118,7 @@ * @param x the instruction to push onto the stack */ public void xpush(Value x) { + assert x == null || !x.isDeleted(); stack[stackIndex++] = x; } @@ -204,7 +205,9 @@ * @return x the instruction popped off the stack */ public Value xpop() { - return stack[--stackIndex]; + Value result = stack[--stackIndex]; + assert result == null || !result.isDeleted(); + return result; } /** diff -r cc2b98e2b832 -r 43ffa0e47a46 graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java Mon May 23 16:23:28 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java Mon May 23 19:21:53 2011 +0200 @@ -46,7 +46,7 @@ public Node set(int index, Node node) { assert node == Node.Null || node.graph == self().graph; - assert node == Node.Null || node.id() != Node.DeletedID; + assert node == Node.Null || node.id() != Node.DeletedID : "inserted node must not be deleted"; Node old = nodes[index]; if (old != node) {