# HG changeset patch # User Thomas Wuerthinger # Date 1308152700 -7200 # Node ID d69b4d2eb49999bc9933b5ad0303944e47cbf03b # Parent ca2d8e02711096f2554317043aad8b32804e0b06 Cleaned up code around moveToPhi. The function is now explicitely called for EndNode and LoopEnd. diff -r ca2d8e027110 -r d69b4d2eb499 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Wed Jun 15 17:19:57 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Wed Jun 15 17:45:00 2011 +0200 @@ -246,7 +246,7 @@ } } } - if (!(instr instanceof Merge) && instr != instr.graph().start()) { + if (instr != instr.graph().start()) { walkState(instr, stateAfter); doRoot((Value) instr); } @@ -261,18 +261,7 @@ } } if (block.blockSuccessors().size() >= 1 && !jumpsToNextBlock(block.lastInstruction())) { - moveToPhi(); - Node last = block.lastInstruction(); - if (last instanceof EndNode) { - EndNode end = (EndNode) last; - block.lir().jump(getLIRBlock(end.merge())); - } else if (last instanceof LoopEnd) { - LoopEnd loopEnd = (LoopEnd) last; - block.lir().jump(getLIRBlock(loopEnd.loopBegin())); - } else { -// TTY.println("lastInstr: " + block.lastInstruction() + ", block=" + block.blockID()); - block.lir().jump(getLIRBlock((FixedNode) block.lastInstruction().successors().get(0))); - } + block.lir().jump(getLIRBlock((FixedNode) block.lastInstruction().successors().get(0))); } if (GraalOptions.TraceLIRGeneratorLevel >= 1) { @@ -284,8 +273,13 @@ blockDoEpilog(); } + @Override + public void visitMerge(Merge x) { + // Nothing to do. + } + private static boolean jumpsToNextBlock(Node node) { - return node instanceof BlockEnd || node instanceof Anchor; + return node instanceof BlockEnd || node instanceof EndNode || node instanceof LoopEnd; } @Override @@ -465,12 +459,6 @@ @Override public void visitAnchor(Anchor x) { setNoResult(x); - - // emit phi-instruction moves after safepoint since this simplifies - // describing the state at the safepoint. - - moveToPhi(); - lir.jump(getLIRBlock(x.next())); } @Override @@ -1413,58 +1401,44 @@ return null; } - protected void moveToPhi() { - // Moves all stack values into their phi position - LIRBlock bb = currentBlock; - if (bb.numberOfSux() == 1) { - - Node lastNode = bb.lastInstruction(); - if (lastNode instanceof EndNode || lastNode instanceof LoopEnd || lastNode instanceof Anchor) { - Node nextInstr = null; - int nextSuccIndex; + @Override + public void visitEndNode(EndNode end) { + setNoResult(end); + Merge merge = end.merge(); + moveToPhi(merge, merge.endIndex(end)); + lir.jump(getLIRBlock(end.merge())); + } - if (lastNode instanceof LoopEnd) { - LoopEnd loopEnd = (LoopEnd) lastNode; - nextInstr = loopEnd.loopBegin(); - nextSuccIndex = loopEnd.loopBegin().endCount(); - } else if (lastNode instanceof Anchor) { - assert false; - nextSuccIndex = -1; - } else { - assert lastNode instanceof EndNode; - nextInstr = ((EndNode) lastNode).merge(); - nextSuccIndex = nextInstr.inputs().variablePart().indexOf(lastNode); - } + + @Override + public void visitLoopEnd(LoopEnd x) { + setNoResult(x); + moveToPhi(x.loopBegin(), x.loopBegin().endCount()); + lir.jump(getLIRBlock(x.loopBegin())); + } - if (nextInstr instanceof Merge) { - Merge merge = (Merge) nextInstr; - assert nextSuccIndex >= 0 : "nextSuccIndex=" + nextSuccIndex + ", lastNode=" + lastNode + ", nextInstr=" + nextInstr + "; preds=" + nextInstr.predecessors() + ";"; - - PhiResolver resolver = new PhiResolver(this); - for (Node n : merge.usages()) { - if (n instanceof Phi) { - Phi phi = (Phi) n; - if (!phi.isDead()) { - Value curVal = phi.valueAt(nextSuccIndex); - if (curVal != null && curVal != phi) { - if (curVal instanceof Phi) { - operandForPhi((Phi) curVal); - } - CiValue operand = curVal.operand(); - if (operand.isIllegal()) { - assert curVal instanceof Constant || curVal instanceof Local : "these can be produced lazily" + curVal + "/" + phi; - operand = operandForInstruction(curVal); - } - resolver.move(operand, operandForPhi(phi)); - } - } + private void moveToPhi(Merge merge, int nextSuccIndex) { + PhiResolver resolver = new PhiResolver(this); + for (Node n : merge.usages()) { + if (n instanceof Phi) { + Phi phi = (Phi) n; + if (!phi.isDead()) { + Value curVal = phi.valueAt(nextSuccIndex); + if (curVal != null && curVal != phi) { + if (curVal instanceof Phi) { + operandForPhi((Phi) curVal); } + CiValue operand = curVal.operand(); + if (operand.isIllegal()) { + assert curVal instanceof Constant || curVal instanceof Local : "these can be produced lazily" + curVal + "/" + phi; + operand = operandForInstruction(curVal); + } + resolver.move(operand, operandForPhi(phi)); } - resolver.dispose(); } - return; } } + resolver.dispose(); } /** diff -r ca2d8e027110 -r d69b4d2eb499 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/EndNode.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/EndNode.java Wed Jun 15 17:19:57 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/EndNode.java Wed Jun 15 17:45:00 2011 +0200 @@ -36,7 +36,7 @@ @Override public void accept(ValueVisitor v) { - // Do nothing. Maybe moveToPhi? + v.visitEndNode(this); } @Override diff -r ca2d8e027110 -r d69b4d2eb499 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java Wed Jun 15 17:19:57 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java Wed Jun 15 17:45:00 2011 +0200 @@ -73,6 +73,11 @@ v.visitMerge(this); } + public int endIndex(EndNode end) { + assert inputs().variablePart().contains(end); + return inputs().variablePart().indexOf(end); + } + public void addEnd(EndNode end) { inputs().variablePart().add(end); } diff -r ca2d8e027110 -r d69b4d2eb499 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java Wed Jun 15 17:19:57 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java Wed Jun 15 17:45:00 2011 +0200 @@ -39,6 +39,7 @@ public abstract void visitConstant(Constant i); public abstract void visitConvert(Convert i); public abstract void visitExceptionObject(ExceptionObject i); + public abstract void visitEndNode(EndNode i); public abstract void visitFrameState(FrameState i); public abstract void visitAnchor(Anchor i); public abstract void visitIf(If i); diff -r ca2d8e027110 -r d69b4d2eb499 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java Wed Jun 15 17:19:57 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java Wed Jun 15 17:45:00 2011 +0200 @@ -466,11 +466,6 @@ } @Override - public void visitMerge(Merge x) { - // nothing to do for now - } - - @Override public void visitExceptionDispatch(ExceptionDispatch x) { // TODO ls: this needs some more work... @@ -494,17 +489,6 @@ } @Override - public void visitLoopEnd(LoopEnd x) { - setNoResult(x); - - // emit phi-instruction moves after safepoint since this simplifies - // describing the state at the safepoint. - - moveToPhi(); - lir.jump(getLIRBlock(x.loopBegin())); - } - - @Override public void visitValueAnchor(ValueAnchor valueAnchor) { // nothing to do for ValueAnchors }