changeset 2764:99912abb3ff7

Phi clean up. Phis no longer save their local/stack index.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 23 May 2011 15:07:01 +0200
parents 5e8a69041cd7
children 2fd52cd64156 cc2b98e2b832
files graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java
diffstat 4 files changed, 26 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java	Mon May 23 14:51:18 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java	Mon May 23 15:07:01 2011 +0200
@@ -57,10 +57,10 @@
             // attempt to simplify the phi by recursively simplifying its operands
             phi.setFlag(Value.Flag.PhiVisited);
             Value phiSubst = null;
-            int max = phi.phiInputCount();
+            int max = phi.valueCount();
             boolean cannotSimplify = false;
             for (int i = 0; i < max; i++) {
-                Value oldInstr = phi.inputAt(i);
+                Value oldInstr = phi.valueAt(i);
 
                 if (oldInstr == null || oldInstr.isIllegal() || oldInstr.isDeadPhi()) {
                     // if one operand is illegal, make the entire phi illegal
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Mon May 23 14:51:18 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/BlockBegin.java	Mon May 23 15:07:01 2011 +0200
@@ -352,7 +352,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#phiInputCount() inputs} are appended to the returned string.
+     * block, its {@linkplain Phi#valueCount() inputs} are appended to the returned string.
      *
      * @param index the index of the value in the frame state
      * @param value the frame state value
@@ -368,9 +368,9 @@
             // print phi operands
             if (phi.block() == this) {
                 sb.append(" [");
-                for (int j = 0; j < phi.phiInputCount(); j++) {
+                for (int j = 0; j < phi.valueCount(); j++) {
                     sb.append(' ');
-                    Value operand = phi.inputAt(j);
+                    Value operand = phi.valueAt(j);
                     if (operand != null) {
                         sb.append(Util.valueString(operand));
                     } else {
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java	Mon May 23 14:51:18 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java	Mon May 23 15:07:01 2011 +0200
@@ -33,15 +33,14 @@
  */
 public final class Phi extends Value {
 
+    private static final int DEFAULT_MAX_VALUES = 2;
+
     private static final int INPUT_COUNT = 1;
     private static final int INPUT_BLOCK = 0;
 
     private static final int SUCCESSOR_COUNT = 0;
 
-    @Override
-    protected int inputCount() {
-        return super.inputCount() + INPUT_COUNT + maxValues;
-    }
+    private int usedInputCount;
 
     @Override
     protected int successorCount() {
@@ -60,10 +59,6 @@
         return (BlockBegin) inputs().set(super.inputCount() + INPUT_BLOCK, n);
     }
 
-    private final int index;
-    private final int maxValues;
-    private int usedInputCount;
-
     /**
      * Create a new Phi for the specified join block and local variable (or operand stack) slot.
      * @param kind the type of the variable
@@ -71,50 +66,14 @@
      * @param index the index into the stack (if < 0) or local variables
      * @param graph
      */
-    public Phi(CiKind kind, BlockBegin block, int index, Graph graph) {
-        this(kind, block, index, 2, graph);
-    }
-
-    public Phi(CiKind kind, BlockBegin block, int index, int maxValues, Graph graph) {
-        super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph);
-        usedInputCount = 1;
-        this.maxValues = maxValues;
-        this.index = index;
-        setBlock(block);
-    }
-
-    /**
-     * Check whether this phi corresponds to a local variable.
-     * @return {@code true} if this phi refers to a local variable
-     */
-    public boolean isLocal() {
-        return index >= 0;
+    public Phi(CiKind kind, BlockBegin block, Graph graph) {
+        this(kind, block, DEFAULT_MAX_VALUES, graph);
     }
 
-    /**
-     * Check whether this phi corresponds to a stack location.
-     * @return {@code true} if this phi refers to a stack location
-     */
-    public boolean isOnStack() {
-        return index < 0;
-    }
-
-    /**
-     * Get the local index of this phi.
-     * @return the local index
-     */
-    public int localIndex() {
-        assert isLocal();
-        return index;
-    }
-
-    /**
-     * Get the stack index of this phi.
-     * @return the stack index of this phi
-     */
-    public int stackIndex() {
-        assert isOnStack();
-        return -(index + 1);
+    public Phi(CiKind kind, BlockBegin block, int maxValues, Graph graph) {
+        super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph);
+        usedInputCount = 1;
+        setBlock(block);
     }
 
     /**
@@ -123,28 +82,15 @@
      * @param i the index of the predecessor
      * @return the instruction that produced the value in the i'th predecessor
      */
-    public Value inputAt(int i) {
+    public Value valueAt(int i) {
         return (Value) inputs().get(i + INPUT_COUNT);
     }
 
     /**
-     * Gets the instruction that produces the value for this phi in the specified state.
-     * @param state the state to access
-     * @return the instruction producing the value
-     */
-    public Value inputIn(FrameState state) {
-        if (isLocal()) {
-            return state.localAt(localIndex());
-        } else {
-            return state.stackAt(stackIndex());
-        }
-    }
-
-    /**
      * 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
      */
-    public int phiInputCount() {
+    public int valueCount() {
         return usedInputCount - 1;
     }
 
@@ -168,16 +114,16 @@
 
     @Override
     public String shortName() {
-        return "Phi: " + index + " (" + phiInputCount() + ")";
+        return "Phi: (" + valueCount() + ")";
     }
 
-    public Phi addInput(Value y) {
+    public Phi addInput(Node y) {
         assert !this.isDeleted() && !y.isDeleted();
         Phi phi = this;
         if (usedInputCount == inputs().size()) {
-            phi = new Phi(kind, block(), index, maxValues * 2, graph());
-            for (int i = 0; i < phiInputCount(); ++i) {
-                phi.addInput(inputAt(i));
+            phi = new Phi(kind, block(), usedInputCount * 2, graph());
+            for (int i = 0; i < valueCount(); ++i) {
+                phi.addInput(valueAt(i));
             }
             phi.addInput(y);
             this.replace(phi);
@@ -186,6 +132,4 @@
         }
         return phi;
     }
-
-
 }
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Mon May 23 14:51:18 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java	Mon May 23 15:07:01 2011 +0200
@@ -261,11 +261,11 @@
         if (p != null) {
             if (p instanceof Phi) {
                 Phi phi = (Phi) p;
-                if (phi.block() == block && phi.isOnStack() && phi.stackIndex() == i) {
+                if (phi.block() == block) {
                     return phi;
                 }
             }
-            Phi phi = new Phi(p.kind, block, -i - 1, graph());
+            Phi phi = new Phi(p.kind, block, graph());
             inputs().set(localsSize + i, phi);
             return phi;
         }
@@ -281,11 +281,11 @@
         Value p = localAt(i);
         if (p instanceof Phi) {
             Phi phi = (Phi) p;
-            if (phi.block() == block && phi.isLocal() && phi.localIndex() == i) {
+            if (phi.block() == block) {
                 return phi;
             }
         }
-        Phi phi = new Phi(p.kind, block, i, graph());
+        Phi phi = new Phi(p.kind, block, graph());
         storeLocal(i, phi);
         return phi;
     }
@@ -352,7 +352,7 @@
                     }
 
                     Phi originalPhi = phi;
-                    if (phi.phiInputCount() == 0) {
+                    if (phi.valueCount() == 0) {
                         int size = block.predecessors().size();
                         if (blockAppended) {
                             size--;