changeset 6464:6f2b35ef59b0

Fix problem in MemoryPhi creation during FloatingRead, add an assert to detect this kind of problems
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 01 Oct 2012 15:53:03 +0200
parents 41f0849e107b
children ec2211254419
files graal/com.oracle.graal.compiler.phases/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java
diffstat 2 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.phases/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java	Sun Sep 30 21:44:03 2012 +0200
+++ b/graal/com.oracle.graal.compiler.phases/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java	Mon Oct 01 15:53:03 2012 +0200
@@ -102,17 +102,17 @@
                     keys.add(key);
                 }
             }
+            @SuppressWarnings("unchecked")
+            IdentityHashMap<Object, ValueNode> newMemorySnapshot = (IdentityHashMap<Object, ValueNode>) lastMemorySnapshot.clone();
 
             for (Object key : keys) {
                 ValueNode merged = lastMemorySnapshot.get(key);
                 if (merged == null) {
                     merged = lastMemorySnapshot.get(LocationNode.ANY_LOCATION);
                 }
-                Iterator<MemoryMap> it = withStates.iterator();
-                int i = 1;
+                int mergedStatesCount = 1;
                 boolean isPhi = false;
-                while (it.hasNext()) {
-                    MemoryMap other = it.next();
+                for (MemoryMap other : withStates) {
                     ValueNode otherValue = other.lastMemorySnapshot.get(key);
                     if (otherValue == null) {
                         otherValue = other.lastMemorySnapshot.get(LocationNode.ANY_LOCATION);
@@ -121,17 +121,19 @@
                         ((PhiNode) merged).addInput(otherValue);
                     } else if (merged != otherValue) {
                         PhiNode phi = merge.graph().add(new PhiNode(PhiType.Memory, merge));
-                        for (int j = 0; j < i; j++) {
+                        for (int j = 0; j < mergedStatesCount; j++) {
                             phi.addInput(merged);
                         }
                         phi.addInput(otherValue);
                         merged = phi;
                         isPhi = true;
-                        lastMemorySnapshot.put(key, phi);
+                        newMemorySnapshot.put(key, phi);
                     }
-                    i++;
+                    mergedStatesCount++;
                 }
             }
+
+            lastMemorySnapshot = newMemorySnapshot;
             return true;
         }
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java	Sun Sep 30 21:44:03 2012 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java	Mon Oct 01 15:53:03 2012 +0200
@@ -179,6 +179,7 @@
     }
 
     public void addInput(ValueNode x) {
+        assert !(x instanceof PhiNode) || ((PhiNode) x).merge() instanceof LoopBeginNode ||  ((PhiNode) x).merge() != this.merge();
         values.add(x);
     }