Move instruction_set_ to CompilerOptions.

Removes CompilerDriver dependency from ImageWriter and
several other classes.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Test: Pixel 2 XL boots.
Test: m test-art-target-gtest
Test: testrunner.py --target --optimizing
Change-Id: I3c5b8ff73732128b9c4fad9405231a216ea72465
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 52c767f..22720ce 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -153,11 +153,7 @@
   {
     ScopedObjectAccess soa(Thread::Current());
 
-    const InstructionSet instruction_set = kRuntimeISA;
-    // Take the default set of instruction features from the build.
-    instruction_set_features_ = InstructionSetFeatures::FromCppDefines();
-
-    runtime_->SetInstructionSet(instruction_set);
+    runtime_->SetInstructionSet(instruction_set_);
     for (uint32_t i = 0; i < static_cast<uint32_t>(CalleeSaveType::kLastCalleeSaveType); ++i) {
       CalleeSaveType type = CalleeSaveType(i);
       if (!runtime_->HasCalleeSaveMethod(type)) {
@@ -165,23 +161,48 @@
       }
     }
 
-    CreateCompilerDriver(compiler_kind_, instruction_set);
+    CreateCompilerDriver();
   }
 }
 
-void CommonCompilerTest::CreateCompilerDriver(Compiler::Kind kind,
-                                              InstructionSet isa,
-                                              size_t number_of_threads) {
+void CommonCompilerTest::ApplyInstructionSet() {
+  // Copy local instruction_set_ and instruction_set_features_ to *compiler_options_;
+  CHECK(instruction_set_features_ != nullptr);
+  if (instruction_set_ == InstructionSet::kThumb2) {
+    CHECK_EQ(InstructionSet::kArm, instruction_set_features_->GetInstructionSet());
+  } else {
+    CHECK_EQ(instruction_set_, instruction_set_features_->GetInstructionSet());
+  }
+  compiler_options_->instruction_set_ = instruction_set_;
+  compiler_options_->instruction_set_features_ =
+      InstructionSetFeatures::FromBitmap(instruction_set_, instruction_set_features_->AsBitmap());
+  CHECK(compiler_options_->instruction_set_features_->Equals(instruction_set_features_.get()));
+}
+
+void CommonCompilerTest::OverrideInstructionSetFeatures(InstructionSet instruction_set,
+                                                        const std::string& variant) {
+  instruction_set_ = instruction_set;
+  std::string error_msg;
+  instruction_set_features_ =
+      InstructionSetFeatures::FromVariant(instruction_set, variant, &error_msg);
+  CHECK(instruction_set_features_ != nullptr) << error_msg;
+
+  if (compiler_options_ != nullptr) {
+    ApplyInstructionSet();
+  }
+}
+
+void CommonCompilerTest::CreateCompilerDriver() {
+  ApplyInstructionSet();
+
   compiler_options_->boot_image_ = true;
   compiler_options_->SetCompilerFilter(GetCompilerFilter());
   compiler_options_->image_classes_.swap(*GetImageClasses());
   compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
                                             verification_results_.get(),
-                                            kind,
-                                            isa,
-                                            instruction_set_features_.get(),
+                                            compiler_kind_,
                                             &compiler_options_->image_classes_,
-                                            number_of_threads,
+                                            number_of_threads_,
                                             /* swap_fd */ -1,
                                             GetProfileCompilationInfo()));
   // We typically don't generate an image in unit tests, disable this optimization by default.
@@ -207,11 +228,6 @@
   compiler_kind_ = compiler_kind;
 }
 
-InstructionSet CommonCompilerTest::GetInstructionSet() const {
-  DCHECK(compiler_driver_.get() != nullptr);
-  return compiler_driver_->GetInstructionSet();
-}
-
 void CommonCompilerTest::TearDown() {
   compiler_driver_.reset();
   callbacks_.reset();
@@ -339,4 +355,8 @@
   compiler_driver_->dex_to_dex_compiler_.SetDexFiles(dex_files);
 }
 
+void CommonCompilerTest::ClearBootImageOption() {
+  compiler_options_->boot_image_ = false;
+}
+
 }  // namespace art