Add OptimizingCompilerStats to the CodeGenerator class.

Just refactoring, not yet used, but will be used by the incoming patch
series and future CodeGen specific stats.

Change-Id: I7d20489907b82678120518a77bdab9c4cc58f937
Signed-off-by: Serban Constantinescu <serban.constantinescu@linaro.org>
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 503187b..e8304e5 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -531,24 +531,33 @@
   }
 }
 
+void CodeGenerator::MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count) const {
+  if (stats_ != nullptr) {
+    stats_->RecordStat(compilation_stat, count);
+  }
+}
+
 CodeGenerator* CodeGenerator::Create(HGraph* graph,
                                      InstructionSet instruction_set,
                                      const InstructionSetFeatures& isa_features,
-                                     const CompilerOptions& compiler_options) {
+                                     const CompilerOptions& compiler_options,
+                                     OptimizingCompilerStats* stats) {
   switch (instruction_set) {
 #ifdef ART_ENABLE_CODEGEN_arm
     case kArm:
     case kThumb2: {
       return new arm::CodeGeneratorARM(graph,
-          *isa_features.AsArmInstructionSetFeatures(),
-          compiler_options);
+                                      *isa_features.AsArmInstructionSetFeatures(),
+                                      compiler_options,
+                                      stats);
     }
 #endif
 #ifdef ART_ENABLE_CODEGEN_arm64
     case kArm64: {
       return new arm64::CodeGeneratorARM64(graph,
-          *isa_features.AsArm64InstructionSetFeatures(),
-          compiler_options);
+                                          *isa_features.AsArm64InstructionSetFeatures(),
+                                          compiler_options,
+                                          stats);
     }
 #endif
 #ifdef ART_ENABLE_CODEGEN_mips
@@ -561,22 +570,25 @@
 #ifdef ART_ENABLE_CODEGEN_mips64
     case kMips64: {
       return new mips64::CodeGeneratorMIPS64(graph,
-          *isa_features.AsMips64InstructionSetFeatures(),
-          compiler_options);
+                                            *isa_features.AsMips64InstructionSetFeatures(),
+                                            compiler_options,
+                                            stats);
     }
 #endif
 #ifdef ART_ENABLE_CODEGEN_x86
     case kX86: {
       return new x86::CodeGeneratorX86(graph,
-           *isa_features.AsX86InstructionSetFeatures(),
-           compiler_options);
+                                      *isa_features.AsX86InstructionSetFeatures(),
+                                      compiler_options,
+                                      stats);
     }
 #endif
 #ifdef ART_ENABLE_CODEGEN_x86_64
     case kX86_64: {
       return new x86_64::CodeGeneratorX86_64(graph,
-          *isa_features.AsX86_64InstructionSetFeatures(),
-          compiler_options);
+                                            *isa_features.AsX86_64InstructionSetFeatures(),
+                                            compiler_options,
+                                            stats);
     }
 #endif
     default:
diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h
index 938369b..f945564 100644
--- a/compiler/optimizing/code_generator.h
+++ b/compiler/optimizing/code_generator.h
@@ -26,6 +26,7 @@
 #include "locations.h"
 #include "memory_region.h"
 #include "nodes.h"
+#include "optimizing_compiler_stats.h"
 #include "stack_map_stream.h"
 
 namespace art {
@@ -143,7 +144,8 @@
   static CodeGenerator* Create(HGraph* graph,
                                InstructionSet instruction_set,
                                const InstructionSetFeatures& isa_features,
-                               const CompilerOptions& compiler_options);
+                               const CompilerOptions& compiler_options,
+                               OptimizingCompilerStats* stats = nullptr);
   virtual ~CodeGenerator() {}
 
   HGraph* GetGraph() const { return graph_; }
@@ -208,6 +210,8 @@
 
   const CompilerOptions& GetCompilerOptions() const { return compiler_options_; }
 
+  void MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count = 1) const;
+
   // Saves the register in the stack. Returns the size taken on stack.
   virtual size_t SaveCoreRegister(size_t stack_index, uint32_t reg_id) = 0;
   // Restores the register from the stack. Returns the size taken on stack.
@@ -375,7 +379,8 @@
                 size_t number_of_register_pairs,
                 uint32_t core_callee_save_mask,
                 uint32_t fpu_callee_save_mask,
-                const CompilerOptions& compiler_options)
+                const CompilerOptions& compiler_options,
+                OptimizingCompilerStats* stats)
       : frame_size_(0),
         core_spill_mask_(0),
         fpu_spill_mask_(0),
@@ -392,6 +397,7 @@
         block_order_(nullptr),
         is_baseline_(false),
         disasm_info_(nullptr),
+        stats_(stats),
         graph_(graph),
         compiler_options_(compiler_options),
         slow_paths_(graph->GetArena(), 8),
@@ -485,6 +491,8 @@
   void BlockIfInRegister(Location location, bool is_out = false) const;
   void EmitEnvironment(HEnvironment* environment, SlowPathCode* slow_path);
 
+  OptimizingCompilerStats* stats_;
+
   HGraph* const graph_;
   const CompilerOptions& compiler_options_;
 
diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc
index 62026f3..3b9413f 100644
--- a/compiler/optimizing/code_generator_arm.cc
+++ b/compiler/optimizing/code_generator_arm.cc
@@ -397,7 +397,8 @@
 
 CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
                                    const ArmInstructionSetFeatures& isa_features,
-                                   const CompilerOptions& compiler_options)
+                                   const CompilerOptions& compiler_options,
+                                   OptimizingCompilerStats* stats)
     : CodeGenerator(graph,
                     kNumberOfCoreRegisters,
                     kNumberOfSRegisters,
@@ -406,7 +407,8 @@
                                         arraysize(kCoreCalleeSaves)),
                     ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
                                         arraysize(kFpuCalleeSaves)),
-                    compiler_options),
+                    compiler_options,
+                    stats),
       block_labels_(graph->GetArena(), 0),
       location_builder_(graph, this),
       instruction_visitor_(graph, this),
diff --git a/compiler/optimizing/code_generator_arm.h b/compiler/optimizing/code_generator_arm.h
index 9528cca..9c14067 100644
--- a/compiler/optimizing/code_generator_arm.h
+++ b/compiler/optimizing/code_generator_arm.h
@@ -231,7 +231,8 @@
  public:
   CodeGeneratorARM(HGraph* graph,
                    const ArmInstructionSetFeatures& isa_features,
-                   const CompilerOptions& compiler_options);
+                   const CompilerOptions& compiler_options,
+                   OptimizingCompilerStats* stats = nullptr);
   virtual ~CodeGeneratorARM() {}
 
   void GenerateFrameEntry() OVERRIDE;
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index 25b3ea2..348c5c8 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -510,14 +510,16 @@
 
 CodeGeneratorARM64::CodeGeneratorARM64(HGraph* graph,
                                        const Arm64InstructionSetFeatures& isa_features,
-                                       const CompilerOptions& compiler_options)
+                                       const CompilerOptions& compiler_options,
+                                       OptimizingCompilerStats* stats)
     : CodeGenerator(graph,
                     kNumberOfAllocatableRegisters,
                     kNumberOfAllocatableFPRegisters,
                     kNumberOfAllocatableRegisterPairs,
                     callee_saved_core_registers.list(),
                     callee_saved_fp_registers.list(),
-                    compiler_options),
+                    compiler_options,
+                    stats),
       block_labels_(nullptr),
       location_builder_(graph, this),
       instruction_visitor_(graph, this),
diff --git a/compiler/optimizing/code_generator_arm64.h b/compiler/optimizing/code_generator_arm64.h
index 18070fc..1fa6e82 100644
--- a/compiler/optimizing/code_generator_arm64.h
+++ b/compiler/optimizing/code_generator_arm64.h
@@ -248,7 +248,8 @@
  public:
   CodeGeneratorARM64(HGraph* graph,
                      const Arm64InstructionSetFeatures& isa_features,
-                     const CompilerOptions& compiler_options);
+                     const CompilerOptions& compiler_options,
+                     OptimizingCompilerStats* stats = nullptr);
   virtual ~CodeGeneratorARM64() {}
 
   void GenerateFrameEntry() OVERRIDE;
diff --git a/compiler/optimizing/code_generator_mips64.cc b/compiler/optimizing/code_generator_mips64.cc
index 093d786..75fd0eb 100644
--- a/compiler/optimizing/code_generator_mips64.cc
+++ b/compiler/optimizing/code_generator_mips64.cc
@@ -419,7 +419,8 @@
 
 CodeGeneratorMIPS64::CodeGeneratorMIPS64(HGraph* graph,
                                          const Mips64InstructionSetFeatures& isa_features,
-                                         const CompilerOptions& compiler_options)
+                                         const CompilerOptions& compiler_options,
+                                         OptimizingCompilerStats* stats)
     : CodeGenerator(graph,
                     kNumberOfGpuRegisters,
                     kNumberOfFpuRegisters,
@@ -428,7 +429,8 @@
                                         arraysize(kCoreCalleeSaves)),
                     ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
                                         arraysize(kFpuCalleeSaves)),
-                    compiler_options),
+                    compiler_options,
+                    stats),
       block_labels_(graph->GetArena(), 0),
       location_builder_(graph, this),
       instruction_visitor_(graph, this),
diff --git a/compiler/optimizing/code_generator_mips64.h b/compiler/optimizing/code_generator_mips64.h
index ae7c568..6d4fac3 100644
--- a/compiler/optimizing/code_generator_mips64.h
+++ b/compiler/optimizing/code_generator_mips64.h
@@ -220,7 +220,8 @@
  public:
   CodeGeneratorMIPS64(HGraph* graph,
                       const Mips64InstructionSetFeatures& isa_features,
-                      const CompilerOptions& compiler_options);
+                      const CompilerOptions& compiler_options,
+                      OptimizingCompilerStats* stats = nullptr);
   virtual ~CodeGeneratorMIPS64() {}
 
   void GenerateFrameEntry() OVERRIDE;
diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc
index 72c690d..3421fae 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -429,7 +429,8 @@
 
 CodeGeneratorX86::CodeGeneratorX86(HGraph* graph,
                    const X86InstructionSetFeatures& isa_features,
-                   const CompilerOptions& compiler_options)
+                   const CompilerOptions& compiler_options,
+                   OptimizingCompilerStats* stats)
     : CodeGenerator(graph,
                     kNumberOfCpuRegisters,
                     kNumberOfXmmRegisters,
@@ -437,8 +438,9 @@
                     ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
                                         arraysize(kCoreCalleeSaves))
                         | (1 << kFakeReturnRegister),
-                        0,
-                        compiler_options),
+                    0,
+                    compiler_options,
+                    stats),
       block_labels_(graph->GetArena(), 0),
       location_builder_(graph, this),
       instruction_visitor_(graph, this),
diff --git a/compiler/optimizing/code_generator_x86.h b/compiler/optimizing/code_generator_x86.h
index 17787a8..033693e 100644
--- a/compiler/optimizing/code_generator_x86.h
+++ b/compiler/optimizing/code_generator_x86.h
@@ -220,7 +220,8 @@
  public:
   CodeGeneratorX86(HGraph* graph,
                    const X86InstructionSetFeatures& isa_features,
-                   const CompilerOptions& compiler_options);
+                   const CompilerOptions& compiler_options,
+                   OptimizingCompilerStats* stats = nullptr);
   virtual ~CodeGeneratorX86() {}
 
   void GenerateFrameEntry() OVERRIDE;
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 820ec78..0ea95e8 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -559,7 +559,8 @@
 static constexpr Register kFakeReturnRegister = Register(kLastCpuRegister + 1);
 CodeGeneratorX86_64::CodeGeneratorX86_64(HGraph* graph,
                 const X86_64InstructionSetFeatures& isa_features,
-                const CompilerOptions& compiler_options)
+                const CompilerOptions& compiler_options,
+                OptimizingCompilerStats* stats)
       : CodeGenerator(graph,
                       kNumberOfCpuRegisters,
                       kNumberOfFloatRegisters,
@@ -569,7 +570,8 @@
                           | (1 << kFakeReturnRegister),
                       ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
                                           arraysize(kFpuCalleeSaves)),
-                      compiler_options),
+                      compiler_options,
+                      stats),
         block_labels_(graph->GetArena(), 0),
         location_builder_(graph, this),
         instruction_visitor_(graph, this),
diff --git a/compiler/optimizing/code_generator_x86_64.h b/compiler/optimizing/code_generator_x86_64.h
index 21357be..8ee0a7a 100644
--- a/compiler/optimizing/code_generator_x86_64.h
+++ b/compiler/optimizing/code_generator_x86_64.h
@@ -220,7 +220,8 @@
  public:
   CodeGeneratorX86_64(HGraph* graph,
                   const X86_64InstructionSetFeatures& isa_features,
-                  const CompilerOptions& compiler_options);
+                  const CompilerOptions& compiler_options,
+                  OptimizingCompilerStats* stats = nullptr);
   virtual ~CodeGeneratorX86_64() {}
 
   void GenerateFrameEntry() OVERRIDE;