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/SSATransformation.cc b/src/compiler/SSATransformation.cc
index 95f6db5..dea1971 100644
--- a/src/compiler/SSATransformation.cc
+++ b/src/compiler/SSATransformation.cc
@@ -548,6 +548,48 @@
     return true;
 }
 
+static void doDFSPreOrderSSARename(CompilationUnit* cUnit, BasicBlock* block)
+{
+
+    if (block->visited || block->hidden) return;
+    block->visited = true;
+
+    /* Process this block */
+    oatDoSSAConversion(cUnit, block);
+    int mapSize = sizeof(int) * cUnit->method->NumRegisters();
+
+    /* Save SSA map snapshot */
+    int* savedSSAMap = (int*)oatNew(mapSize, false);
+    memcpy(savedSSAMap, cUnit->dalvikToSSAMap, mapSize);
+
+    if (block->fallThrough) {
+        doDFSPreOrderSSARename(cUnit, block->fallThrough);
+        /* Restore SSA map snapshot */
+        memcpy(cUnit->dalvikToSSAMap, savedSSAMap, mapSize);
+    }
+    if (block->taken) {
+        doDFSPreOrderSSARename(cUnit, block->taken);
+        /* Restore SSA map snapshot */
+        memcpy(cUnit->dalvikToSSAMap, savedSSAMap, mapSize);
+    }
+    if (block->successorBlockList.blockListType != kNotUsed) {
+        GrowableListIterator iterator;
+        oatGrowableListIteratorInit(&block->successorBlockList.blocks,
+                                    &iterator);
+        while (true) {
+            SuccessorBlockInfo *successorBlockInfo =
+                (SuccessorBlockInfo *) oatGrowableListIteratorNext(&iterator);
+            if (successorBlockInfo == NULL) break;
+            BasicBlock* succBB = successorBlockInfo->block;
+            doDFSPreOrderSSARename(cUnit, succBB);
+            /* Restore SSA map snapshot */
+            memcpy(cUnit->dalvikToSSAMap, savedSSAMap, mapSize);
+        }
+    }
+    cUnit->dalvikToSSAMap = savedSSAMap;
+    return;
+}
+
 /* Perform SSA transformation for the whole method */
 void oatMethodSSATransformation(CompilationUnit* cUnit)
 {
@@ -567,9 +609,10 @@
     insertPhiNodes(cUnit);
 
     /* Rename register names by local defs and phi nodes */
-    oatDataFlowAnalysisDispatcher(cUnit, oatDoSSAConversion,
-                                          kPreOrderDFSTraversal,
+    oatDataFlowAnalysisDispatcher(cUnit, oatClearVisitedFlag,
+                                          kAllNodes,
                                           false /* isIterative */);
+    doDFSPreOrderSSARename(cUnit, cUnit->entryBlock);
 
     /*
      * Shared temp bit vector used by each block to count the number of defs