Add ImprovedOptimizingUnitTest::CreateParameters for subclasses

Subclasses of ImprovedOptimizingUnitTest might need a different number
of graph parameters. Currently only a parameter is defined and created.
This CL adds ImprovedOptimizingUnitTest::CreateParameters which
subclasses can override to create as many parameters as they need. All
created parameters are added to the entry basic block. The default
implementation of ImprovedOptimizingUnitTest::CreateParameters does
nothing.

Test: run-gtests.sh
Change-Id: I2c6a58232e36d3562fc2bc0cdc289dd739094a73
diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h
index e5f6941..0157126 100644
--- a/compiler/optimizing/optimizing_unit_test.h
+++ b/compiler/optimizing/optimizing_unit_test.h
@@ -194,8 +194,7 @@
   ImprovedOptimizingUnitTest() : graph_(CreateGraph()),
                                  entry_block_(nullptr),
                                  return_block_(nullptr),
-                                 exit_block_(nullptr),
-                                 parameter_(nullptr) {}
+                                 exit_block_(nullptr) {}
 
   virtual ~ImprovedOptimizingUnitTest() {}
 
@@ -214,11 +213,11 @@
     entry_block_->AddSuccessor(return_block_);
     return_block_->AddSuccessor(exit_block_);
 
-    parameter_ = new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
-                                                      dex::TypeIndex(0),
-                                                      0,
-                                                      DataType::Type::kInt32);
-    entry_block_->AddInstruction(parameter_);
+    CreateParameters();
+    for (HInstruction* parameter : parameters_) {
+      entry_block_->AddInstruction(parameter);
+    }
+
     return_block_->AddInstruction(new (GetAllocator()) HReturnVoid());
     exit_block_->AddInstruction(new (GetAllocator()) HExit());
   }
@@ -250,13 +249,17 @@
   }
 
  protected:
+  // Create parameters to be added to the graph entry block.
+  // Subclasses can override it to create parameters they need.
+  virtual void CreateParameters() { /* do nothing */ }
+
   HGraph* graph_;
 
   HBasicBlock* entry_block_;
   HBasicBlock* return_block_;
   HBasicBlock* exit_block_;
 
-  HInstruction* parameter_;
+  std::vector<HInstruction*> parameters_;
 };
 
 // Naive string diff data type.
diff --git a/compiler/optimizing/select_generator_test.cc b/compiler/optimizing/select_generator_test.cc
index 6e65497..6e68c6c 100644
--- a/compiler/optimizing/select_generator_test.cc
+++ b/compiler/optimizing/select_generator_test.cc
@@ -25,6 +25,14 @@
 namespace art {
 
 class SelectGeneratorTest : public ImprovedOptimizingUnitTest {
+ private:
+  void CreateParameters() override {
+    parameters_.push_back(new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
+                                                               dex::TypeIndex(0),
+                                                               0,
+                                                               DataType::Type::kInt32));
+  }
+
  public:
   void ConstructBasicGraphForSelect(HInstruction* instr) {
     HBasicBlock* if_block = new (GetAllocator()) HBasicBlock(graph_);
@@ -75,10 +83,10 @@
 // HDivZeroCheck might throw and should not be hoisted from the conditional to an unconditional.
 TEST_F(SelectGeneratorTest, testZeroCheck) {
   InitGraph();
-  HDivZeroCheck* instr = new (GetAllocator()) HDivZeroCheck(parameter_, 0);
+  HDivZeroCheck* instr = new (GetAllocator()) HDivZeroCheck(parameters_[0], 0);
   ConstructBasicGraphForSelect(instr);
 
-  ArenaVector<HInstruction*> current_locals({parameter_, graph_->GetIntConstant(1)},
+  ArenaVector<HInstruction*> current_locals({parameters_[0], graph_->GetIntConstant(1)},
                                             GetAllocator()->Adapter(kArenaAllocInstruction));
   ManuallyBuildEnvFor(instr, &current_locals);
 
@@ -88,7 +96,9 @@
 // Test that SelectGenerator succeeds with HAdd.
 TEST_F(SelectGeneratorTest, testAdd) {
   InitGraph();
-  HAdd* instr = new (GetAllocator()) HAdd(DataType::Type::kInt32, parameter_, parameter_, 0);
+  HAdd* instr = new (GetAllocator()) HAdd(DataType::Type::kInt32,
+                                          parameters_[0],
+                                          parameters_[0], 0);
   ConstructBasicGraphForSelect(instr);
   EXPECT_TRUE(CheckGraphAndTrySelectGenerator());
 }
diff --git a/compiler/optimizing/superblock_cloner_test.cc b/compiler/optimizing/superblock_cloner_test.cc
index aa19de6..ddcf154 100644
--- a/compiler/optimizing/superblock_cloner_test.cc
+++ b/compiler/optimizing/superblock_cloner_test.cc
@@ -31,6 +31,14 @@
 // This class provides methods and helpers for testing various cloning and copying routines:
 // individual instruction cloning and cloning of the more coarse-grain structures.
 class SuperblockClonerTest : public ImprovedOptimizingUnitTest {
+ private:
+  void CreateParameters() override {
+    parameters_.push_back(new (GetAllocator()) HParameterValue(graph_->GetDexFile(),
+                                                               dex::TypeIndex(0),
+                                                               0,
+                                                               DataType::Type::kInt32));
+  }
+
  public:
   void CreateBasicLoopControlFlow(HBasicBlock* position,
                                   HBasicBlock* successor,
@@ -75,7 +83,7 @@
     loop_header->AddInstruction(new (GetAllocator()) HIf(loop_check));
 
     // Loop body block.
-    HInstruction* null_check = new (GetAllocator()) HNullCheck(parameter_, dex_pc);
+    HInstruction* null_check = new (GetAllocator()) HNullCheck(parameters_[0], dex_pc);
     HInstruction* array_length = new (GetAllocator()) HArrayLength(null_check, dex_pc);
     HInstruction* bounds_check = new (GetAllocator()) HBoundsCheck(phi, array_length, dex_pc);
     HInstruction* array_get =
@@ -100,7 +108,7 @@
     graph_->SetHasBoundsChecks(true);
 
     // Adjust HEnvironment for each instruction which require that.
-    ArenaVector<HInstruction*> current_locals({phi, const_128, parameter_},
+    ArenaVector<HInstruction*> current_locals({phi, const_128, parameters_[0]},
                                               GetAllocator()->Adapter(kArenaAllocInstruction));
 
     HEnvironment* env = ManuallyBuildEnvFor(suspend_check, &current_locals);
@@ -421,7 +429,7 @@
   if_block->AddSuccessor(temp1);
   temp1->AddSuccessor(header);
 
-  if_block->AddInstruction(new (GetAllocator()) HIf(parameter_));
+  if_block->AddInstruction(new (GetAllocator()) HIf(parameters_[0]));
 
   HInstructionIterator it(header->GetPhis());
   DCHECK(!it.Done());
@@ -586,7 +594,7 @@
   // Change the loop3 - insert an exit which leads to loop1.
   HBasicBlock* loop3_extra_if_block = new (GetAllocator()) HBasicBlock(graph_);
   graph_->AddBlock(loop3_extra_if_block);
-  loop3_extra_if_block->AddInstruction(new (GetAllocator()) HIf(parameter_));
+  loop3_extra_if_block->AddInstruction(new (GetAllocator()) HIf(parameters_[0]));
 
   loop3_header->ReplaceSuccessor(loop_body3, loop3_extra_if_block);
   loop3_extra_if_block->AddSuccessor(loop_body1);  // Long exit.