# HG changeset patch # User Lukas Stadler # Date 1304596034 -7200 # Node ID 768d77a1c7af4282c726531447c50e69b568e5eb # Parent 4a36a0bd6d188d54d8dd25d84ff5e4eb9e3891fc new node layout: Instruction diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Thu May 05 13:47:14 2011 +0200 @@ -182,7 +182,7 @@ // 3. setup internal state for appending instructions curBlock = startBlock; lastInstr = startBlock; - lastInstr.setNext(null, -1); + lastInstr.appendNext(null, -1); curState = initialState; if (isSynchronized(rootMethod.accessFlags())) { @@ -1165,7 +1165,7 @@ if (lastInstr instanceof Base) { assert false : "may only happen when inlining intrinsics"; } else { - lastInstr = lastInstr.setNext(x, bci); + lastInstr = lastInstr.appendNext(x, bci); } if (++stats.nodeCount >= C1XOptions.MaximumInstructionCount) { // bailout if we've exceeded the maximum inlining size @@ -1289,7 +1289,7 @@ curBlock = b; curState = b.stateBefore().copy(); lastInstr = b; - b.setNext(null, -1); + b.appendNext(null, -1); iterateBytecodesForBlock(b.bci(), false); } @@ -1321,7 +1321,7 @@ if (nextBlock != null && nextBlock != block) { // we fell through to the next block, add a goto and break end = new Goto(nextBlock, null, false); - lastInstr = lastInstr.setNext(end, prevBCI); + lastInstr = lastInstr.appendNext(end, prevBCI); break; } // read the opcode diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Thu May 05 13:47:14 2011 +0200 @@ -179,7 +179,7 @@ // This goto is not a safepoint. Goto e = new Goto(target, null, false); - newSucc.setNext(e, bci); + newSucc.appendNext(e, bci); newSucc.setEnd(e); // setup states FrameState s = source.end().stateAfter(); diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java Thu May 05 13:47:14 2011 +0200 @@ -842,7 +842,7 @@ /** * Formats a given instruction as a value in a {@linkplain FrameState frame state}. If the instruction is a phi defined at a given - * block, its {@linkplain Phi#inputCount() inputs} are appended to the returned string. + * block, its {@linkplain Phi#phiInputCount() inputs} are appended to the returned string. * * @param index the index of the value in the frame state * @param value the frame state value @@ -858,7 +858,7 @@ // print phi operands if (phi.block() == this) { sb.append(" ["); - for (int j = 0; j < phi.inputCount(); j++) { + for (int j = 0; j < phi.phiInputCount(); j++) { sb.append(' '); Value operand = phi.inputAt(j); if (operand != null) { diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java Thu May 05 13:47:14 2011 +0200 @@ -24,6 +24,7 @@ import java.util.*; +import com.oracle.graal.graph.*; import com.sun.c1x.*; import com.sun.c1x.value.*; import com.sun.cri.ci.*; @@ -42,6 +43,34 @@ */ public abstract class Instruction extends Value { + public static final int INPUT_COUNT = 0; + + public static final int SUCCESSOR_COUNT = 1; + public static final int SUCCESSOR_NEXT = 0; + + @Override + protected int inputCount() { + return super.inputCount() + INPUT_COUNT; + } + + @Override + protected int successorCount() { + return super.successorCount() + SUCCESSOR_COUNT; + } + + /** + * Links to next instruction in a basic block, to {@code null} if this instruction is the end of a basic block or to + * itself if not in a block. + */ + public Instruction next() { + return (Instruction) successors().get(super.successorCount() + SUCCESSOR_NEXT); + } + + public Node setNext(Instruction next) { + return successors().set(super.successorCount() + SUCCESSOR_NEXT, next); + } + + public static final int SYNCHRONIZATION_ENTRY_BCI = -1; /** @@ -51,11 +80,6 @@ private int bci; /** - * Links to next instruction in a basic block or to {@code} itself if not in a block. - */ - private Instruction next = this; - - /** * List of associated exception handlers. */ private List exceptionHandlers = ExceptionHandler.ZERO_HANDLERS; @@ -63,10 +87,16 @@ /** * Constructs a new instruction with the specified value type. * @param kind the value type for this instruction + * @param inputCount + * @param successorCount */ + public Instruction(CiKind kind, int inputCount, int successorCount, Graph graph) { + super(kind, inputCount + INPUT_COUNT, successorCount + SUCCESSOR_COUNT, graph); + C1XMetrics.HIRInstructions++; + } + public Instruction(CiKind kind) { - super(kind); - C1XMetrics.HIRInstructions++; + this(kind, 0, 0, null); } /** @@ -91,20 +121,9 @@ * @return {@code true} if this instruction has been added to the basic block containing it */ public final boolean isAppended() { - return next != this; + return next() != this; } - /** - * Gets the next instruction after this one in the basic block, or {@code null} - * if this instruction is the end of a basic block. - * @return the next instruction after this one in the basic block - */ - public final Instruction next() { - if (next == this) { - return null; - } - return next; - } /** * Sets the next instruction for this instruction. Note that it is illegal to @@ -113,13 +132,13 @@ * @param bci the bytecode index of the next instruction * @return the new next instruction */ - public final Instruction setNext(Instruction next, int bci) { - this.next = next; + public final Instruction appendNext(Instruction next, int bci) { + setNext(next); if (next != null) { assert !(this instanceof BlockEnd); next.setBCI(bci); - if (next.next == next) { - next.next = null; + if (next.next() == next) { + next.setNext(null); } } return next; @@ -134,7 +153,7 @@ public final Instruction resetNext(Instruction next) { if (next != null) { assert !(this instanceof BlockEnd); - this.next = next; + setNext(next); } return next; } @@ -164,7 +183,7 @@ // TODO(tw): Make this more efficient. Instruction cur = this; while (!(cur instanceof BlockEnd)) { - cur = cur.next; + cur = cur.next(); } return ((BlockEnd) cur).begin; } diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Thu May 05 13:47:14 2011 +0200 @@ -125,8 +125,7 @@ * Get the number of inputs to this phi (i.e. the number of predecessors to the join block). * @return the number of inputs in this phi */ - @Override - public int inputCount() { + public int phiInputCount() { if (block.isExceptionEntry()) { return block.exceptionHandlerStates().size(); } else { diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/opt/PhiSimplifier.java --- a/graal/GraalCompiler/src/com/sun/c1x/opt/PhiSimplifier.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/opt/PhiSimplifier.java Thu May 05 13:47:14 2011 +0200 @@ -78,7 +78,7 @@ // attempt to simplify the phi by recursively simplifying its operands phi.setFlag(Value.Flag.PhiVisited); Value phiSubst = null; - int max = phi.inputCount(); + int max = phi.phiInputCount(); boolean cannotSimplify = false; for (int i = 0; i < max; i++) { Value oldInstr = phi.inputAt(i); diff -r 4a36a0bd6d18 -r 768d77a1c7af graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Thu May 05 13:27:48 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Thu May 05 13:47:14 2011 +0200 @@ -363,7 +363,7 @@ if (x instanceof Phi) { Phi phi = (Phi) x; if (phi.block() == block) { - for (int j = 0; j < phi.inputCount(); j++) { + for (int j = 0; j < phi.phiInputCount(); j++) { if (phi.inputIn(other) == null) { throw new CiBailout("phi " + phi + " has null operand at new predecessor"); }