MIR tidying.

Fix memory leak in the MIR graph m_units_.
Don't shadow the arena_ field in Backend.

Change-Id: I0ffaebd088f1383205bde9fb34c5d33156bb7260
diff --git a/src/compiler/dex/backend.h b/src/compiler/dex/backend.h
index 1f0c5d8..45a1531 100644
--- a/src/compiler/dex/backend.h
+++ b/src/compiler/dex/backend.h
@@ -30,8 +30,8 @@
     virtual CompiledMethod* GetCompiledMethod() = 0;
 
   protected:
-    Backend() : arena_(NULL) {};
-    ArenaAllocator* arena_;
+    Backend(ArenaAllocator* arena) : arena_(arena) {};
+    ArenaAllocator* const arena_;
 
 };  // Class Backend
 
diff --git a/src/compiler/dex/mir_graph.cc b/src/compiler/dex/mir_graph.cc
index 37600fc..6154eec 100644
--- a/src/compiler/dex/mir_graph.cc
+++ b/src/compiler/dex/mir_graph.cc
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
+#include "base/stl_util.h"
 #include "compiler_internals.h"
-#include "mir_graph.h"
-#include "leb128.h"
 #include "dex_file-inl.h"
+#include "leb128.h"
+#include "mir_graph.h"
 
 namespace art {
 
@@ -112,6 +113,10 @@
   try_block_addr_ = new (arena_) ArenaBitVector(arena_, 0, true /* expandable */);
 }
 
+MIRGraph::~MIRGraph() {
+  STLDeleteElements(&m_units_);
+}
+
 bool MIRGraph::ContentIsInsn(const uint16_t* code_ptr) {
   uint16_t instr = *code_ptr;
   Instruction::Code opcode = static_cast<Instruction::Code>(instr & 0xff);
diff --git a/src/compiler/dex/mir_graph.h b/src/compiler/dex/mir_graph.h
index 6a45ac0..fd81967 100644
--- a/src/compiler/dex/mir_graph.h
+++ b/src/compiler/dex/mir_graph.h
@@ -310,7 +310,7 @@
 class MIRGraph {
  public:
   MIRGraph(CompilationUnit* cu, ArenaAllocator* arena);
-  ~MIRGraph() {}
+  ~MIRGraph();
 
   /*
    * Parse dex method and add MIR at current insert point.  Returns id (which is
diff --git a/src/compiler/dex/portable/mir_to_gbc.h b/src/compiler/dex/portable/mir_to_gbc.h
index 5088761..233735b 100644
--- a/src/compiler/dex/portable/mir_to_gbc.h
+++ b/src/compiler/dex/portable/mir_to_gbc.h
@@ -46,7 +46,8 @@
     // TODO: flesh out and integrate into new world order.
     MirConverter(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena,
                  llvm::LlvmCompilationUnit* llvm_compilation_unit)
-      : cu_(cu),
+      : Backend(arena),
+        cu_(cu),
         mir_graph_(mir_graph),
         llvm_compilation_unit_(llvm_compilation_unit),
         llvm_info_(llvm_compilation_unit->GetQuickContext()),
@@ -62,7 +63,6 @@
         llvm_values_(arena, mir_graph->GetNumSSARegs()),
         temp_name_(0),
         current_dalvik_offset_(0) {
-      arena_ = arena;
       if (kIsDebugBuild) {
         cu->enable_debug |= (1 << kDebugVerifyBitcode);
       }
diff --git a/src/compiler/dex/quick/codegen_util.cc b/src/compiler/dex/quick/codegen_util.cc
index 717d7ca..517d1b5 100644
--- a/src/compiler/dex/quick/codegen_util.cc
+++ b/src/compiler/dex/quick/codegen_util.cc
@@ -1115,7 +1115,8 @@
 
 // TODO: move to mir_to_lir.cc
 Mir2Lir::Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
-    : literal_list_(NULL),
+    : Backend(arena),
+      literal_list_(NULL),
       method_literal_list_(NULL),
       code_literal_list_(NULL),
       cu_(cu),
@@ -1139,7 +1140,6 @@
       first_lir_insn_(NULL),
       last_lir_insn_(NULL)
  {
-  arena_ = arena;
   promotion_map_ = static_cast<PromotionMap*>
       (arena_->NewMem((cu_->num_dalvik_registers  + cu_->num_compiler_temps + 1) *
                       sizeof(promotion_map_[0]), true, ArenaAllocator::kAllocRegAlloc));
diff --git a/src/compiler/dex/quick/mir_to_lir.h b/src/compiler/dex/quick/mir_to_lir.h
index 04682d9..21a0aac 100644
--- a/src/compiler/dex/quick/mir_to_lir.h
+++ b/src/compiler/dex/quick/mir_to_lir.h
@@ -745,8 +745,6 @@
     unsigned int fp_spill_mask_;
     LIR* first_lir_insn_;
     LIR* last_lir_insn_;
-    ArenaAllocator* arena_;
-
 };  // Class Mir2Lir
 
 }  // namespace art