# HG changeset patch # User Thomas Wuerthinger # Date 1306344580 -7200 # Node ID 50677668afe363dba3a7b9da1436abd160c84c3d # Parent aeccd2af4e9e891331b2feb57b17c0b9de4402b7 Towards making goto removal work. diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java Wed May 25 19:29:40 2011 +0200 @@ -116,7 +116,7 @@ public static int SequentialSwitchLimit = 4; public static int RangeTestsSwitchDensity = 5; - public static boolean DetailedAsserts = ____; + public static boolean DetailedAsserts = true;//____; // Runtime settings public static int ReadPrefetchInstr = 0; diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/CriticalEdgeFinder.java Wed May 25 19:29:40 2011 +0200 @@ -105,28 +105,19 @@ // This goto is not a safepoint. Goto e = new Goto(null, graph); - - //TTY.println("SPLITTING NODE"); - // link predecessor to new block -// if (source.getInstructions().size() > 0) { - Instruction sourceInstruction = source.getInstructions().get(source.getInstructions().size() - 1); Instruction targetInstruction = target.getInstructions().get(0); - int replacedIndex = sourceInstruction.successors().indexOf(targetInstruction); + int sourceInstructionPredIndex = targetInstruction.predecessors().indexOf(sourceInstruction); + int replacedIndex = targetInstruction.predecessorsIndex().get(sourceInstructionPredIndex); assert replacedIndex != -1 && sourceInstruction.successors().get(replacedIndex) != null; e.successors().setAndClear(1, sourceInstruction, replacedIndex); sourceInstruction.successors().set(replacedIndex, e); newSucc.getInstructions().add(e); - // assert e.successors().get(0) != null; assert e.defaultSuccessor() != null; -// } - - source.substituteSuccessor(target, newSucc); target.substitutePredecessor(source, newSucc); newSucc.blockPredecessors().add(source); newSucc.blockSuccessors().add(target); - return newSucc; } } diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Wed May 25 19:29:40 2011 +0200 @@ -221,18 +221,11 @@ for (Node n : graph.getNodes()) { if (n instanceof Placeholder) { Placeholder p = (Placeholder) n; - - /*if (p == graph.start().successors().get(0)) { - // nothing to do... - } else*/ - if (p.blockPredecessors().size() == 0) { - assert p.next() == null; - p.delete(); - } else { - assert p.blockPredecessors().size() == 1; - p.successors().replaceKeepOrder(p.next(), p.blockPredecessors().get(0)); - p.delete(); - } + assert p.blockPredecessors().size() == 1; + Node pred = p.blockPredecessors().get(0); + int predIndex = p.predecessorsIndex().get(0); + pred.successors().setAndClear(predIndex, p, 0); + p.delete(); } } @@ -326,9 +319,10 @@ if (first instanceof Placeholder) { BlockBegin merge = new BlockBegin(existingState.bci, target.blockID, target.isLoopHeader, graph); - for (Node n : new ArrayList(first.predecessors())) { - n.successors().replace(first, merge); - } + + Placeholder p = (Placeholder) first; + assert p.next() == null; + p.replace(merge); target.firstInstruction = merge; merge.setStateBefore(existingState); } @@ -1177,8 +1171,13 @@ } private void appendGoto(Instruction target) { - lastInstr.appendNext(target); - //append(new Goto(target, graph)); + //if (target instanceof BlockBegin && !((BlockBegin)target).isLoopHeader) { + // System.out.println("NOTOMITTED"); + //append(new Goto(target, graph)); + //} else { + // System.out.println("omitted"); + lastInstr.appendNext(target); + //} } private void iterateBytecodesForBlock(Block block) { diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockEnd.java Wed May 25 19:29:40 2011 +0200 @@ -142,18 +142,6 @@ } /** - * This method reorders the predecessors of the i-th successor in such a way that this BlockEnd is at position backEdgeIndex. - */ - public void reorderSuccessor(int i, int backEdgeIndex) { - assert i >= 0 && i < blockSuccessorCount; - Instruction successor = blockSuccessor(i); - if (successor != null) { - successors().set(super.successorCount() + SUCCESSOR_COUNT + i, Node.Null); - successors().set(super.successorCount() + SUCCESSOR_COUNT + i, successor, backEdgeIndex); - } - } - - /** * Gets this block end's list of successors. * @return the successor list */ diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalGraph/src/com/oracle/graal/graph/Node.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/Node.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/Node.java Wed May 25 19:29:40 2011 +0200 @@ -37,6 +37,7 @@ final NodeArray successors; final ArrayList usages; final ArrayList predecessors; + final ArrayList predecessorsIndex; public Node(int inputCount, int successorCount, Graph graph) { assert graph != null; @@ -46,12 +47,17 @@ this.successors = new NodeArray(this, successorCount); this.predecessors = new ArrayList(); this.usages = new ArrayList(); + this.predecessorsIndex = new ArrayList(); } public List predecessors() { return Collections.unmodifiableList(predecessors); } + public List predecessorsIndex() { + return Collections.unmodifiableList(predecessorsIndex); + } + public List usages() { return Collections.unmodifiableList(usages); } @@ -82,15 +88,20 @@ for (Node usage : usages) { usage.inputs.replaceFirstOccurrence(this, other); } + int z = 0; for (Node predecessor : predecessors) { - predecessor.successors.replaceFirstOccurrence(this, other); + int predIndex = predecessorsIndex.get(z); + predecessor.successors.nodes[predIndex] = other; + ++z; } if (other != null) { other.usages.addAll(usages); other.predecessors.addAll(predecessors); + other.predecessorsIndex.addAll(predecessorsIndex); } usages.clear(); predecessors.clear(); + predecessorsIndex.clear(); delete(); } @@ -101,6 +112,7 @@ public void delete() { assert !isDeleted(); assert usages.size() == 0 && predecessors.size() == 0; + assert predecessorsIndex.size() == 0; for (int i = 0; i < inputs.size(); ++i) { inputs.set(i, Null); } diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java Wed May 25 19:29:40 2011 +0200 @@ -30,7 +30,7 @@ public class NodeArray extends AbstractList { private final Node node; - private final Node[] nodes; + final Node[] nodes; public NodeArray(Node node, int length) { this.node = node; @@ -62,40 +62,17 @@ } else { assert self().successors == this; if (old != null) { - old.predecessors.remove(self()); + for (int i = 0; i < old.predecessors.size(); ++i) { + Node cur = old.predecessors.get(i); + if (cur == self() && old.predecessorsIndex.get(i) == index) { + old.predecessors.remove(i); + old.predecessorsIndex.remove(i); + } + } } if (node != null) { node.predecessors.add(self()); - } - } - } - - return old; - } - - /** - * Sets the specified input/successor to the given node, and inserts the back edge (usage/predecessor) at the given index. - */ - public Node set(int index, Node node, int backIndex) { - assert node == Node.Null || node.graph == self().graph; - Node old = nodes[index]; - - if (old != node) { - nodes[index] = node; - if (self().inputs == this) { - if (old != null) { - old.usages.remove(self()); - } - if (node != null) { - node.usages.add(backIndex, self()); - } - } else { - assert self().successors == this; - if (old != null) { - old.predecessors.remove(self()); - } - if (node != null) { - node.predecessors.add(backIndex, self()); + node.predecessorsIndex.add(index); } } } @@ -147,59 +124,14 @@ set(index, Node.Null); nodes[index] = value; - int numberOfMatchingSuccs = 0; - for (int i = 0; i < clearedIndex; ++i) { - if (clearedNode.successors.get(i) == value) { - numberOfMatchingSuccs++; - } - } - for (int i = 0; i < value.predecessors.size(); ++i) { - if (value.predecessors.get(i) == clearedNode) { - if (numberOfMatchingSuccs == 0) { - value.predecessors.set(i, self()); - break; - } else { - numberOfMatchingSuccs--; - } + if (value.predecessors.get(i) == clearedNode && value.predecessorsIndex.get(i) == clearedIndex) { + value.predecessors.set(i, self()); + value.predecessorsIndex.set(i, index); } } } - public int replaceKeepOrder(Node targetNode, Node replacement) { - int deletedSuccessorIndex = -1; - if (this == self().successors) { - int firstIndex = -1; - for (int i = 0; i < replacement.successors.size(); ++i) { - if (replacement.successors.get(i) == self()) { - replacement.successors().set(i, Node.Null); - firstIndex = i; - break; - } - } - - assert firstIndex != -1; - - for (int i = 0; i < this.size(); ++i) { - if (nodes[i] == targetNode) { - replacement.successors().nodes[firstIndex] = targetNode; - for (int j = 0; j < targetNode.predecessors.size(); ++j) { - if (targetNode.predecessors.get(j) == self()) { - targetNode.predecessors.set(j, replacement); - break; - } - } - nodes[i] = Node.Null; - deletedSuccessorIndex = i; - break; - } - } - } else { - assert false : "not supported"; - } - return deletedSuccessorIndex; - } - public int size() { return nodes.length; } diff -r aeccd2af4e9e -r 50677668afe3 graal/GraalRuntime/src/com/oracle/graal/runtime/HotSpotOptions.java --- a/graal/GraalRuntime/src/com/oracle/graal/runtime/HotSpotOptions.java Wed May 25 16:48:28 2011 +0200 +++ b/graal/GraalRuntime/src/com/oracle/graal/runtime/HotSpotOptions.java Wed May 25 19:29:40 2011 +0200 @@ -77,7 +77,7 @@ } if (value != null) { f.set(null, value); - Logger.info("Set option " + fieldName + " to " + value); + //Logger.info("Set option " + fieldName + " to " + value); } else { Logger.info("Wrong value \"" + valueString + "\" for option " + fieldName); return false;