changeset 22980:e47e7efd9ec0

TraceRA: rewrite TraceGlobalMoveResolutionPhase.addMapping.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 12 Nov 2015 17:57:09 +0100
parents 9ef376e2e6b6
children f22ae5bade77
files graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java
diffstat 1 files changed, 35 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java	Thu Nov 12 17:24:05 2015 +0100
+++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceGlobalMoveResolutionPhase.java	Thu Nov 12 17:57:09 2015 +0100
@@ -25,12 +25,14 @@
 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.asRegisterValue;
 import static jdk.vm.ci.code.ValueUtil.isIllegal;
 import static jdk.vm.ci.code.ValueUtil.isRegister;
 
 import java.util.List;
 
 import jdk.vm.ci.code.Architecture;
+import jdk.vm.ci.code.RegisterValue;
 import jdk.vm.ci.code.TargetDescription;
 import jdk.vm.ci.meta.AllocatableValue;
 import jdk.vm.ci.meta.Value;
@@ -111,40 +113,46 @@
 
     public static void addMapping(MoveResolver moveResolver, Value from, Value to) {
         assert !isIllegal(to);
-        // prepare input/output values.
-        final Value src;
-        final Value srcShadow;
+        if (isShadowedRegisterValue(to)) {
+            ShadowedRegisterValue toSh = asShadowedRegisterValue(to);
+            addMappingToRegister(moveResolver, from, toSh.getRegister());
+            addMappingToStackSlot(moveResolver, from, toSh.getStackSlot());
+        } else {
+            if (isRegister(to)) {
+                addMappingToRegister(moveResolver, from, asRegisterValue(to));
+            } else {
+                assert isStackSlotValue(to) : "Expected stack slot: " + to;
+                addMappingToStackSlot(moveResolver, from, (AllocatableValue) to);
+            }
+        }
+    }
+
+    private static void addMappingToRegister(MoveResolver moveResolver, Value from, RegisterValue register) {
         if (isShadowedRegisterValue(from)) {
-            ShadowedRegisterValue phiOutSh = asShadowedRegisterValue(from);
-            src = phiOutSh.getRegister();
-            srcShadow = phiOutSh.getStackSlot();
+            RegisterValue fromReg = asShadowedRegisterValue(from).getRegister();
+            checkAndAddMapping(moveResolver, fromReg, register);
         } else {
-            src = from;
-            srcShadow = null;
+            checkAndAddMapping(moveResolver, from, register);
         }
-        assert src != null;
-        assert srcShadow == null || isRegister(src) && isStackSlotValue(srcShadow) : "Unexpected shadowed value: " + from;
+    }
 
-        final Value dst;
-        final Value dstShadow;
-        if (isShadowedRegisterValue(to)) {
-            ShadowedRegisterValue phiInSh = asShadowedRegisterValue(to);
-            dst = phiInSh.getRegister();
-            dstShadow = phiInSh.getStackSlot();
+    private static void addMappingToStackSlot(MoveResolver moveResolver, Value from, AllocatableValue stack) {
+        if (isShadowedRegisterValue(from)) {
+            ShadowedRegisterValue shadowedFrom = asShadowedRegisterValue(from);
+            RegisterValue fromReg = shadowedFrom.getRegister();
+            AllocatableValue fromStack = shadowedFrom.getStackSlot();
+            if (!fromStack.equals(stack)) {
+                checkAndAddMapping(moveResolver, fromReg, stack);
+            }
         } else {
-            dst = to;
-            dstShadow = null;
+            checkAndAddMapping(moveResolver, from, stack);
         }
-        assert dst != null;
-        assert dstShadow == null || isRegister(dst) && isStackSlotValue(dstShadow) : "Unexpected shadowed value: " + to;
 
-        // set dst
-        if (!dst.equals(src)) {
-            moveResolver.addMapping(src, (AllocatableValue) dst);
-        }
-        // set dst_shadow
-        if (dstShadow != null && !dstShadow.equals(src) && !dstShadow.equals(srcShadow)) {
-            moveResolver.addMapping(src, (AllocatableValue) dstShadow);
+    }
+
+    private static void checkAndAddMapping(MoveResolver moveResolver, Value from, AllocatableValue to) {
+        if (!from.equals(to)) {
+            moveResolver.addMapping(from, to);
         }
     }
 }