changeset 3164:2b1eace223b0

added PhiType.(Value, Memory, Virtual), removed Phi.isDead, phis are now deleted immediately when they become invalid
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 06 Jul 2011 16:31:18 +0200
parents a5e5ef264dbf
children ce7e5b3798f7
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/PhiSimplifier.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoopPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/MemoryPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java
diffstat 10 files changed, 60 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jul 06 16:31:18 2011 +0200
@@ -39,6 +39,7 @@
 import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.compiler.ir.*;
 import com.oracle.max.graal.compiler.ir.Deoptimize.DeoptAction;
+import com.oracle.max.graal.compiler.ir.Phi.PhiType;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.compiler.value.*;
@@ -1499,7 +1500,7 @@
         int nextSuccIndex = merge.phiPredecessorIndex(pred);
         PhiResolver resolver = new PhiResolver(this);
         for (Phi phi : merge.phis()) {
-            if (!phi.isDead()) {
+            if (phi.type() == PhiType.Value) {
                 Value curVal = phi.valueAt(nextSuccIndex);
                 if (curVal != null && curVal != phi) {
                     if (curVal instanceof Phi) {
@@ -1561,7 +1562,7 @@
     }
 
     private CiValue operandForPhi(Phi phi) {
-        assert !phi.isDead() : "dead phi: " + phi.id();
+        assert phi.type() == PhiType.Value : "wrong phi type: " + phi.id();
         if (phi.operand().isIllegal()) {
             // allocate a variable for this phi
             createResultVariable(phi);
@@ -1626,7 +1627,7 @@
             public void doValue(Value value) {
                 if (value == x) {
                     // nothing to do, will be visited shortly
-                } else if (value instanceof Phi && !((Phi) value).isDead()) {
+                } else if (value instanceof Phi && ((Phi) value).type() == PhiType.Value) {
                     // phi's are special
                     operandForPhi((Phi) value);
                 } else if (value.operand().isIllegal()) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/PhiSimplifier.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/PhiSimplifier.java	Wed Jul 06 16:31:18 2011 +0200
@@ -62,9 +62,6 @@
         } else if (visited.isMarked(phi)) {
             // break cycles in phis
             return phi;
-        } else if (phi.isDead()) {
-            // don't bother with illegals
-            return phi;
         } else {
             // attempt to simplify the phi by recursively simplifying its operands
             visited.mark(phi);
@@ -74,20 +71,20 @@
             for (int i = 0; i < max; i++) {
                 Value oldInstr = phi.valueAt(i);
 
-                if (oldInstr == null || (oldInstr instanceof Phi && ((Phi) oldInstr).isDead())) {
+                if (oldInstr == null) {
                     // if one operand is illegal, make the entire phi illegal
-                    phi.makeDead();
                     visited.clear(phi);
-                    return phi;
+                    phi.replaceAndDelete(null);
+                    return null;
                 }
 
                 Value newInstr = simplify(oldInstr);
 
-                if (newInstr == null || (newInstr instanceof Phi && ((Phi) newInstr).isDead())) {
+                if (newInstr == null) {
                     // if the subst instruction is illegal, make the entire phi illegal
-                    phi.makeDead();
                     visited.clear(phi);
-                    return phi;
+                    phi.replaceAndDelete(null);
+                    return null;
                 }
 
                 // attempt to simplify this operand
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Merge.java	Wed Jul 06 16:31:18 2011 +0200
@@ -197,7 +197,7 @@
             while (!hasPhisOnStack && i < state.stackSize()) {
                 Value value = state.stackAt(i);
                 hasPhisOnStack = isPhiAtBlock(value);
-                if (value != null && !(value instanceof Phi && ((Phi) value).isDead())) {
+                if (value != null) {
                     i += value.kind.sizeInSlots();
                 } else {
                     i++;
@@ -208,7 +208,7 @@
                 Value value = state.localAt(i);
                 hasPhisInLocals = isPhiAtBlock(value);
                 // also ignore illegal HiWords
-                if (value != null && !(value instanceof Phi && ((Phi) value).isDead())) {
+                if (value != null) {
                     i += value.kind.sizeInSlots();
                 } else {
                     i++;
@@ -227,11 +227,7 @@
                 if (value != null) {
                     out.println(stateString(j, value));
                     // also ignore illegal HiWords
-                    if (value instanceof Phi && ((Phi) value).isDead()) {
-                        j +=  1;
-                    } else {
-                        j += value.kind.sizeInSlots();
-                    }
+                    j += value.kind.sizeInSlots();
                 } else {
                     j++;
                 }
@@ -320,10 +316,7 @@
 
         for (Node usage : usages()) {
             if (usage instanceof Phi) {
-                Phi phi = (Phi) usage;
-                if (!phi.isDead()) {
-                    phi.removeInput(predIndex);
-                }
+                ((Phi) usage).removeInput(predIndex);
             }
         }
     }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Phi.java	Wed Jul 06 16:31:18 2011 +0200
@@ -42,7 +42,7 @@
 
     private static final int SUCCESSOR_COUNT = 0;
 
-    private boolean isDead;
+    private final PhiType type;
 
     @Override
     protected int inputCount() {
@@ -66,21 +66,31 @@
         inputs().set(super.inputCount() + INPUT_MERGE, n);
     }
 
-    public Phi(CiKind kind, Merge merge, Graph graph) {
+    public static enum PhiType {
+        Value,          // normal value phis
+        Memory,         // memory phis
+        Virtual         // phis used for VirtualObjectField merges
+    }
+
+    public Phi(CiKind kind, Merge merge, PhiType type, Graph graph) {
         super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+        this.type = type;
         setMerge(merge);
     }
 
-    Phi(CiKind kind, Graph graph) {
+    private Phi(CiKind kind, PhiType type, Graph graph) {
         super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+        this.type = type;
+    }
+
+    public PhiType type() {
+        return type;
     }
 
     @Override
     public boolean verify() {
         assertTrue(merge() != null);
-        if (!isDead()) {
-            assertTrue(merge().phiPredecessorCount() == valueCount(), merge().phiPredecessorCount() + "==" + valueCount());
-        }
+        assertTrue(merge().phiPredecessorCount() == valueCount(), merge().phiPredecessorCount() + "==" + valueCount());
         return true;
     }
 
@@ -111,17 +121,6 @@
         v.visitPhi(this);
     }
 
-    /**
-     * Make this phi illegal if types were not merged correctly.
-     */
-    public void makeDead() {
-        isDead = true;
-    }
-
-    public boolean isDead() {
-        return isDead;
-    }
-
     @Override
     public void print(LogStream out) {
         out.print("phi function (");
@@ -143,10 +142,10 @@
             }
             str.append(valueAt(i) == null ? "-" : valueAt(i).id());
         }
-        if (isDead()) {
-            return "Phi: dead (" + str + ")";
+        if (type == PhiType.Value) {
+            return "Phi: (" + str + ")";
         } else {
-            return "Phi: (" + str + ")";
+            return type + "Phi: (" + str + ")";
         }
     }
 
@@ -160,8 +159,7 @@
 
     @Override
     public Node copy(Graph into) {
-        Phi x = new Phi(kind, into);
-        x.isDead = isDead;
+        Phi x = new Phi(kind, type, into);
         return x;
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Wed Jul 06 16:31:18 2011 +0200
@@ -29,6 +29,7 @@
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.compiler.ir.Phi.*;
 import com.oracle.max.graal.compiler.observer.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.value.*;
@@ -242,14 +243,13 @@
             Phi[] valuePhis = new Phi[fieldState.length];
             for (BlockExitState other : withStates) {
                 if (virtualObjectField != other.virtualObjectField && vobjPhi == null) {
-                    vobjPhi = new Phi(CiKind.Illegal, merge, virtualObject.graph());
-                    vobjPhi.makeDead();
+                    vobjPhi = new Phi(CiKind.Illegal, merge, PhiType.Virtual, virtualObject.graph());
                     vobjPhi.addInput(virtualObjectField);
                     virtualObjectField = vobjPhi;
                 }
                 for (int i2 = 0; i2 < fieldState.length; i2++) {
                     if (fieldState[i2] != other.fieldState[i2] && valuePhis[i2] == null) {
-                        valuePhis[i2] = new Phi(fieldState[i2].kind, merge, virtualObject.graph());
+                        valuePhis[i2] = new Phi(fieldState[i2].kind, merge, PhiType.Value, virtualObject.graph());
                         valuePhis[i2].addInput(fieldState[i2]);
                         fieldState[i2] = valuePhis[i2];
                     }
@@ -277,12 +277,11 @@
         @Override
         public void loopBegin(LoopBegin loopBegin) {
             Phi vobjPhi = null;
-            vobjPhi = new Phi(CiKind.Illegal, loopBegin, virtualObject.graph());
-            vobjPhi.makeDead();
+            vobjPhi = new Phi(CiKind.Illegal, loopBegin, PhiType.Virtual, virtualObject.graph());
             vobjPhi.addInput(virtualObjectField);
             virtualObjectField = vobjPhi;
             for (int i2 = 0; i2 < fieldState.length; i2++) {
-                Phi valuePhi = new Phi(fieldState[i2].kind, loopBegin, virtualObject.graph());
+                Phi valuePhi = new Phi(fieldState[i2].kind, loopBegin, PhiType.Value, virtualObject.graph());
                 valuePhi.addInput(fieldState[i2]);
                 fieldState[i2] = valuePhi;
                 updateField(i2);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoopPhase.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoopPhase.java	Wed Jul 06 16:31:18 2011 +0200
@@ -26,6 +26,7 @@
 
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.compiler.ir.Phi.PhiType;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.compiler.util.LoopUtil.Loop;
 import com.oracle.max.graal.compiler.value.*;
@@ -93,7 +94,7 @@
                         IntegerSub sub = new IntegerSub(kind, c2.init(), c1.init(), graph);
                         IntegerAdd addStride = new IntegerAdd(kind, sub, c1.stride(), graph);
                         IntegerAdd add = new IntegerAdd(kind, c1, addStride, graph);
-                        Phi phi = new Phi(kind, loopBegin, graph); // (gd) assumes order on loopBegin preds - works in collab with graph builder
+                        Phi phi = new Phi(kind, loopBegin, PhiType.Value, graph); // (gd) assumes order on loopBegin preds - works in collab with graph builder
                         phi.addInput(c2.init());
                         phi.addInput(add);
                         c2.replaceAndDelete(phi);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/MemoryPhase.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/MemoryPhase.java	Wed Jul 06 16:31:18 2011 +0200
@@ -28,6 +28,7 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.debug.*;
 import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.compiler.ir.Phi.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.graph.*;
 import com.sun.cri.ci.*;
@@ -155,8 +156,7 @@
                 assert phi.valueCount() <= phi.merge().endCount();
                 return original;
             } else {
-                Phi phi = new Phi(CiKind.Illegal, m, m.graph());
-                phi.makeDead(); // Phi does not produce a value, it is only a memory phi.
+                Phi phi = new Phi(CiKind.Illegal, m, PhiType.Memory, m.graph());
                 for (int i = 0; i < mergeOperationCount + 1; ++i) {
                     phi.addInput(original);
                 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/LoopUtil.java	Wed Jul 06 16:31:18 2011 +0200
@@ -27,6 +27,7 @@
 
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.compiler.ir.Phi.*;
 import com.oracle.max.graal.compiler.observer.*;
 import com.oracle.max.graal.compiler.schedule.*;
 import com.oracle.max.graal.compiler.util.GraphUtil.ColorSplitingLambda;
@@ -153,7 +154,7 @@
             for (Node usage : n.dataUsages()) {
                 if (usage instanceof Phi) { // filter out data graph cycles
                     Phi phi = (Phi) usage;
-                    if (!phi.isDead()) {
+                    if (phi.type() == PhiType.Value) {
                         Merge merge = phi.merge();
                         if (merge instanceof LoopBegin) {
                             LoopBegin phiLoop = (LoopBegin) merge;
@@ -172,7 +173,7 @@
             markWithState(n, inOrBefore);
             if (n instanceof Phi) { // filter out data graph cycles
                 Phi phi = (Phi) n;
-                if (!phi.isDead()) {
+                if (phi.type() == PhiType.Value) {
                     int backIndex = -1;
                     Merge merge = phi.merge();
                     if (!loopNodes.isMarked(merge) && merge instanceof LoopBegin) {
@@ -489,7 +490,7 @@
                     values.add(valueAt);
                 }
                 if (createPhi) {
-                    Phi phi = new Phi(kind, merge, merge.graph());
+                    Phi phi = new Phi(kind, merge, PhiType.Value, merge.graph());
                     valueMap.set(point, phi);
                     for (EndNode end : merge.cfgPredecessors()) {
                         phi.addInput(getValueAt(colors.get(end), valueMap, kind));
@@ -642,7 +643,7 @@
             }
             if (n instanceof Phi) { // filter out data graph cycles
                 Phi phi = (Phi) n;
-                if (!phi.isDead()) {
+                if (phi.type() == PhiType.Value) {
                     int backIndex = -1;
                     Merge merge = phi.merge();
                     if (!loopNodes.isNew(merge) && !loopNodes.isMarked(merge) && merge instanceof LoopBegin) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameState.java	Wed Jul 06 16:31:18 2011 +0200
@@ -29,6 +29,7 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.debug.*;
 import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.compiler.ir.Phi.*;
 import com.oracle.max.graal.graph.*;
 import com.sun.cri.ci.*;
 import com.sun.cri.ri.*;
@@ -330,7 +331,7 @@
                     return phi;
                 }
             }
-            Phi phi = new Phi(p.kind, block, graph());
+            Phi phi = new Phi(p.kind, block, PhiType.Value, graph());
             setValueAt(localsSize + i, phi);
             return phi;
         }
@@ -350,7 +351,7 @@
                 return phi;
             }
         }
-        Phi phi = new Phi(p.kind, block, graph());
+        Phi phi = new Phi(p.kind, block, PhiType.Value, graph());
         storeLocal(i, phi);
         return phi;
     }
@@ -398,11 +399,9 @@
                 Value y = other.valueAt(i);
                 if (x != y || ((x instanceof Phi) && ((Phi) x).merge() == block)) {
                     if (typeMismatch(x, y)) {
-                        if (x instanceof Phi) {
-                            Phi phi = (Phi) x;
-                            if (phi.merge() == block) {
-                                phi.makeDead();
-                            }
+                        if ((x instanceof Phi) && ((Phi) x).merge() == block) {
+                            x.replaceAtUsages(null);
+                            x.delete();
                         }
                         setValueAt(i, null);
                         continue;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java	Wed Jul 06 16:01:29 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java	Wed Jul 06 16:31:18 2011 +0200
@@ -28,6 +28,7 @@
 import java.util.*;
 
 import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.compiler.ir.Phi.PhiType;
 import com.oracle.max.graal.graph.*;
 import com.sun.cri.ci.*;
 import com.sun.cri.ri.*;
@@ -332,8 +333,11 @@
     public Value loadLocal(int i) {
         Value x = locals[i];
         if (x != null) {
-            if (x instanceof Phi && ((Phi) x).isDead()) {
-                return null;
+            if (x instanceof Phi) {
+                assert ((Phi) x).type() == PhiType.Value;
+                if (x.isDeleted()) {
+                    return null;
+                }
             }
             assert x.kind.isSingleWord() || locals[i + 1] == null || locals[i + 1] instanceof Phi;
         }