# HG changeset patch # User Thomas Wuerthinger # Date 1306178507 -7200 # Node ID dd6419f4bfe27b7d621c12a1b53675d530361070 # Parent 43ffa0e47a463fabe24d8fdaa7716f289e19cc0a Fixed several issues with incorrect predecessor count/order. One known issue around exception dispatch remaining in fop. diff -r 43ffa0e47a46 -r dd6419f4bfe2 graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Mon May 23 19:21:53 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Mon May 23 21:21:47 2011 +0200 @@ -1239,12 +1239,20 @@ } } - void moveToPhi(PhiResolver resolver, Value curVal, Value suxVal) { + void moveToPhi(PhiResolver resolver, Value curVal, Value suxVal, List phis, int predIndex) { // move current value to referenced phi function if (suxVal instanceof Phi) { Phi phi = (Phi) suxVal; + // curVal can be null without phi being null in conjunction with inlining if (!phi.isDeadPhi() && curVal != null && curVal != phi) { + + assert phis.contains(phi); + if (phi.valueAt(predIndex) != curVal) { + phi.print(TTY.out()); + } + assert phi.valueAt(predIndex) == curVal : "curVal=" + curVal + "valueAt(" + predIndex + ")=" + phi.valueAt(predIndex); + assert !phi.isIllegal() : "illegal phi cannot be marked as live"; if (curVal instanceof Phi) { operandForPhi((Phi) curVal); @@ -1293,31 +1301,26 @@ List phis = getPhis(sux); - if (phis != null) { - int predIndex = 0; - for (; predIndex < sux.numberOfPreds(); ++predIndex) { - if (sux.predAt(predIndex) == bb) { - break; - } + + int predIndex = 0; + for (; predIndex < sux.numberOfPreds(); ++predIndex) { + if (sux.predAt(predIndex) == bb) { + break; } - assert predIndex < sux.numberOfPreds(); + } + 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()); -// } - + if (phis != null) { 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 != null && curVal != phi) { 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); } @@ -1328,14 +1331,17 @@ resolver.dispose(); } -/* PhiResolver resolver = new PhiResolver(this); + /*TTY.println("number of preds: " + sux.numberOfPreds()); + + PhiResolver resolver = new PhiResolver(this); + for (int index = 0; index < suxState.stackSize(); index++) { - moveToPhi(resolver, curState.stackAt(index), suxState.stackAt(index)); + moveToPhi(resolver, curState.stackAt(index), suxState.stackAt(index), phis, predIndex); } for (int index = 0; index < suxState.localsSize(); index++) { - moveToPhi(resolver, curState.localAt(index), suxState.localAt(index)); + moveToPhi(resolver, curState.localAt(index), suxState.localAt(index), phis, predIndex); } resolver.dispose();*/ } diff -r 43ffa0e47a46 -r dd6419f4bfe2 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Mon May 23 19:21:53 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Mon May 23 21:21:47 2011 +0200 @@ -685,8 +685,8 @@ If ifNode = new If(x, cond, y, null, graph); append(ifNode); Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState); + ifNode.setBlockSuccessor(0, tsucc); Instruction fsucc = createTargetAt(stream().nextBCI(), frameState); - ifNode.setBlockSuccessor(0, tsucc); ifNode.setBlockSuccessor(1, fsucc); } @@ -1056,19 +1056,21 @@ BytecodeTableSwitch ts = new BytecodeTableSwitch(stream(), bci); int max = ts.numberOfCases(); List list = new ArrayList(max + 1); - boolean isBackwards = false; + List offsetList = new ArrayList(max + 1); for (int i = 0; i < max; i++) { // add all successors to the successor list int offset = ts.offsetAt(i); - list.add(createTargetAt(bci + offset, frameState)); - isBackwards |= offset < 0; // track if any of the successors are backwards + list.add(null); + offsetList.add(offset); } int offset = ts.defaultOffset(); - isBackwards |= offset < 0; // if the default successor is backwards - list.add(createTargetAt(bci + offset, frameState)); - boolean isSafepoint = isBackwards && !noSafepoints(); - FrameState stateAfter = isSafepoint ? frameState.create(bci()) : null; - append(new TableSwitch(value, list, ts.lowKey(), stateAfter, graph)); + list.add(null); + offsetList.add(offset); + TableSwitch tableSwitch = new TableSwitch(value, list, ts.lowKey(), null, graph); + for (int i = 0; i < offsetList.size(); ++i) { + tableSwitch.setBlockSuccessor(i, createTargetAt(bci + offsetList.get(i), frameState)); + } + append(tableSwitch); } private void genLookupswitch() { @@ -1077,21 +1079,23 @@ BytecodeLookupSwitch ls = new BytecodeLookupSwitch(stream(), bci); int max = ls.numberOfCases(); List list = new ArrayList(max + 1); + List offsetList = new ArrayList(max + 1); int[] keys = new int[max]; - boolean isBackwards = false; for (int i = 0; i < max; i++) { // add all successors to the successor list int offset = ls.offsetAt(i); - list.add(createTargetAt(bci + offset, frameState)); + list.add(null); + offsetList.add(offset); keys[i] = ls.keyAt(i); - isBackwards |= offset < 0; // track if any of the successors are backwards } int offset = ls.defaultOffset(); - isBackwards |= offset < 0; // if the default successor is backwards - list.add(createTargetAt(bci + offset, frameState)); - boolean isSafepoint = isBackwards && !noSafepoints(); - FrameState stateAfter = isSafepoint ? frameState.create(bci()) : null; - append(new LookupSwitch(value, list, keys, stateAfter, graph)); + list.add(null); + offsetList.add(offset); + LookupSwitch lookupSwitch = new LookupSwitch(value, list, keys, null, graph); + for (int i = 0; i < offsetList.size(); ++i) { + lookupSwitch.setBlockSuccessor(i, createTargetAt(bci + offsetList.get(i), frameState)); + } + append(lookupSwitch); } private Value appendConstant(CiConstant constant) { diff -r 43ffa0e47a46 -r dd6419f4bfe2 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Mon May 23 19:21:53 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Mon May 23 21:21:47 2011 +0200 @@ -224,10 +224,18 @@ // create new successor and mark it for special block order treatment BlockBegin newSucc = new BlockBegin(bci, nextBlockNumber(), false, compilation.graph); + List removePhiInputs = new ArrayList(); + for (int i = backEdgeIndex + 1; i < target.predecessors().size(); ++i) { + if (target.predecessors().get(i) == source.end()) { + removePhiInputs.add(i); + } + } + // This goto is not a safepoint. Goto e = new Goto(target, null, compilation.graph); newSucc.appendNext(e); e.reorderSuccessor(0, backEdgeIndex); + // setup states FrameState s = source.end().stateAfter(); newSucc.setStateBefore(s); @@ -237,6 +245,20 @@ assert newSucc.stateBefore().locksSize() == s.locksSize(); // link predecessor to new block source.end().substituteSuccessor(target, newSucc); + if (removePhiInputs.size() > 0) { + + for (Node n : target.usages()) { + if (n instanceof Phi) { + Phi phi = (Phi) n; + int correction = 0; + for (int index : removePhiInputs) { + phi.removeInput(index - correction); + correction++; + } + } + } + + } return newSucc; } diff -r 43ffa0e47a46 -r dd6419f4bfe2 graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Mon May 23 19:21:53 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Mon May 23 21:21:47 2011 +0200 @@ -129,13 +129,16 @@ * @param oldSucc the old successor to replace * @param newSucc the new successor */ - public void substituteSuccessor(BlockBegin oldSucc, BlockBegin newSucc) { + public int substituteSuccessor(BlockBegin oldSucc, BlockBegin newSucc) { assert newSucc != null; + int count = 0; for (int i = 0; i < blockSuccessorCount; i++) { if (blockSuccessor(i) == oldSucc) { setBlockSuccessor(i, newSucc); + count++; } } + return count; } /** diff -r 43ffa0e47a46 -r dd6419f4bfe2 graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Mon May 23 19:21:53 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Mon May 23 21:21:47 2011 +0200 @@ -34,7 +34,7 @@ */ public final class Phi extends Value { - private static final int DEFAULT_MAX_VALUES = 20; + private static final int DEFAULT_MAX_VALUES = 2; private static final int INPUT_COUNT = 1; private static final int INPUT_BLOCK = 0; @@ -140,4 +140,12 @@ } return phi; } + + public void removeInput(int index) { + inputs().set(index, null); + for (int i = index + 1; i < usedInputCount; ++i) { + inputs().set(i - 1, inputs().get(i)); + } + usedInputCount--; + } } diff -r 43ffa0e47a46 -r dd6419f4bfe2 graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Mon May 23 19:21:53 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Mon May 23 21:21:47 2011 +0200 @@ -364,15 +364,15 @@ } else { 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(); + assert phi.valueCount() == block.predecessors().size() + (blockAppended ? 0 : 1) : "valueCount=" + phi.valueCount() + " predSize= " + block.predecessors().size(); } } }