changeset 22976:fe8534ad7e6e

TraceRA: TraceGlobalMoveResolutionPhase: proper handling of ShadowedRegisterValue in LabelOp.incoming.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 12 Nov 2015 13:56:55 +0100
parents a55fe96b8e0a
children 913b2001af72
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolver.java
diffstat 2 files changed, 65 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java	Thu Nov 12 14:01:02 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java	Thu Nov 12 13:56:55 2015 +0100
@@ -22,9 +22,11 @@
  */
 package com.oracle.graal.lir.alloc.trace;
 
+import static com.oracle.graal.lir.LIRValueUtil.isStackSlotValue;
 import static com.oracle.graal.lir.alloc.trace.TraceUtil.asShadowedRegisterValue;
 import static com.oracle.graal.lir.alloc.trace.TraceUtil.isShadowedRegisterValue;
 import static jdk.vm.ci.code.ValueUtil.isIllegal;
+import static jdk.vm.ci.code.ValueUtil.isRegister;
 
 import java.util.List;
 
@@ -66,7 +68,41 @@
         TraceGlobalMoveResolver moveResolver = new TraceGlobalMoveResolver(lirGenRes, spillMoveFactory, arch);
         PhiValueVisitor visitor = (Value phiIn, Value phiOut) -> {
             if (!isIllegal(phiIn) && !TraceGlobalMoveResolver.isMoveToSelf(phiOut, phiIn)) {
-                moveResolver.addMapping(getFromValue(phiOut), (AllocatableValue) phiIn);
+                // prepare input/output values.
+                final Value src;
+                final Value srcShadow;
+                if (isShadowedRegisterValue(phiOut)) {
+                    ShadowedRegisterValue phiOutSh = asShadowedRegisterValue(phiOut);
+                    src = phiOutSh.getRegister();
+                    srcShadow = phiOutSh.getStackSlot();
+                } else {
+                    src = phiOut;
+                    srcShadow = null;
+                }
+                assert src != null;
+                assert srcShadow == null || isRegister(src) && isStackSlotValue(srcShadow) : "Unexpected shadowed value: " + phiOut;
+
+                final Value dst;
+                final Value dstShadow;
+                if (isShadowedRegisterValue(phiIn)) {
+                    ShadowedRegisterValue phiInSh = asShadowedRegisterValue(phiIn);
+                    dst = phiInSh.getRegister();
+                    dstShadow = phiInSh.getStackSlot();
+                } else {
+                    dst = phiIn;
+                    dstShadow = null;
+                }
+                assert dst != null;
+                assert dstShadow == null || isRegister(dst) && isStackSlotValue(dstShadow) : "Unexpected shadowed value: " + phiIn;
+
+                // set dst
+                if (!dst.equals(src)) {
+                    moveResolver.addMapping(src, (AllocatableValue) dst);
+                }
+                // set dst_shadow
+                if (dstShadow != null && !dstShadow.equals(src)) {
+                    moveResolver.addMapping(src, (AllocatableValue) dstShadow);
+                }
             }
         };
 
@@ -99,8 +135,4 @@
             }
         }
     }
-
-    private static Value getFromValue(Value from) {
-        return isShadowedRegisterValue(from) ? asShadowedRegisterValue(from).getRegister() : from;
-    }
 }
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolver.java	Thu Nov 12 14:01:02 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolver.java	Thu Nov 12 13:56:55 2015 +0100
@@ -251,14 +251,36 @@
             return false;
         }
         if (isShadowedRegisterValue(from)) {
+            /* From is a shadowed register. */
+            if (isShadowedRegisterValue(to)) {
+                // both shadowed but not equal
+                return false;
+            }
             ShadowedRegisterValue shadowed = asShadowedRegisterValue(from);
-            // TODO(jeisl)if (isStackSlotValue(to)) {
-            // return to.equals(shadowed.getStackSlot());
-            // }
-            if (isRegister(to)) {
-                return asRegister(to).equals(asRegister(shadowed.getRegister()));
+            if (isRegisterToRegisterMoveToSelf(shadowed.getRegister(), to)) {
+                return true;
             }
-        } else if (isRegister(from) && isRegister(to) && asRegister(from).equals(asRegister(to))) {
+            if (isStackSlotValue(to)) {
+                return to.equals(shadowed.getStackSlot());
+            }
+        } else {
+            /*
+             * A shadowed destination value is never a self move it both values are not equal. Fall
+             * through.
+             */
+            // if (isShadowedRegisterValue(to)) return false;
+
+            return isRegisterToRegisterMoveToSelf(from, to);
+        }
+        return false;
+    }
+
+    private static boolean isRegisterToRegisterMoveToSelf(Value from, Value to) {
+        if (to.equals(from)) {
+            return true;
+        }
+        if (isRegister(from) && isRegister(to) && asRegister(from).equals(asRegister(to))) {
+            // Values differ but Registers are the same
             assert LIRKind.verifyMoveKinds(to.getLIRKind(), from.getLIRKind()) : String.format("Same register but Kind mismatch %s <- %s", to, from);
             return true;
         }