Mercurial > hg > graal-jvmci-8
diff graal/GraalCompiler/src/com/sun/c1x/ir/Instruction.java @ 2582:768d77a1c7af
new node layout: Instruction
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Thu, 05 May 2011 13:47:14 +0200 |
parents | 0f9eeb15e636 |
children | 06b2eac2f5d3 |
line wrap: on
line diff
--- 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<ExceptionHandler> 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; }