JIT: Source code reorganization to isolate target independent code

Much of the register utility code is target independent.  Move it up
a level so the x86 JIT can use it.

Change-Id: Id9895a42281fd836cb1a2c942e106de94df62a9a
diff --git a/vm/Dvm.mk b/vm/Dvm.mk
index ae69333..3854c5d 100644
--- a/vm/Dvm.mk
+++ b/vm/Dvm.mk
@@ -276,13 +276,14 @@
 
   ifeq ($(WITH_JIT),true)
     LOCAL_SRC_FILES += \
-		compiler/codegen/arm/RallocUtil.c \
+		compiler/codegen/RallocUtil.c \
 		compiler/codegen/arm/$(dvm_arch_variant)/Codegen.c \
 		compiler/codegen/arm/$(dvm_arch_variant)/CallingConvention.S \
 		compiler/codegen/arm/Assemble.c \
 		compiler/codegen/arm/ArchUtility.c \
 		compiler/codegen/arm/LocalOptimizations.c \
 		compiler/codegen/arm/GlobalOptimizations.c \
+		compiler/codegen/arm/ArmRallocUtil.c \
 		compiler/template/out/CompilerTemplateAsm-$(dvm_arch_variant).S
   endif
 endif
diff --git a/vm/compiler/codegen/arm/Ralloc.h b/vm/compiler/codegen/Ralloc.h
similarity index 86%
rename from vm/compiler/codegen/arm/Ralloc.h
rename to vm/compiler/codegen/Ralloc.h
index cc3e605..2296fbc 100644
--- a/vm/compiler/codegen/arm/Ralloc.h
+++ b/vm/compiler/codegen/Ralloc.h
@@ -15,11 +15,7 @@
  */
 
 /*
- * This file contains register alloction support and is intended to be
- * included by:
- *
- *        Codegen-$(TARGET_ARCH_VARIANT).c
- *
+ * This file contains target independent register alloction support.
  */
 
 #include "compiler/CompilerUtility.h"
@@ -203,4 +199,28 @@
 
 extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit);
 
-extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
+extern void dvmCompilerFlushRegWide(CompilationUnit *cUnit, int reg1, int reg2);
+
+extern void dvmCompilerFlushReg(CompilationUnit *cUnit, int reg);
+
+/*
+ * Architecture-dependent register allocation routines implemented in
+ * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c
+ */
+extern int dvmCompilerAllocTypedTempPair(CompilationUnit *cUnit,
+                                         bool fpHint, int regClass);
+
+extern int dvmCompilerAllocTypedTemp(CompilationUnit *cUnit, bool fpHint,
+                                     int regClass);
+
+extern ArmLIR* dvmCompilerRegCopy(CompilationUnit *cUnit, int rDest, int rSrc);
+
+extern void dvmCompilerRegCopyWide(CompilationUnit *cUnit, int destLo,
+                                   int destHi, int srcLo, int srcHi);
+
+extern void dvmCompilerFlushRegImpl(CompilationUnit *cUnit, int rBase,
+                                    int displacement, int rSrc, OpSize size);
+
+extern void dvmCompilerFlushRegWideImpl(CompilationUnit *cUnit, int rBase,
+                                        int displacement, int rSrcLo,
+                                        int rSrcHi);
diff --git a/vm/compiler/codegen/arm/RallocUtil.c b/vm/compiler/codegen/RallocUtil.c
similarity index 88%
rename from vm/compiler/codegen/arm/RallocUtil.c
rename to vm/compiler/codegen/RallocUtil.c
index ff5d16b..32977eb 100644
--- a/vm/compiler/codegen/arm/RallocUtil.c
+++ b/vm/compiler/codegen/RallocUtil.c
@@ -25,33 +25,8 @@
 #include "compiler/CompilerUtility.h"
 #include "compiler/CompilerIR.h"
 #include "compiler/Dataflow.h"
-#include "ArmLIR.h"
-#include "Codegen.h"
 #include "Ralloc.h"
 
-/*
- * Register usage for 16-bit Thumb systems:
- *     r0-r3: Temp/argument
- *     lr(r14):      Temp for translations, return address for handlers
- *     rGLUE(r6):    Pointer to InterpState
- *     rFP(r5):      Dalvik frame pointer
- *     r4, r7:       Temp for translations
- *     r8, r9, r10:   Temp preserved across C calls
- *     r11, ip(r12):  Temp not preserved across C calls
- *
- * Register usage for 32-bit Thumb systems:
- *     r0-r3: Temp/argument
- *     lr(r14):      Temp for translations, return address for handlers
- *     rGLUE(r6):    Pointer to InterpState
- *     rFP(r5):      Dalvik frame pointer
- *     r4, r7:       Temp for translations
- *     r8, r9, r10   Temp preserved across C calls
- *     r11, ip(r12):      Temp not preserved across C calls
- *     fp0-fp15:     Hot temps, not preserved across C calls
- *     fp16-fp31:    Promotion pool
- *
- */
-
 #define SREG(c, s) ((c)->regLocation[(s)].sRegLow)
 /*
  * Get the "real" sreg number associated with an sReg slot.  In general,
@@ -127,7 +102,7 @@
     return NULL;
 }
 
-static void flushRegWide(CompilationUnit *cUnit, int reg1, int reg2)
+void dvmCompilerFlushRegWide(CompilationUnit *cUnit, int reg1, int reg2)
 {
     RegisterInfo *info1 = getRegInfo(cUnit, reg1);
     RegisterInfo *info2 = getRegInfo(cUnit, reg2);
@@ -146,7 +121,7 @@
     }
 }
 
-static void flushReg(CompilationUnit *cUnit, int reg)
+void dvmCompilerFlushReg(CompilationUnit *cUnit, int reg)
 {
     RegisterInfo *info = getRegInfo(cUnit, reg);
     if (info->live && info->dirty) {
@@ -166,9 +141,9 @@
         if (p[i].reg == reg) {
             if (p[i].live && p[i].dirty) {
                 if (p[i].pair) {
-                    flushRegWide(cUnit, p[i].reg, p[i].partner);
+                    dvmCompilerFlushRegWide(cUnit, p[i].reg, p[i].partner);
                 } else {
-                    flushReg(cUnit, p[i].reg);
+                    dvmCompilerFlushReg(cUnit, p[i].reg);
                 }
             }
             p[i].live = false;
@@ -463,31 +438,6 @@
     dvmCompilerAbort(cUnit);
 }
 
-/* Clobber all regs that might be used by an external C call */
-extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit)
-{
-    dvmCompilerClobber(cUnit, r0);
-    dvmCompilerClobber(cUnit, r1);
-    dvmCompilerClobber(cUnit, r2);
-    dvmCompilerClobber(cUnit, r3);
-    dvmCompilerClobber(cUnit, r9); // Need to do this?, be conservative
-    dvmCompilerClobber(cUnit, r11);
-    dvmCompilerClobber(cUnit, r12);
-    dvmCompilerClobber(cUnit, rlr);
-}
-
-/* Clobber all of the temps that might be used by a handler. */
-extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit)
-{
-    //TUNING: reduce the set of regs used by handlers.  Only a few need lots.
-    dvmCompilerClobberCallRegs(cUnit);
-    dvmCompilerClobber(cUnit, r4PC);
-    dvmCompilerClobber(cUnit, r7);
-    dvmCompilerClobber(cUnit, r8);
-    dvmCompilerClobber(cUnit, r9);
-    dvmCompilerClobber(cUnit, r10);
-}
-
 extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg)
 {
     RegisterInfo *p = getRegInfo(cUnit, reg);
@@ -638,9 +588,9 @@
     for (i=0; i < numRegs; i++) {
         if (info[i].live && info[i].dirty) {
             if (info[i].pair) {
-                flushRegWide(cUnit, info[i].reg, info[i].partner);
+                dvmCompilerFlushRegWide(cUnit, info[i].reg, info[i].partner);
             } else {
-                flushReg(cUnit, info[i].reg);
+                dvmCompilerFlushReg(cUnit, info[i].reg);
             }
         }
     }
@@ -942,47 +892,6 @@
     return getLocWide(cUnit, mir, low, high, true);
 }
 
-extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit)
-{
-    RegLocation res = LOC_C_RETURN_WIDE;
-    dvmCompilerClobber(cUnit, r0);
-    dvmCompilerClobber(cUnit, r1);
-    dvmCompilerMarkInUse(cUnit, r0);
-    dvmCompilerMarkInUse(cUnit, r1);
-    dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg);
-    return res;
-}
-
-extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit)
-{
-    RegLocation res = LOC_C_RETURN_WIDE;
-    res.lowReg = r2;
-    res.highReg = r3;
-    dvmCompilerClobber(cUnit, r2);
-    dvmCompilerClobber(cUnit, r3);
-    dvmCompilerMarkInUse(cUnit, r2);
-    dvmCompilerMarkInUse(cUnit, r3);
-    dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg);
-    return res;
-}
-
-extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit)
-{
-    RegLocation res = LOC_C_RETURN;
-    dvmCompilerClobber(cUnit, r0);
-    dvmCompilerMarkInUse(cUnit, r0);
-    return res;
-}
-
-extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit)
-{
-    RegLocation res = LOC_C_RETURN;
-    res.lowReg = r1;
-    dvmCompilerClobber(cUnit, r1);
-    dvmCompilerMarkInUse(cUnit, r1);
-    return res;
-}
-
 /* Kill the corresponding bit in the null-checked register list */
 extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit,
                                           RegLocation loc)
@@ -997,14 +906,3 @@
         }
     }
 }
-
-extern void dvmCompilerFlushRegWideForV5TEVFP(CompilationUnit *cUnit,
-                                              int reg1, int reg2)
-{
-    flushRegWide(cUnit, reg1, reg2);
-}
-
-extern void dvmCompilerFlushRegForV5TEVFP(CompilationUnit *cUnit, int reg)
-{
-    flushReg(cUnit, reg);
-}
diff --git a/vm/compiler/codegen/arm/ArmRallocUtil.c b/vm/compiler/codegen/arm/ArmRallocUtil.c
new file mode 100644
index 0000000..bc643c1
--- /dev/null
+++ b/vm/compiler/codegen/arm/ArmRallocUtil.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file contains Arm-specific register alloction support.
+ */
+
+#include "compiler/CompilerUtility.h"
+#include "compiler/CompilerIR.h"
+#include "compiler/Dataflow.h"
+#include "ArmLIR.h"
+#include "Codegen.h"
+#include "compiler/codegen/Ralloc.h"
+
+/*
+ * Register usage for 16-bit Thumb systems:
+ *     r0-r3: Temp/argument
+ *     lr(r14):      Temp for translations, return address for handlers
+ *     rGLUE(r6):    Pointer to InterpState
+ *     rFP(r5):      Dalvik frame pointer
+ *     r4, r7:       Temp for translations
+ *     r8, r9, r10:   Temp preserved across C calls
+ *     r11, ip(r12):  Temp not preserved across C calls
+ *
+ * Register usage for 32-bit Thumb systems:
+ *     r0-r3: Temp/argument
+ *     lr(r14):      Temp for translations, return address for handlers
+ *     rGLUE(r6):    Pointer to InterpState
+ *     rFP(r5):      Dalvik frame pointer
+ *     r4, r7:       Temp for translations
+ *     r8, r9, r10   Temp preserved across C calls
+ *     r11, ip(r12):      Temp not preserved across C calls
+ *     fp0-fp15:     Hot temps, not preserved across C calls
+ *     fp16-fp31:    Promotion pool
+ *
+ */
+
+/* Clobber all regs that might be used by an external C call */
+extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit)
+{
+    dvmCompilerClobber(cUnit, r0);
+    dvmCompilerClobber(cUnit, r1);
+    dvmCompilerClobber(cUnit, r2);
+    dvmCompilerClobber(cUnit, r3);
+    dvmCompilerClobber(cUnit, r9); // Need to do this?, be conservative
+    dvmCompilerClobber(cUnit, r11);
+    dvmCompilerClobber(cUnit, r12);
+    dvmCompilerClobber(cUnit, rlr);
+}
+
+/* Clobber all of the temps that might be used by a handler. */
+extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit)
+{
+    //TUNING: reduce the set of regs used by handlers.  Only a few need lots.
+    dvmCompilerClobberCallRegs(cUnit);
+    dvmCompilerClobber(cUnit, r4PC);
+    dvmCompilerClobber(cUnit, r7);
+    dvmCompilerClobber(cUnit, r8);
+    dvmCompilerClobber(cUnit, r9);
+    dvmCompilerClobber(cUnit, r10);
+}
+
+extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit)
+{
+    RegLocation res = LOC_C_RETURN_WIDE;
+    dvmCompilerClobber(cUnit, r0);
+    dvmCompilerClobber(cUnit, r1);
+    dvmCompilerMarkInUse(cUnit, r0);
+    dvmCompilerMarkInUse(cUnit, r1);
+    dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg);
+    return res;
+}
+
+extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit)
+{
+    RegLocation res = LOC_C_RETURN_WIDE;
+    res.lowReg = r2;
+    res.highReg = r3;
+    dvmCompilerClobber(cUnit, r2);
+    dvmCompilerClobber(cUnit, r3);
+    dvmCompilerMarkInUse(cUnit, r2);
+    dvmCompilerMarkInUse(cUnit, r3);
+    dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg);
+    return res;
+}
+
+extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit)
+{
+    RegLocation res = LOC_C_RETURN;
+    dvmCompilerClobber(cUnit, r0);
+    dvmCompilerMarkInUse(cUnit, r0);
+    return res;
+}
+
+extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit)
+{
+    RegLocation res = LOC_C_RETURN;
+    res.lowReg = r1;
+    dvmCompilerClobber(cUnit, r1);
+    dvmCompilerMarkInUse(cUnit, r1);
+    return res;
+}
diff --git a/vm/compiler/codegen/arm/Codegen.h b/vm/compiler/codegen/arm/Codegen.h
index be74e3f..8522e62 100644
--- a/vm/compiler/codegen/arm/Codegen.h
+++ b/vm/compiler/codegen/arm/Codegen.h
@@ -60,29 +60,7 @@
 void dvmSelfVerificationMemOpDecode(int lr, int* sp);
 #endif
 
-/*
- * Architecture-dependent register allocation routines implemented in
- * Thumb[2]/Ralloc.c
- */
-extern int dvmCompilerAllocTypedTempPair(CompilationUnit *cUnit,
-                                         bool fpHint, int regClass);
-
-extern int dvmCompilerAllocTypedTemp(CompilationUnit *cUnit, bool fpHint,
-                                     int regClass);
+extern void dvmCompilerSetupResourceMasks(ArmLIR *lir);
 
 extern ArmLIR* dvmCompilerRegCopyNoInsert(CompilationUnit *cUnit, int rDest,
                                           int rSrc);
-
-extern ArmLIR* dvmCompilerRegCopy(CompilationUnit *cUnit, int rDest, int rSrc);
-
-extern void dvmCompilerRegCopyWide(CompilationUnit *cUnit, int destLo,
-                                   int destHi, int srcLo, int srcHi);
-
-extern void dvmCompilerSetupResourceMasks(ArmLIR *lir);
-
-extern void dvmCompilerFlushRegImpl(CompilationUnit *cUnit, int rBase,
-                                    int displacement, int rSrc, OpSize size);
-
-extern void dvmCompilerFlushRegWideImpl(CompilationUnit *cUnit, int rBase,
-                                        int displacement, int rSrcLo,
-                                        int rSrcHi);
diff --git a/vm/compiler/codegen/arm/FP/ThumbVFP.c b/vm/compiler/codegen/arm/FP/ThumbVFP.c
index 16d3ff7..db940b0 100644
--- a/vm/compiler/codegen/arm/FP/ThumbVFP.c
+++ b/vm/compiler/codegen/arm/FP/ThumbVFP.c
@@ -19,10 +19,6 @@
  * variant-specific code.
  */
 
-extern void dvmCompilerFlushRegWideForV5TEVFP(CompilationUnit *cUnit,
-                                              int reg1, int reg2);
-extern void dvmCompilerFlushRegForV5TEVFP(CompilationUnit *cUnit, int reg);
-
 /*
  * Take the address of a Dalvik register and store it into rDest.
  * Clobber any live values associated either with the Dalvik value
@@ -35,10 +31,9 @@
                           dvmCompilerUpdateLoc(cUnit, rlSrc);
      if (rlSrc.location == kLocPhysReg) {
          if (rlSrc.wide) {
-             dvmCompilerFlushRegWideForV5TEVFP(cUnit, rlSrc.lowReg,
-                                               rlSrc.highReg);
+             dvmCompilerFlushRegWide(cUnit, rlSrc.lowReg, rlSrc.highReg);
          } else {
-             dvmCompilerFlushRegForV5TEVFP(cUnit, rlSrc.lowReg);
+             dvmCompilerFlushReg(cUnit, rlSrc.lowReg);
          }
      }
      dvmCompilerClobber(cUnit, rDest);
diff --git a/vm/compiler/codegen/arm/armv5te-vfp/Codegen.c b/vm/compiler/codegen/arm/armv5te-vfp/Codegen.c
index eda243f..2554754 100644
--- a/vm/compiler/codegen/arm/armv5te-vfp/Codegen.c
+++ b/vm/compiler/codegen/arm/armv5te-vfp/Codegen.c
@@ -23,7 +23,7 @@
 #include "compiler/CompilerInternals.h"
 #include "compiler/codegen/arm/ArmLIR.h"
 #include "mterp/common/FindInterface.h"
-#include "compiler/codegen/arm/Ralloc.h"
+#include "compiler/codegen/Ralloc.h"
 #include "compiler/codegen/arm/Codegen.h"
 #include "compiler/Loop.h"
 #include "ArchVariant.h"
diff --git a/vm/compiler/codegen/arm/armv5te/Codegen.c b/vm/compiler/codegen/arm/armv5te/Codegen.c
index f953390..37d7028 100644
--- a/vm/compiler/codegen/arm/armv5te/Codegen.c
+++ b/vm/compiler/codegen/arm/armv5te/Codegen.c
@@ -23,7 +23,7 @@
 #include "compiler/CompilerInternals.h"
 #include "compiler/codegen/arm/ArmLIR.h"
 #include "mterp/common/FindInterface.h"
-#include "compiler/codegen/arm/Ralloc.h"
+#include "compiler/codegen/Ralloc.h"
 #include "compiler/codegen/arm/Codegen.h"
 #include "compiler/Loop.h"
 #include "ArchVariant.h"
diff --git a/vm/compiler/codegen/arm/armv7-a-neon/Codegen.c b/vm/compiler/codegen/arm/armv7-a-neon/Codegen.c
index 1edc25b..2cf8e53 100644
--- a/vm/compiler/codegen/arm/armv7-a-neon/Codegen.c
+++ b/vm/compiler/codegen/arm/armv7-a-neon/Codegen.c
@@ -23,7 +23,7 @@
 #include "compiler/CompilerInternals.h"
 #include "compiler/codegen/arm/ArmLIR.h"
 #include "mterp/common/FindInterface.h"
-#include "compiler/codegen/arm/Ralloc.h"
+#include "compiler/codegen/Ralloc.h"
 #include "compiler/codegen/arm/Codegen.h"
 #include "compiler/Loop.h"
 #include "ArchVariant.h"
diff --git a/vm/compiler/codegen/arm/armv7-a/Codegen.c b/vm/compiler/codegen/arm/armv7-a/Codegen.c
index 1514d55..14d923f 100644
--- a/vm/compiler/codegen/arm/armv7-a/Codegen.c
+++ b/vm/compiler/codegen/arm/armv7-a/Codegen.c
@@ -23,7 +23,7 @@
 #include "compiler/CompilerInternals.h"
 #include "compiler/codegen/arm/ArmLIR.h"
 #include "mterp/common/FindInterface.h"
-#include "compiler/codegen/arm/Ralloc.h"
+#include "compiler/codegen/Ralloc.h"
 #include "compiler/codegen/arm/Codegen.h"
 #include "compiler/Loop.h"
 #include "ArchVariant.h"