ART: API changes

- Moved AppendMIR to BasicBlock
- Moved PrependMIR to BasicBlock
- Moved InsertMIRAfter to BasicBlock
- Moved GetNextUnconditionalMir to BasicBlock

Change-Id: Id261434e9f7d5d93f1bce0c87c9276a20077c483
Signed-off-by: Jean Christophe Beyler <jean.christophe.beyler@intel.com>
diff --git a/compiler/dex/mir_graph.cc b/compiler/dex/mir_graph.cc
index 60719a5..34f140b 100644
--- a/compiler/dex/mir_graph.cc
+++ b/compiler/dex/mir_graph.cc
@@ -528,7 +528,7 @@
       static_cast<Instruction::Code>(kMirOpCheck);
   // Associate the two halves
   insn->meta.throw_insn = new_insn;
-  AppendMIR(new_block, new_insn);
+  new_block->AppendMIR(new_insn);
   return new_block;
 }
 
@@ -646,7 +646,7 @@
       }
       if (width == 1) {
         // It is a simple nop - treat normally.
-        AppendMIR(cur_block, insn);
+        cur_block->AppendMIR(insn);
       } else {
         DCHECK(cur_block->fall_through == NullBasicBlockId);
         DCHECK(cur_block->taken == NullBasicBlockId);
@@ -654,7 +654,7 @@
         flags &= ~Instruction::kContinue;
       }
     } else {
-      AppendMIR(cur_block, insn);
+      cur_block->AppendMIR(insn);
     }
 
     // Associate the starting dex_pc for this opcode with its containing basic block.
@@ -873,42 +873,42 @@
 }
 
 /* Insert an MIR instruction to the end of a basic block */
-void MIRGraph::AppendMIR(BasicBlock* bb, MIR* mir) {
-  if (bb->first_mir_insn == NULL) {
-    DCHECK(bb->last_mir_insn == NULL);
-    bb->last_mir_insn = bb->first_mir_insn = mir;
-    mir->next = NULL;
+void BasicBlock::AppendMIR(MIR* mir) {
+  if (first_mir_insn == nullptr) {
+    DCHECK(last_mir_insn == nullptr);
+    last_mir_insn = first_mir_insn = mir;
+    mir->next = nullptr;
   } else {
-    bb->last_mir_insn->next = mir;
-    mir->next = NULL;
-    bb->last_mir_insn = mir;
+    last_mir_insn->next = mir;
+    mir->next = nullptr;
+    last_mir_insn = mir;
   }
 }
 
 /* Insert an MIR instruction to the head of a basic block */
-void MIRGraph::PrependMIR(BasicBlock* bb, MIR* mir) {
-  if (bb->first_mir_insn == NULL) {
-    DCHECK(bb->last_mir_insn == NULL);
-    bb->last_mir_insn = bb->first_mir_insn = mir;
-    mir->next = NULL;
+void BasicBlock::PrependMIR(MIR* mir) {
+  if (first_mir_insn == nullptr) {
+    DCHECK(last_mir_insn == nullptr);
+    last_mir_insn = first_mir_insn = mir;
+    mir->next = nullptr;
   } else {
-    mir->next = bb->first_mir_insn;
-    bb->first_mir_insn = mir;
+    mir->next = first_mir_insn;
+    first_mir_insn = mir;
   }
 }
 
 /* Insert a MIR instruction after the specified MIR */
-void MIRGraph::InsertMIRAfter(BasicBlock* bb, MIR* current_mir, MIR* new_mir) {
+void BasicBlock::InsertMIRAfter(MIR* current_mir, MIR* new_mir) {
   new_mir->next = current_mir->next;
   current_mir->next = new_mir;
 
-  if (bb->last_mir_insn == current_mir) {
+  if (last_mir_insn == current_mir) {
     /* Is the last MIR in the block */
-    bb->last_mir_insn = new_mir;
+    last_mir_insn = new_mir;
   }
 }
 
-MIR* MIRGraph::GetNextUnconditionalMir(BasicBlock* bb, MIR* current) {
+MIR* BasicBlock::GetNextUnconditionalMir(MIRGraph* mir_graph, MIR* current) {
   MIR* next_mir = nullptr;
 
   if (current != nullptr) {
@@ -917,8 +917,8 @@
 
   if (next_mir == nullptr) {
     // Only look for next MIR that follows unconditionally.
-    if ((bb->taken == NullBasicBlockId) && (bb->fall_through != NullBasicBlockId)) {
-      next_mir = GetBasicBlock(bb->fall_through)->first_mir_insn;
+    if ((taken == NullBasicBlockId) && (fall_through != NullBasicBlockId)) {
+      next_mir = mir_graph->GetBasicBlock(fall_through)->first_mir_insn;
     }
   }
 
diff --git a/compiler/dex/mir_graph.h b/compiler/dex/mir_graph.h
index fd25798..e10f66f 100644
--- a/compiler/dex/mir_graph.h
+++ b/compiler/dex/mir_graph.h
@@ -308,6 +308,20 @@
   ArenaBitVector* dom_frontier;     // Dominance frontier.
   GrowableArray<BasicBlockId>* predecessors;
   GrowableArray<SuccessorBlockInfo*>* successor_blocks;
+
+  void AppendMIR(MIR* mir);
+  void PrependMIR(MIR* mir);
+  void InsertMIRAfter(MIR* current_mir, MIR* new_mir);
+
+  /**
+   * @brief Used to obtain the next MIR that follows unconditionally.
+   * @details The implementation does not guarantee that a MIR does not
+   * follow even if this method returns nullptr.
+   * @param mir_graph the MIRGraph.
+   * @param current The MIR for which to find an unconditional follower.
+   * @return Returns the following MIR if one can be found.
+   */
+  MIR* GetNextUnconditionalMir(MIRGraph* mir_graph, MIR* current);
 };
 
 /*
@@ -786,20 +800,6 @@
   bool SetHigh(int index, bool is_high);
   bool SetHigh(int index);
 
-  void AppendMIR(BasicBlock* bb, MIR* mir);
-  void PrependMIR(BasicBlock* bb, MIR* mir);
-  void InsertMIRAfter(BasicBlock* bb, MIR* current_mir, MIR* new_mir);
-
-  /**
-   * @brief Used to obtain the next MIR that follows unconditionally.
-   * @details The implementation does not guarantee that a MIR does not
-   * follow even if this method returns nullptr.
-   * @param bb The basic block of "current" MIR.
-   * @param current The MIR for which to find an unconditional follower.
-   * @return Returns the following MIR if one can be found.
-   */
-  MIR* GetNextUnconditionalMir(BasicBlock* bb, MIR* current);
-
   char* GetDalvikDisassembly(const MIR* mir);
   void ReplaceSpecialChars(std::string& str);
   std::string GetSSAName(int ssa_reg);
diff --git a/compiler/dex/mir_optimization_test.cc b/compiler/dex/mir_optimization_test.cc
index f499364..40ced70 100644
--- a/compiler/dex/mir_optimization_test.cc
+++ b/compiler/dex/mir_optimization_test.cc
@@ -163,7 +163,7 @@
       mir->dalvikInsn.opcode = def->opcode;
       ASSERT_LT(def->bbid, cu_.mir_graph->block_list_.Size());
       BasicBlock* bb = cu_.mir_graph->block_list_.Get(def->bbid);
-      cu_.mir_graph->AppendMIR(bb, mir);
+      bb->AppendMIR(mir);
       if (def->opcode >= Instruction::SGET && def->opcode <= Instruction::SPUT_SHORT) {
         ASSERT_LT(def->field_or_method_info, cu_.mir_graph->sfield_lowering_infos_.Size());
         mir->meta.sfield_lowering_info = def->field_or_method_info;
diff --git a/compiler/dex/quick/dex_file_method_inliner.cc b/compiler/dex/quick/dex_file_method_inliner.cc
index 53e26c7..fa6de96 100644
--- a/compiler/dex/quick/dex_file_method_inliner.cc
+++ b/compiler/dex/quick/dex_file_method_inliner.cc
@@ -564,7 +564,7 @@
   insn->dalvikInsn.opcode = Instruction::CONST;
   insn->dalvikInsn.vA = move_result->dalvikInsn.vA;
   insn->dalvikInsn.vB = method.d.data;
-  mir_graph->InsertMIRAfter(bb, move_result, insn);
+  bb->InsertMIRAfter(move_result, insn);
   return true;
 }
 
@@ -603,7 +603,7 @@
   insn->dalvikInsn.opcode = opcode;
   insn->dalvikInsn.vA = move_result->dalvikInsn.vA;
   insn->dalvikInsn.vB = arg;
-  mir_graph->InsertMIRAfter(bb, move_result, insn);
+  bb->InsertMIRAfter(move_result, insn);
   return true;
 }
 
@@ -650,7 +650,7 @@
   DCHECK_EQ(data.field_offset, mir_graph->GetIFieldLoweringInfo(insn).FieldOffset().Uint32Value());
   DCHECK_EQ(data.is_volatile, mir_graph->GetIFieldLoweringInfo(insn).IsVolatile() ? 1u : 0u);
 
-  mir_graph->InsertMIRAfter(bb, move_result, insn);
+  bb->InsertMIRAfter(move_result, insn);
   return true;
 }
 
@@ -688,7 +688,7 @@
   DCHECK_EQ(data.field_offset, mir_graph->GetIFieldLoweringInfo(insn).FieldOffset().Uint32Value());
   DCHECK_EQ(data.is_volatile, mir_graph->GetIFieldLoweringInfo(insn).IsVolatile() ? 1u : 0u);
 
-  mir_graph->InsertMIRAfter(bb, invoke, insn);
+  bb->InsertMIRAfter(invoke, insn);
   return true;
 }
 
diff --git a/compiler/dex/quick/mir_to_lir.cc b/compiler/dex/quick/mir_to_lir.cc
index 39994e9..82664e2 100644
--- a/compiler/dex/quick/mir_to_lir.cc
+++ b/compiler/dex/quick/mir_to_lir.cc
@@ -212,7 +212,7 @@
       RegLocation rl_dest = GetReturn(cu_->shorty[0] == 'F');
       GenPrintLabel(mir);
       LoadConstant(rl_dest.reg.GetReg(), static_cast<int>(special.d.data));
-      return_mir = mir_graph_->GetNextUnconditionalMir(bb, mir);
+      return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir);
       break;
     }
     case kInlineOpReturnArg:
@@ -221,11 +221,11 @@
       break;
     case kInlineOpIGet:
       successful = GenSpecialIGet(mir, special);
-      return_mir = mir_graph_->GetNextUnconditionalMir(bb, mir);
+      return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir);
       break;
     case kInlineOpIPut:
       successful = GenSpecialIPut(mir, special);
-      return_mir = mir_graph_->GetNextUnconditionalMir(bb, mir);
+      return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir);
       break;
     default:
       break;
diff --git a/compiler/dex/ssa_transformation.cc b/compiler/dex/ssa_transformation.cc
index d70e3f5..dab98d9 100644
--- a/compiler/dex/ssa_transformation.cc
+++ b/compiler/dex/ssa_transformation.cc
@@ -563,7 +563,7 @@
       phi->dalvikInsn.vA = dalvik_reg;
       phi->offset = phi_bb->start_offset;
       phi->m_unit_index = 0;  // Arbitrarily assign all Phi nodes to outermost method.
-      PrependMIR(phi_bb, phi);
+      phi_bb->PrependMIR(phi);
     }
   }
 }