Revert "Revert "Refactor HGraphBuilder and SsaBuilder to remove HLocals""

This patch merges the instruction-building phases from HGraphBuilder
and SsaBuilder into a single HInstructionBuilder class. As a result,
it is not necessary to generate HLocal, HLoadLocal and HStoreLocal
instructions any more, as the builder produces SSA form directly.

Saves 5-15% of arena-allocated memory (see bug for more data):
  GMS      20.46MB  =>  19.26MB  (-5.86%)
  Maps     24.12MB  =>  21.47MB  (-10.98%)
  YouTube  28.60MB  =>  26.01MB  (-9.05%)

This CL fixed an issue with parsing quickened instructions.

Bug: 27894376
Bug: 27998571
Bug: 27995065

Change-Id: I20dbe1bf2d0fe296377478db98cb86cba695e694
diff --git a/compiler/optimizing/constant_folding_test.cc b/compiler/optimizing/constant_folding_test.cc
index b9081cb..d1a2a26 100644
--- a/compiler/optimizing/constant_folding_test.cc
+++ b/compiler/optimizing/constant_folding_test.cc
@@ -111,21 +111,21 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  4: IntConstant [7]\n"
-      "  2: SuspendCheck\n"
-      "  3: Goto 1\n"
+      "  2: IntConstant [3]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  7: Neg(4) [10]\n"
-      "  10: Return(7)\n"
+      "  3: Neg(2) [4]\n"
+      "  4: Return(3)\n"
       "BasicBlock 2, pred: 1\n"
-      "  11: Exit\n";
+      "  5: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  4: IntConstant [7]\n", "  4: IntConstant\n"
-                                "  12: IntConstant [10]\n" },
-    { "  7: Neg(4) [10]\n",     removed },
-    { "  10: Return(7)\n",      "  10: Return(12)\n" }
+    { "  2: IntConstant [3]\n", "  2: IntConstant\n"
+                                "  6: IntConstant [4]\n" },
+    { "  3: Neg(2) [4]\n",      removed },
+    { "  4: Return(3)\n",       "  4: Return(6)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -138,7 +138,7 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
-    { "  4: IntConstant\n", removed },
+    { "  2: IntConstant\n", removed },
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -172,21 +172,21 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  6: LongConstant [9]\n"
-      "  4: SuspendCheck\n"
-      "  5: Goto 1\n"
+      "  2: LongConstant [3]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  9: Neg(6) [12]\n"
-      "  12: Return(9)\n"
+      "  3: Neg(2) [4]\n"
+      "  4: Return(3)\n"
       "BasicBlock 2, pred: 1\n"
-      "  13: Exit\n";
+      "  5: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  6: LongConstant [9]\n", "  6: LongConstant\n"
-                                 "  14: LongConstant [12]\n" },
-    { "  9: Neg(6) [12]\n",      removed },
-    { "  12: Return(9)\n",       "  12: Return(14)\n" }
+    { "  2: LongConstant [3]\n", "  2: LongConstant\n"
+                                 "  6: LongConstant [4]\n" },
+    { "  3: Neg(2) [4]\n",       removed },
+    { "  4: Return(3)\n",        "  4: Return(6)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -199,7 +199,7 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
-    { "  6: LongConstant\n", removed },
+    { "  2: LongConstant\n", removed },
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -231,23 +231,23 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  5: IntConstant [11]\n"
-      "  7: IntConstant [11]\n"
-      "  3: SuspendCheck\n"
-      "  4: Goto 1\n"
+      "  2: IntConstant [4]\n"
+      "  3: IntConstant [4]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  11: Add(5, 7) [14]\n"
-      "  14: Return(11)\n"
+      "  4: Add(2, 3) [5]\n"
+      "  5: Return(4)\n"
       "BasicBlock 2, pred: 1\n"
-      "  15: Exit\n";
+      "  6: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  5: IntConstant [11]\n", "  5: IntConstant\n" },
-    { "  7: IntConstant [11]\n", "  7: IntConstant\n"
-                                 "  16: IntConstant [14]\n" },
-    { "  11: Add(5, 7) [14]\n",  removed },
-    { "  14: Return(11)\n",      "  14: Return(16)\n" }
+    { "  2: IntConstant [4]\n", "  2: IntConstant\n" },
+    { "  3: IntConstant [4]\n", "  3: IntConstant\n"
+                                "  7: IntConstant [5]\n" },
+    { "  4: Add(2, 3) [5]\n",   removed },
+    { "  5: Return(4)\n",       "  5: Return(7)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -260,8 +260,8 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
-    { "  5: IntConstant\n", removed },
-    { "  7: IntConstant\n", removed }
+    { "  2: IntConstant\n", removed },
+    { "  3: IntConstant\n", removed }
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -300,33 +300,33 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  5: IntConstant [11]\n"
-      "  7: IntConstant [11]\n"
-      "  13: IntConstant [19]\n"
-      "  15: IntConstant [19]\n"
-      "  3: SuspendCheck\n"
-      "  4: Goto 1\n"
+      "  2: IntConstant [4]\n"
+      "  3: IntConstant [4]\n"
+      "  5: IntConstant [7]\n"
+      "  6: IntConstant [7]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  11: Add(5, 7) [23]\n"
-      "  19: Add(13, 15) [23]\n"
-      "  23: Add(11, 19) [26]\n"
-      "  26: Return(23)\n"
+      "  4: Add(2, 3) [8]\n"
+      "  7: Add(5, 6) [8]\n"
+      "  8: Add(4, 7) [9]\n"
+      "  9: Return(8)\n"
       "BasicBlock 2, pred: 1\n"
-      "  27: Exit\n";
+      "  10: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  5: IntConstant [11]\n",  "  5: IntConstant\n" },
-    { "  7: IntConstant [11]\n",  "  7: IntConstant\n" },
-    { "  13: IntConstant [19]\n", "  13: IntConstant\n" },
-    { "  15: IntConstant [19]\n", "  15: IntConstant\n"
-                                  "  28: IntConstant\n"
-                                  "  29: IntConstant\n"
-                                  "  30: IntConstant [26]\n" },
-    { "  11: Add(5, 7) [23]\n",   removed },
-    { "  19: Add(13, 15) [23]\n", removed },
-    { "  23: Add(11, 19) [26]\n", removed  },
-    { "  26: Return(23)\n",       "  26: Return(30)\n" }
+    { "  2: IntConstant [4]\n",  "  2: IntConstant\n" },
+    { "  3: IntConstant [4]\n",  "  3: IntConstant\n" },
+    { "  5: IntConstant [7]\n",  "  5: IntConstant\n" },
+    { "  6: IntConstant [7]\n",  "  6: IntConstant\n"
+                                 "  11: IntConstant\n"
+                                 "  12: IntConstant\n"
+                                 "  13: IntConstant [9]\n" },
+    { "  4: Add(2, 3) [8]\n",    removed },
+    { "  7: Add(5, 6) [8]\n",    removed },
+    { "  8: Add(4, 7) [9]\n",    removed  },
+    { "  9: Return(8)\n",        "  9: Return(13)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -345,12 +345,12 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
+    { "  2: IntConstant\n",  removed },
+    { "  3: IntConstant\n",  removed },
     { "  5: IntConstant\n",  removed },
-    { "  7: IntConstant\n",  removed },
-    { "  13: IntConstant\n", removed },
-    { "  15: IntConstant\n", removed },
-    { "  28: IntConstant\n", removed },
-    { "  29: IntConstant\n", removed }
+    { "  6: IntConstant\n",  removed },
+    { "  11: IntConstant\n", removed },
+    { "  12: IntConstant\n", removed }
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -381,23 +381,23 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  5: IntConstant [11]\n"
-      "  7: IntConstant [11]\n"
-      "  3: SuspendCheck\n"
-      "  4: Goto 1\n"
+      "  2: IntConstant [4]\n"
+      "  3: IntConstant [4]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  11: Sub(5, 7) [14]\n"
-      "  14: Return(11)\n"
+      "  4: Sub(2, 3) [5]\n"
+      "  5: Return(4)\n"
       "BasicBlock 2, pred: 1\n"
-      "  15: Exit\n";
+      "  6: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  5: IntConstant [11]\n", "  5: IntConstant\n" },
-    { "  7: IntConstant [11]\n", "  7: IntConstant\n"
-                                 "  16: IntConstant [14]\n" },
-    { "  11: Sub(5, 7) [14]\n",  removed },
-    { "  14: Return(11)\n",      "  14: Return(16)\n" }
+    { "  2: IntConstant [4]\n",  "  2: IntConstant\n" },
+    { "  3: IntConstant [4]\n",  "  3: IntConstant\n"
+                                 "  7: IntConstant [5]\n" },
+    { "  4: Sub(2, 3) [5]\n",    removed },
+    { "  5: Return(4)\n",        "  5: Return(7)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -410,8 +410,8 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
-    { "  5: IntConstant\n", removed },
-    { "  7: IntConstant\n", removed }
+    { "  2: IntConstant\n", removed },
+    { "  3: IntConstant\n", removed }
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -444,23 +444,23 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  8: LongConstant [14]\n"
-      "  10: LongConstant [14]\n"
-      "  6: SuspendCheck\n"
-      "  7: Goto 1\n"
+      "  2: LongConstant [4]\n"
+      "  3: LongConstant [4]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  14: Add(8, 10) [17]\n"
-      "  17: Return(14)\n"
+      "  4: Add(2, 3) [5]\n"
+      "  5: Return(4)\n"
       "BasicBlock 2, pred: 1\n"
-      "  18: Exit\n";
+      "  6: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  8: LongConstant [14]\n",  "  8: LongConstant\n" },
-    { "  10: LongConstant [14]\n", "  10: LongConstant\n"
-                                   "  19: LongConstant [17]\n" },
-    { "  14: Add(8, 10) [17]\n",   removed },
-    { "  17: Return(14)\n",        "  17: Return(19)\n" }
+    { "  2: LongConstant [4]\n",  "  2: LongConstant\n" },
+    { "  3: LongConstant [4]\n",  "  3: LongConstant\n"
+                                  "  7: LongConstant [5]\n" },
+    { "  4: Add(2, 3) [5]\n",     removed },
+    { "  5: Return(4)\n",         "  5: Return(7)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -473,8 +473,8 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
-    { "  8: LongConstant\n", removed },
-    { "  10: LongConstant\n", removed }
+    { "  2: LongConstant\n", removed },
+    { "  3: LongConstant\n", removed }
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -508,23 +508,23 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  8: LongConstant [14]\n"
-      "  10: LongConstant [14]\n"
-      "  6: SuspendCheck\n"
-      "  7: Goto 1\n"
+      "  2: LongConstant [4]\n"
+      "  3: LongConstant [4]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 2\n"
-      "  14: Sub(8, 10) [17]\n"
-      "  17: Return(14)\n"
+      "  4: Sub(2, 3) [5]\n"
+      "  5: Return(4)\n"
       "BasicBlock 2, pred: 1\n"
-      "  18: Exit\n";
+      "  6: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  8: LongConstant [14]\n",  "  8: LongConstant\n" },
-    { "  10: LongConstant [14]\n", "  10: LongConstant\n"
-                                   "  19: LongConstant [17]\n" },
-    { "  14: Sub(8, 10) [17]\n",   removed },
-    { "  17: Return(14)\n",        "  17: Return(19)\n" }
+    { "  2: LongConstant [4]\n",  "  2: LongConstant\n" },
+    { "  3: LongConstant [4]\n",  "  3: LongConstant\n"
+                                  "  7: LongConstant [5]\n" },
+    { "  4: Sub(2, 3) [5]\n",     removed },
+    { "  5: Return(4)\n",         "  5: Return(7)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -537,8 +537,8 @@
 
   // Expected difference after dead code elimination.
   diff_t expected_dce_diff = {
-    { "  8: LongConstant\n", removed },
-    { "  10: LongConstant\n", removed }
+    { "  2: LongConstant\n", removed },
+    { "  3: LongConstant\n", removed }
   };
   std::string expected_after_dce = Patch(expected_after_cf, expected_dce_diff);
 
@@ -587,44 +587,44 @@
 
   std::string expected_before =
       "BasicBlock 0, succ: 1\n"
-      "  5: IntConstant [11]\n"            // v0 <- 1
-      "  7: IntConstant [11]\n"            // v1 <- 2
-      "  15: IntConstant [16]\n"           // const 5
-      "  20: IntConstant [21]\n"           // const 4
-      "  25: IntConstant [26]\n"           // const 8
-      "  3: SuspendCheck\n"
-      "  4: Goto 1\n"
+      "  2: IntConstant [4]\n"             // v0 <- 1
+      "  3: IntConstant [4]\n"             // v1 <- 2
+      "  6: IntConstant [7]\n"             // const 5
+      "  9: IntConstant [10]\n"            // const 4
+      "  12: IntConstant [13]\n"           // const 8
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 3\n"
-      "  11: Add(5, 7) [21]\n"             // v2 <- v0 + v1 = 1 + 2 = 3
-      "  13: Goto 3\n"                     // goto L2
+      "  4: Add(2, 3) [7]\n"               // v2 <- v0 + v1 = 1 + 2 = 3
+      "  5: Goto 3\n"                      // goto L2
       "BasicBlock 2, pred: 3, succ: 4\n"   // L1:
-      "  16: Add(21, 15) [26]\n"           // v1 <- v0 + 3 = 7 + 5 = 12
-      "  18: Goto 4\n"                     // goto L3
+      "  10: Add(7, 9) [13]\n"             // v1 <- v0 + 3 = 7 + 5 = 12
+      "  11: Goto 4\n"                     // goto L3
       "BasicBlock 3, pred: 1, succ: 2\n"   // L2:
-      "  21: Add(11, 20) [16]\n"           // v0 <- v2 + 2 = 3 + 4 = 7
-      "  23: Goto 2\n"                     // goto L1
+      "  7: Add(4, 6) [10]\n"              // v0 <- v2 + 2 = 3 + 4 = 7
+      "  8: Goto 2\n"                      // goto L1
       "BasicBlock 4, pred: 2, succ: 5\n"   // L3:
-      "  26: Add(16, 25) [29]\n"           // v2 <- v1 + 4 = 12 + 8 = 20
-      "  29: Return(26)\n"                 // return v2
+      "  13: Add(10, 12) [14]\n"           // v2 <- v1 + 4 = 12 + 8 = 20
+      "  14: Return(13)\n"                 // return v2
       "BasicBlock 5, pred: 4\n"
-      "  30: Exit\n";
+      "  15: Exit\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  5: IntConstant [11]\n",  "  5: IntConstant\n" },
-    { "  7: IntConstant [11]\n",  "  7: IntConstant\n" },
-    { "  15: IntConstant [16]\n", "  15: IntConstant\n" },
-    { "  20: IntConstant [21]\n", "  20: IntConstant\n" },
-    { "  25: IntConstant [26]\n", "  25: IntConstant\n"
-                                  "  31: IntConstant\n"
-                                  "  32: IntConstant\n"
-                                  "  33: IntConstant\n"
-                                  "  34: IntConstant [29]\n" },
-    { "  11: Add(5, 7) [21]\n",   removed },
-    { "  16: Add(21, 15) [26]\n", removed },
-    { "  21: Add(11, 20) [16]\n", removed },
-    { "  26: Add(16, 25) [29]\n", removed },
-    { "  29: Return(26)\n",       "  29: Return(34)\n"}
+    { "  2: IntConstant [4]\n",   "  2: IntConstant\n" },
+    { "  3: IntConstant [4]\n",   "  3: IntConstant\n" },
+    { "  6: IntConstant [7]\n",   "  6: IntConstant\n" },
+    { "  9: IntConstant [10]\n",  "  9: IntConstant\n" },
+    { "  12: IntConstant [13]\n", "  12: IntConstant\n"
+                                  "  16: IntConstant\n"
+                                  "  17: IntConstant\n"
+                                  "  18: IntConstant\n"
+                                  "  19: IntConstant [14]\n" },
+    { "  4: Add(2, 3) [7]\n",     removed },
+    { "  10: Add(7, 9) [13]\n",   removed },
+    { "  7: Add(4, 6) [10]\n",    removed },
+    { "  13: Add(10, 12) [14]\n", removed },
+    { "  14: Return(13)\n",       "  14: Return(19)\n"}
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -647,13 +647,13 @@
   // Expected difference after dead code elimination.
   std::string expected_after_dce =
       "BasicBlock 0, succ: 1\n"
-      "  34: IntConstant [29]\n"
-      "  3: SuspendCheck\n"
-      "  4: Goto 1\n"
+      "  19: IntConstant [14]\n"
+      "  0: SuspendCheck\n"
+      "  1: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 5\n"
-      "  29: Return(34)\n"
+      "  14: Return(19)\n"
       "BasicBlock 5, pred: 1\n"
-      "  30: Exit\n";
+      "  15: Exit\n";
 
   TestCode(data,
            expected_before,
@@ -685,31 +685,31 @@
     Instruction::RETURN_VOID);
 
   std::string expected_before =
-     "BasicBlock 0, succ: 1\n"
-      "  6: IntConstant [18, 22, 11]\n"
-      "  8: IntConstant [22, 11]\n"
-      "  4: SuspendCheck\n"
-      "  5: Goto 1\n"
+      "BasicBlock 0, succ: 1\n"
+      "  3: IntConstant [9, 8, 5]\n"
+      "  4: IntConstant [8, 5]\n"
+      "  1: SuspendCheck\n"
+      "  2: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 5, 2\n"
-      "  11: GreaterThanOrEqual(6, 8) [12]\n"
-      "  12: If(11)\n"
+      "  5: GreaterThanOrEqual(3, 4) [6]\n"
+      "  6: If(5)\n"
       "BasicBlock 2, pred: 1, succ: 3\n"
-      "  15: Goto 3\n"
+      "  7: Goto 3\n"
       "BasicBlock 3, pred: 5, 2, succ: 4\n"
-      "  22: Phi(8, 6) [18]\n"
-      "  18: Add(22, 6)\n"
-      "  20: ReturnVoid\n"
+      "  8: Phi(4, 3) [9]\n"
+      "  9: Add(8, 3)\n"
+      "  10: ReturnVoid\n"
       "BasicBlock 4, pred: 3\n"
-      "  21: Exit\n"
+      "  11: Exit\n"
       "BasicBlock 5, pred: 1, succ: 3\n"
       "  0: Goto 3\n";
 
   // Expected difference after constant folding.
   diff_t expected_cf_diff = {
-    { "  6: IntConstant [18, 22, 11]\n",       "  6: IntConstant [12, 18, 22]\n" },
-    { "  8: IntConstant [22, 11]\n",           "  8: IntConstant [22]\n" },
-    { "  11: GreaterThanOrEqual(6, 8) [12]\n", removed },
-    { "  12: If(11)\n",                        "  12: If(6)\n" }
+    { "  3: IntConstant [9, 8, 5]\n",        "  3: IntConstant [6, 9, 8]\n" },
+    { "  4: IntConstant [8, 5]\n",           "  4: IntConstant [8]\n" },
+    { "  5: GreaterThanOrEqual(3, 4) [6]\n", removed },
+    { "  6: If(5)\n",                        "  6: If(3)\n" }
   };
   std::string expected_after_cf = Patch(expected_before, expected_cf_diff);
 
@@ -723,12 +723,12 @@
   // Expected graph after dead code elimination.
   std::string expected_after_dce =
       "BasicBlock 0, succ: 1\n"
-      "  4: SuspendCheck\n"
-      "  5: Goto 1\n"
+      "  1: SuspendCheck\n"
+      "  2: Goto 1\n"
       "BasicBlock 1, pred: 0, succ: 4\n"
-      "  20: ReturnVoid\n"
+      "  10: ReturnVoid\n"
       "BasicBlock 4, pred: 1\n"
-      "  21: Exit\n";
+      "  11: Exit\n";
 
   TestCode(data,
            expected_before,