# HG changeset patch # User Thomas Wuerthinger # Date 1308062487 -7200 # Node ID 49a8b14e9d249ad6d5727851d277f5870d0bd591 # Parent 84a7b7069ffbc2cf56b0f9ee46d1ed8a935cda77 Tentative change that adds successor tags. diff -r 84a7b7069ffb -r 49a8b14e9d24 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 Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Tue Jun 14 16:41:27 2011 +0200 @@ -1407,6 +1407,50 @@ // Moves all stack values into their phi position LIRBlock bb = currentBlock; if (bb.numberOfSux() == 1) { + + Node lastNode = bb.lastInstruction(); + if (lastNode instanceof Instruction || lastNode == lastNode.graph().start()) { + Node nextInstr = lastNode.successors().get(Instruction.SUCCESSOR_NEXT); + int nextSuccIndex = lastNode.successorTags()[Instruction.SUCCESSOR_NEXT]; + + if (lastNode instanceof LoopEnd) { + LoopEnd loopEnd = (LoopEnd) lastNode; + nextInstr = loopEnd.loopBegin(); + nextSuccIndex = loopEnd.loopBegin().predecessors().size() + 1; + } + if (nextInstr instanceof Merge) { + Merge merge = (Merge) nextInstr; + assert nextSuccIndex > 0 : "nextSuccIndex=" + nextSuccIndex + ", lastNode=" + lastNode + ", nextInstr=" + nextInstr + "; preds=" + nextInstr.predecessors() + "; predIndex=" + nextInstr.predecessorsIndex(); + + 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 - 1); + 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; + } + + assert false : "lastNode=" + lastNode + " instr=" + bb.getInstructions(); + + + LIRBlock sux = bb.suxAt(0); assert sux.numberOfPreds() > 0 : "invalid CFG"; diff -r 84a7b7069ffb -r 49a8b14e9d24 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Tue Jun 14 16:41:27 2011 +0200 @@ -69,6 +69,8 @@ */ public void build() { new GraphBuilderPhase(compilation, compilation.method, false, false).apply(compilation.graph); + + printGraph("After GraphBuilding", compilation.graph); //new DuplicationPhase().apply(compilation.graph); new DeadCodeEliminationPhase().apply(compilation.graph); @@ -79,6 +81,17 @@ printGraph("After Ininling", compilation.graph); } + // Set successor tags + for (Node n : compilation.graph.getNodes()) { + if (n instanceof Merge) { + for (int i=0; i blockPredecessors() { - return (List) Collections.unmodifiableList(predecessors()); - } - /** * Get the number of predecessors. * @return the number of predecessors diff -r 84a7b7069ffb -r 49a8b14e9d24 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Value.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Value.java Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Value.java Tue Jun 14 16:41:27 2011 +0200 @@ -134,19 +134,6 @@ return null; // default: unknown declared type } - /** - * Apply the specified closure to all the input values of this instruction. - * @param closure the closure to apply - */ - public void inputValuesDo(ValueClosure closure) { - for (int i = 0; i < inputs().size(); i++) { - inputs().set(i, closure.apply((Value) inputs().get(i))); - } - for (int i = 0; i < successors().size(); i++) { - successors().set(i, closure.apply((Value) successors().get(i))); - } - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); diff -r 84a7b7069ffb -r 49a8b14e9d24 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Tue Jun 14 16:41:27 2011 +0200 @@ -193,8 +193,8 @@ for (Node n : graph.getNodes()) { if (n instanceof Placeholder) { Placeholder p = (Placeholder) n; - assert p.blockPredecessors().size() == 1; - Node pred = p.blockPredecessors().get(0); + assert p.predecessors().size() == 1; + Node pred = p.predecessors().get(0); int predIndex = p.predecessorsIndex().get(0); pred.successors().setAndClear(predIndex, p, 0); p.delete(); @@ -1123,8 +1123,6 @@ if (block.firstInstruction == null) { if (block.isLoopHeader) { -// block.firstInstruction = new Merge(block.startBci, graph); - LoopBegin loopBegin = new LoopBegin(graph); LoopEnd loopEnd = new LoopEnd(graph); loopEnd.setLoopBegin(loopBegin); diff -r 84a7b7069ffb -r 49a8b14e9d24 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SplitCriticalEdgesPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SplitCriticalEdgesPhase.java Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/SplitCriticalEdgesPhase.java Tue Jun 14 16:41:27 2011 +0200 @@ -43,6 +43,7 @@ Anchor a = new Anchor(graph); a.successors().setAndClear(Instruction.SUCCESSOR_NEXT, n, j); n.successors().set(j, a); + n.successorTags()[j] = 1; } } } diff -r 84a7b7069ffb -r 49a8b14e9d24 graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Tue Jun 14 16:41:27 2011 +0200 @@ -40,6 +40,7 @@ final ArrayList usages; final ArrayList predecessors; final ArrayList predecessorsIndex; + final int[] successorTags; public Node(int inputCount, int successorCount, Graph graph) { assert graph != null : "cannot create a node for a null graph"; @@ -47,6 +48,7 @@ this.id = graph.register(this); this.inputs = new NodeArray(this, inputCount); this.successors = new NodeArray(this, successorCount); + this.successorTags = new int[successorCount]; this.predecessors = new ArrayList(); this.usages = new ArrayList(); this.predecessorsIndex = new ArrayList(); @@ -71,6 +73,10 @@ public NodeArray successors() { return successors; } + + public int[] successorTags() { + return successorTags; + } public int id() { return id; diff -r 84a7b7069ffb -r 49a8b14e9d24 graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java Tue Jun 14 15:10:46 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java Tue Jun 14 16:41:27 2011 +0200 @@ -26,6 +26,8 @@ import java.util.Arrays; import java.util.Iterator; +import org.omg.PortableInterceptor.SUCCESSFUL; + public class NodeArray extends AbstractList { private final Node node; @@ -149,6 +151,7 @@ assert !self().isDeleted() : "trying to setAndClear successor of deleted node: " + self().shortName(); assert self().successors == this; Node value = clearedNode.successors.get(clearedIndex); + self().successorTags[index] = clearedNode.successorTags[clearedIndex]; assert value != Node.Null; clearedNode.successors.nodes[clearedIndex] = Node.Null; set(index, Node.Null);