SSA renaming fix & invalid opcode fix

The old SSA renaming mechanism was able to take some shortcuts because
of the limited CFG shapes it encountered.  Shortcut replaced and previous
workaround code removed.

Also fixes a regression introduced by the stack bounds checking change
which sometimes resulted in an (opcode < 0x200) assert failure, and
removes an optimization flag and associated code that no longer applicable.

Change-Id: I617e9e5347dfd3a7e8f44a9772647bf4530631d6
diff --git a/src/compiler/Dataflow.cc b/src/compiler/Dataflow.cc
index 06f942f..3369e9e 100644
--- a/src/compiler/Dataflow.cc
+++ b/src/compiler/Dataflow.cc
@@ -1931,10 +1931,9 @@
 static void handleSSADef(CompilationUnit* cUnit, int* defs, int dalvikReg,
                          int regIndex)
 {
-    int encodedValue = cUnit->dalvikToSSAMap[dalvikReg];
     int ssaReg = cUnit->numSSARegs++;
     /* Bump up the subscript */
-    int dalvikSub = DECODE_SUB(encodedValue) + 1;
+    int dalvikSub = ++cUnit->SSALastDefs[dalvikReg];
     int newD2SMapping = ENCODE_REG_SUB(ssaReg, dalvikSub);
 
     cUnit->dalvikToSSAMap[dalvikReg] = newD2SMapping;
@@ -1982,6 +1981,10 @@
 
     if (bb->dataFlowInfo == NULL) return false;
 
+    if (cUnit->printMeVerbose) {
+        LOG(INFO) << "oatDoSSAConversion processing block " << bb->id;
+    }
+
     for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
         mir->ssaRep = (struct SSARepresentation *)
             oatNew(sizeof(SSARepresentation), true);
@@ -1989,14 +1992,17 @@
         int dfAttributes =
             oatDataFlowAttributes[mir->dalvikInsn.opcode];
 
-        int flags = dexGetFlagsFromOpcode(mir->dalvikInsn.opcode);
+        // If not a pseudo-op, note non-leaf or can throw
+        if (mir->dalvikInsn.opcode < kNumPackedOpcodes) {
+            int flags = dexGetFlagsFromOpcode(mir->dalvikInsn.opcode);
 
-        if (flags & kInstrCanThrow) {
-            cUnit->attrs &= ~METHOD_IS_THROW_FREE;
-        }
+            if (flags & kInstrCanThrow) {
+                cUnit->attrs &= ~METHOD_IS_THROW_FREE;
+            }
 
-        if (flags & kInstrInvoke) {
-            cUnit->attrs &= ~METHOD_IS_LEAF;
+            if (flags & kInstrInvoke) {
+                cUnit->attrs &= ~METHOD_IS_LEAF;
+            }
         }
 
         int numUses = 0;
@@ -2222,8 +2228,13 @@
      */
     cUnit->dalvikToSSAMap = (int *)oatNew(sizeof(int) * numDalvikReg,
                                                   false);
+    /* Keep track of the higest def for each dalvik reg */
+    cUnit->SSALastDefs = (int *)oatNew(sizeof(int) * numDalvikReg,
+                                                  false);
+
     for (i = 0; i < numDalvikReg; i++) {
         cUnit->dalvikToSSAMap[i] = i;
+        cUnit->SSALastDefs[i] = 0;
     }
 
     /*