diff graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java @ 2763:5e8a69041cd7

Model phi inputs as direct inputs in the graph instead of referring to the framestates of the predecessors.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 23 May 2011 14:51:18 +0200
parents 7ed72769d51a
children 99912abb3ff7
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java	Sat May 21 17:56:11 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java	Mon May 23 14:51:18 2011 +0200
@@ -40,7 +40,7 @@
 
     @Override
     protected int inputCount() {
-        return super.inputCount() + INPUT_COUNT;
+        return super.inputCount() + INPUT_COUNT + maxValues;
     }
 
     @Override
@@ -56,11 +56,13 @@
         return (BlockBegin) inputs().get(super.inputCount() + INPUT_BLOCK);
     }
 
-    public BlockBegin setBlock(Value n) {
+    public Value setBlock(Value n) {
         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.
@@ -70,7 +72,13 @@
      * @param graph
      */
     public Phi(CiKind kind, BlockBegin block, int index, Graph graph) {
-        super(kind, INPUT_COUNT, SUCCESSOR_COUNT, 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);
     }
@@ -116,7 +124,7 @@
      * @return the instruction that produced the value in the i'th predecessor
      */
     public Value inputAt(int i) {
-        return inputIn(block().blockPredecessors().get(i).stateAfter());
+        return (Value) inputs().get(i + INPUT_COUNT);
     }
 
     /**
@@ -137,7 +145,7 @@
      * @return the number of inputs in this phi
      */
     public int phiInputCount() {
-        return block().blockPredecessors().size();
+        return usedInputCount - 1;
     }
 
     @Override
@@ -163,5 +171,21 @@
         return "Phi: " + index + " (" + phiInputCount() + ")";
     }
 
+    public Phi addInput(Value 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.addInput(y);
+            this.replace(phi);
+        } else {
+            phi.inputs().set(usedInputCount++, y);
+        }
+        return phi;
+    }
+
 
 }