ART: Reduce dependencies on CompilerDriver.

Preparation for moving CompilerDriver and other stuff
from libart-compiler.so to dex2oat.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: Ic221ebca4b8c79dd1549316921ace655f2e3f0fe
diff --git a/compiler/compiler.cc b/compiler/compiler.cc
index 54da446..d044c2f 100644
--- a/compiler/compiler.cc
+++ b/compiler/compiler.cc
@@ -22,17 +22,18 @@
 #include "base/utils.h"
 #include "dex/code_item_accessors-inl.h"
 #include "dex/dex_file.h"
-#include "driver/compiler_driver.h"
 #include "optimizing/optimizing_compiler.h"
 
 namespace art {
 
-Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) {
+Compiler* Compiler::Create(const CompilerOptions& compiler_options,
+                           CompiledMethodStorage* storage,
+                           Compiler::Kind kind) {
   switch (kind) {
     case kQuick:
       // TODO: Remove Quick in options.
     case kOptimizing:
-      return CreateOptimizingCompiler(driver);
+      return CreateOptimizingCompiler(compiler_options, storage);
 
     default:
       LOG(FATAL) << "UNREACHABLE";
diff --git a/compiler/compiler.h b/compiler/compiler.h
index 8a67724..a496c6c 100644
--- a/compiler/compiler.h
+++ b/compiler/compiler.h
@@ -36,8 +36,9 @@
 }  // namespace mirror
 
 class ArtMethod;
-class CompilerDriver;
 class CompiledMethod;
+class CompiledMethodStorage;
+class CompilerOptions;
 class DexFile;
 template<class T> class Handle;
 class OatWriter;
@@ -50,11 +51,9 @@
     kOptimizing
   };
 
-  static Compiler* Create(CompilerDriver* driver, Kind kind);
-
-  virtual void Init() = 0;
-
-  virtual void UnInit() const = 0;
+  static Compiler* Create(const CompilerOptions& compiler_options,
+                          CompiledMethodStorage* storage,
+                          Kind kind);
 
   virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const = 0;
 
@@ -91,19 +90,6 @@
 
   virtual ~Compiler() {}
 
-  /*
-   * @brief Generate and return Dwarf CFI initialization, if supported by the
-   * backend.
-   * @param driver CompilerDriver for this compile.
-   * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
-   * information.
-   * @note This is used for backtrace information in generated code.
-   */
-  virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(
-      const CompilerDriver& driver ATTRIBUTE_UNUSED) const {
-    return nullptr;
-  }
-
   // Returns whether the method to compile is such a pathological case that
   // it's not worth compiling.
   static bool IsPathologicalCase(const dex::CodeItem& code_item,
@@ -111,16 +97,25 @@
                                  const DexFile& dex_file);
 
  protected:
-  Compiler(CompilerDriver* driver, uint64_t warning) :
-      driver_(driver), maximum_compilation_time_before_warning_(warning) {
+  Compiler(const CompilerOptions& compiler_options,
+           CompiledMethodStorage* storage,
+           uint64_t warning) :
+      compiler_options_(compiler_options),
+      storage_(storage),
+      maximum_compilation_time_before_warning_(warning) {
   }
 
-  CompilerDriver* GetCompilerDriver() const {
-    return driver_;
+  const CompilerOptions& GetCompilerOptions() const {
+    return compiler_options_;
+  }
+
+  CompiledMethodStorage* GetCompiledMethodStorage() const {
+    return storage_;
   }
 
  private:
-  CompilerDriver* const driver_;
+  const CompilerOptions& compiler_options_;
+  CompiledMethodStorage* const storage_;
   const uint64_t maximum_compilation_time_before_warning_;
 
   DISALLOW_COPY_AND_ASSIGN(Compiler);
diff --git a/compiler/dex/verification_results.cc b/compiler/dex/verification_results.cc
index 6bd5fe8..e7a3817 100644
--- a/compiler/dex/verification_results.cc
+++ b/compiler/dex/verification_results.cc
@@ -20,7 +20,6 @@
 
 #include "base/mutex-inl.h"
 #include "base/stl_util.h"
-#include "driver/compiler_driver.h"
 #include "driver/compiler_options.h"
 #include "runtime.h"
 #include "thread-current-inl.h"
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index f39d8fc..e9a3d55 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -258,7 +258,7 @@
     size_t thread_count,
     int swap_fd)
     : compiler_options_(compiler_options),
-      compiler_(Compiler::Create(this, compiler_kind)),
+      compiler_(),
       compiler_kind_(compiler_kind),
       number_of_soft_verifier_failures_(0),
       had_hard_verifier_failure_(false),
@@ -269,9 +269,8 @@
       dex_to_dex_compiler_(this) {
   DCHECK(compiler_options_ != nullptr);
 
-  compiler_->Init();
-
   compiled_method_storage_.SetDedupeEnabled(compiler_options_->DeduplicateCode());
+  compiler_.reset(Compiler::Create(*compiler_options, &compiled_method_storage_, compiler_kind));
 }
 
 CompilerDriver::~CompilerDriver() {
@@ -281,7 +280,6 @@
       CompiledMethod::ReleaseSwapAllocatedCompiledMethod(GetCompiledMethodStorage(), method);
     }
   });
-  compiler_->UnInit();
 }
 
 
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 6f8ec12..199835c 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -22,8 +22,6 @@
 #include <string>
 #include <vector>
 
-#include "android-base/strings.h"
-
 #include "arch/instruction_set.h"
 #include "base/array_ref.h"
 #include "base/bit_utils.h"
@@ -246,23 +244,6 @@
     return &compiled_method_storage_;
   }
 
-  // Is `boot_image_filename` the name of a core image (small boot
-  // image used for ART testing only)?
-  static bool IsCoreImageFilename(const std::string& boot_image_filename) {
-    // Look for "core.art" or "core-*.art".
-    if (android::base::EndsWith(boot_image_filename, "core.art")) {
-      return true;
-    }
-    if (!android::base::EndsWith(boot_image_filename, ".art")) {
-      return false;
-    }
-    size_t slash_pos = boot_image_filename.rfind('/');
-    if (slash_pos == std::string::npos) {
-      return android::base::StartsWith(boot_image_filename, "core-");
-    }
-    return boot_image_filename.compare(slash_pos + 1, 5u, "core-") == 0;
-  }
-
   optimizer::DexToDexCompiler& GetDexToDexCompiler() {
     return dex_to_dex_compiler_;
   }
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc
index 7dd743f..6f39488 100644
--- a/compiler/driver/compiler_options.cc
+++ b/compiler/driver/compiler_options.cc
@@ -20,6 +20,7 @@
 #include <string_view>
 
 #include "android-base/stringprintf.h"
+#include "android-base/strings.h"
 
 #include "arch/instruction_set.h"
 #include "arch/instruction_set_features.h"
@@ -184,4 +185,19 @@
   return is_system_class;
 }
 
+bool CompilerOptions::IsCoreImageFilename(const std::string& boot_image_filename) {
+  // Look for "core.art" or "core-*.art".
+  if (android::base::EndsWith(boot_image_filename, "core.art")) {
+    return true;
+  }
+  if (!android::base::EndsWith(boot_image_filename, ".art")) {
+    return false;
+  }
+  size_t slash_pos = boot_image_filename.rfind('/');
+  if (slash_pos == std::string::npos) {
+    return android::base::StartsWith(boot_image_filename, "core-");
+  }
+  return boot_image_filename.compare(slash_pos + 1, 5u, "core-") == 0;
+}
+
 }  // namespace art
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index fccd9ca..25d7b36 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -359,6 +359,10 @@
     max_image_block_size_ = size;
   }
 
+  // Is `boot_image_filename` the name of a core image (small boot
+  // image used for ART testing only)?
+  static bool IsCoreImageFilename(const std::string& boot_image_filename);
+
  private:
   bool ParseDumpInitFailures(const std::string& option, std::string* error_msg);
   bool ParseRegisterAllocationStrategy(const std::string& option, std::string* error_msg);
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index 2c20b32..bbf3458 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -26,8 +26,8 @@
 #include "base/systrace.h"
 #include "base/time_utils.h"
 #include "base/timing_logger.h"
+#include "compiler.h"
 #include "debug/elf_debug_writer.h"
-#include "driver/compiler_driver.h"
 #include "driver/compiler_options.h"
 #include "jit/debugger_interface.h"
 #include "jit/jit.h"
@@ -107,7 +107,7 @@
   }
   compiler_options_->instruction_set_features_ = std::move(instruction_set_features);
   compiler_options_->compiling_with_core_image_ =
-      CompilerDriver::IsCoreImageFilename(runtime->GetImageLocation());
+      CompilerOptions::IsCoreImageFilename(runtime->GetImageLocation());
 
   if (compiler_options_->GetGenerateDebugInfo()) {
     jit_logger_.reset(new JitLogger());
@@ -171,14 +171,8 @@
 JitCompiler::JitCompiler() {
   compiler_options_.reset(new CompilerOptions());
   ParseCompilerOptions();
-
-  compiler_driver_.reset(new CompilerDriver(
-      compiler_options_.get(),
-      Compiler::kOptimizing,
-      /* thread_count= */ 1,
-      /* swap_fd= */ -1));
-  // Disable dedupe so we can remove compiled methods.
-  compiler_driver_->SetDedupeEnabled(false);
+  compiler_.reset(
+      Compiler::Create(*compiler_options_, /*storage=*/ nullptr, Compiler::kOptimizing));
 }
 
 JitCompiler::~JitCompiler() {
@@ -203,8 +197,7 @@
   {
     TimingLogger::ScopedTiming t2("Compiling", &logger);
     JitCodeCache* const code_cache = runtime->GetJit()->GetCodeCache();
-    success = compiler_driver_->GetCompiler()->JitCompile(
-        self, code_cache, method, baseline, osr, jit_logger_.get());
+    success = compiler_->JitCompile(self, code_cache, method, baseline, osr, jit_logger_.get());
   }
 
   // Trim maps to reduce memory usage.
diff --git a/compiler/jit/jit_compiler.h b/compiler/jit/jit_compiler.h
index 29d2761..d008de4 100644
--- a/compiler/jit/jit_compiler.h
+++ b/compiler/jit/jit_compiler.h
@@ -23,7 +23,7 @@
 
 class ArtMethod;
 class CompiledMethod;
-class CompilerDriver;
+class Compiler;
 class CompilerOptions;
 class Thread;
 
@@ -44,15 +44,11 @@
     return *compiler_options_.get();
   }
 
-  CompilerDriver* GetCompilerDriver() const {
-    return compiler_driver_.get();
-  }
-
   void ParseCompilerOptions();
 
  private:
   std::unique_ptr<CompilerOptions> compiler_options_;
-  std::unique_ptr<CompilerDriver> compiler_driver_;
+  std::unique_ptr<Compiler> compiler_;
   std::unique_ptr<JitLogger> jit_logger_;
 
   JitCompiler();
diff --git a/compiler/jit/jit_logger.cc b/compiler/jit/jit_logger.cc
index 2199b64..6b9453f 100644
--- a/compiler/jit/jit_logger.cc
+++ b/compiler/jit/jit_logger.cc
@@ -20,7 +20,6 @@
 #include "art_method-inl.h"
 #include "base/time_utils.h"
 #include "base/unix_file/fd_file.h"
-#include "driver/compiler_driver.h"
 #include "jit/jit.h"
 #include "jit/jit_code_cache.h"
 #include "oat_file-inl.h"
diff --git a/compiler/jit/jit_logger.h b/compiler/jit/jit_logger.h
index 8b39888..f4ef75a 100644
--- a/compiler/jit/jit_logger.h
+++ b/compiler/jit/jit_logger.h
@@ -17,10 +17,11 @@
 #ifndef ART_COMPILER_JIT_JIT_LOGGER_H_
 #define ART_COMPILER_JIT_JIT_LOGGER_H_
 
+#include <memory>
+
 #include "base/mutex.h"
+#include "base/os.h"
 #include "compiled_method.h"
-#include "driver/compiler_driver.h"
-#include "driver/compiler_options.h"
 
 namespace art {
 
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 122f27b..cc2ff16 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -49,7 +49,6 @@
 #include "dex/bytecode_utils.h"
 #include "dex/code_item_accessors-inl.h"
 #include "dex/verified_method.h"
-#include "driver/compiler_driver.h"
 #include "graph_visualizer.h"
 #include "image.h"
 #include "gc/space/image_space.h"
diff --git a/compiler/optimizing/inliner.h b/compiler/optimizing/inliner.h
index efd4c74..15d7349 100644
--- a/compiler/optimizing/inliner.h
+++ b/compiler/optimizing/inliner.h
@@ -25,7 +25,6 @@
 namespace art {
 
 class CodeGenerator;
-class CompilerDriver;
 class DexCompilationUnit;
 class HGraph;
 class HInvoke;
diff --git a/compiler/optimizing/optimization.h b/compiler/optimizing/optimization.h
index ce44b5f..b84e038 100644
--- a/compiler/optimizing/optimization.h
+++ b/compiler/optimizing/optimization.h
@@ -24,7 +24,6 @@
 namespace art {
 
 class CodeGenerator;
-class CompilerDriver;
 class DexCompilationUnit;
 
 /**
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 4f43b71..dd5d4a5 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -41,7 +41,7 @@
 #include "dex/dex_file_types.h"
 #include "dex/verification_results.h"
 #include "dex/verified_method.h"
-#include "driver/compiler_driver-inl.h"
+#include "driver/compiled_method_storage.h"
 #include "driver/compiler_options.h"
 #include "driver/dex_compilation_unit.h"
 #include "graph_checker.h"
@@ -107,22 +107,22 @@
   PassObserver(HGraph* graph,
                CodeGenerator* codegen,
                std::ostream* visualizer_output,
-               CompilerDriver* compiler_driver,
+               const CompilerOptions& compiler_options,
                Mutex& dump_mutex)
       : graph_(graph),
         last_seen_graph_size_(0),
         cached_method_name_(),
-        timing_logger_enabled_(compiler_driver->GetCompilerOptions().GetDumpPassTimings()),
+        timing_logger_enabled_(compiler_options.GetDumpPassTimings()),
         timing_logger_(timing_logger_enabled_ ? GetMethodName() : "", true, true),
         disasm_info_(graph->GetAllocator()),
         visualizer_oss_(),
         visualizer_output_(visualizer_output),
-        visualizer_enabled_(!compiler_driver->GetCompilerOptions().GetDumpCfgFileName().empty()),
+        visualizer_enabled_(!compiler_options.GetDumpCfgFileName().empty()),
         visualizer_(&visualizer_oss_, graph, *codegen),
         visualizer_dump_mutex_(dump_mutex),
         graph_in_bad_state_(false) {
     if (timing_logger_enabled_ || visualizer_enabled_) {
-      if (!IsVerboseMethod(compiler_driver, GetMethodName())) {
+      if (!IsVerboseMethod(compiler_options, GetMethodName())) {
         timing_logger_enabled_ = visualizer_enabled_ = false;
       }
       if (visualizer_enabled_) {
@@ -200,11 +200,11 @@
     }
   }
 
-  static bool IsVerboseMethod(CompilerDriver* compiler_driver, const char* method_name) {
+  static bool IsVerboseMethod(const CompilerOptions& compiler_options, const char* method_name) {
     // Test an exact match to --verbose-methods. If verbose-methods is set, this overrides an
     // empty kStringFilter matching all methods.
-    if (compiler_driver->GetCompilerOptions().HasVerboseMethods()) {
-      return compiler_driver->GetCompilerOptions().IsVerboseMethod(method_name);
+    if (compiler_options.HasVerboseMethods()) {
+      return compiler_options.IsVerboseMethod(method_name);
     }
 
     // Test the kStringFilter sub-string. constexpr helper variable to silence unreachable-code
@@ -267,7 +267,8 @@
 
 class OptimizingCompiler final : public Compiler {
  public:
-  explicit OptimizingCompiler(CompilerDriver* driver);
+  explicit OptimizingCompiler(const CompilerOptions& compiler_options,
+                              CompiledMethodStorage* storage);
   ~OptimizingCompiler() override;
 
   bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file) const override;
@@ -289,13 +290,9 @@
   uintptr_t GetEntryPointOf(ArtMethod* method) const override
       REQUIRES_SHARED(Locks::mutator_lock_) {
     return reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCodePtrSize(
-        InstructionSetPointerSize(GetCompilerDriver()->GetCompilerOptions().GetInstructionSet())));
+        InstructionSetPointerSize(GetCompilerOptions().GetInstructionSet())));
   }
 
-  void Init() override;
-
-  void UnInit() const override;
-
   bool JitCompile(Thread* self,
                   jit::JitCodeCache* code_cache,
                   ArtMethod* method,
@@ -422,28 +419,22 @@
 
 static const int kMaximumCompilationTimeBeforeWarning = 100; /* ms */
 
-OptimizingCompiler::OptimizingCompiler(CompilerDriver* driver)
-    : Compiler(driver, kMaximumCompilationTimeBeforeWarning),
-      dump_mutex_("Visualizer dump lock") {}
-
-void OptimizingCompiler::Init() {
-  // Enable C1visualizer output. Must be done in Init() because the compiler
-  // driver is not fully initialized when passed to the compiler's constructor.
-  CompilerDriver* driver = GetCompilerDriver();
-  const std::string cfg_file_name = driver->GetCompilerOptions().GetDumpCfgFileName();
+OptimizingCompiler::OptimizingCompiler(const CompilerOptions& compiler_options,
+                                       CompiledMethodStorage* storage)
+    : Compiler(compiler_options, storage, kMaximumCompilationTimeBeforeWarning),
+      dump_mutex_("Visualizer dump lock") {
+  // Enable C1visualizer output.
+  const std::string& cfg_file_name = compiler_options.GetDumpCfgFileName();
   if (!cfg_file_name.empty()) {
     std::ios_base::openmode cfg_file_mode =
-        driver->GetCompilerOptions().GetDumpCfgAppend() ? std::ofstream::app : std::ofstream::out;
+        compiler_options.GetDumpCfgAppend() ? std::ofstream::app : std::ofstream::out;
     visualizer_output_.reset(new std::ofstream(cfg_file_name, cfg_file_mode));
   }
-  if (driver->GetCompilerOptions().GetDumpStats()) {
+  if (compiler_options.GetDumpStats()) {
     compilation_stats_.reset(new OptimizingCompilerStats());
   }
 }
 
-void OptimizingCompiler::UnInit() const {
-}
-
 OptimizingCompiler::~OptimizingCompiler() {
   if (compilation_stats_.get() != nullptr) {
     compilation_stats_->Log();
@@ -652,8 +643,7 @@
                                           const DexCompilationUnit& dex_compilation_unit,
                                           PassObserver* pass_observer,
                                           VariableSizedHandleScope* handles) const {
-  const std::vector<std::string>* pass_names =
-      GetCompilerDriver()->GetCompilerOptions().GetPassesToRun();
+  const std::vector<std::string>* pass_names = GetCompilerOptions().GetPassesToRun();
   if (pass_names != nullptr) {
     // If passes were defined on command-line, build the optimization
     // passes and run these instead of the built-in optimizations.
@@ -764,15 +754,15 @@
   ArenaVector<linker::LinkerPatch> linker_patches = EmitAndSortLinkerPatches(codegen);
   ScopedArenaVector<uint8_t> stack_map = codegen->BuildStackMaps(code_item_for_osr_check);
 
+  CompiledMethodStorage* storage = GetCompiledMethodStorage();
   CompiledMethod* compiled_method = CompiledMethod::SwapAllocCompiledMethod(
-      GetCompilerDriver()->GetCompiledMethodStorage(),
+      storage,
       codegen->GetInstructionSet(),
       code_allocator->GetMemory(),
       ArrayRef<const uint8_t>(stack_map),
       ArrayRef<const uint8_t>(*codegen->GetAssembler()->cfi().data()),
       ArrayRef<const linker::LinkerPatch>(linker_patches));
 
-  CompiledMethodStorage* storage = GetCompilerDriver()->GetCompiledMethodStorage();
   for (const linker::LinkerPatch& patch : linker_patches) {
     if (codegen->NeedsThunkCode(patch) && storage->GetThunkCode(patch).empty()) {
       ArenaVector<uint8_t> code(allocator->Adapter());
@@ -794,8 +784,7 @@
                                               bool osr,
                                               VariableSizedHandleScope* handles) const {
   MaybeRecordStat(compilation_stats_.get(), MethodCompilationStat::kAttemptBytecodeCompilation);
-  CompilerDriver* compiler_driver = GetCompilerDriver();
-  const CompilerOptions& compiler_options = compiler_driver->GetCompilerOptions();
+  const CompilerOptions& compiler_options = GetCompilerOptions();
   InstructionSet instruction_set = compiler_options.GetInstructionSet();
   const DexFile& dex_file = *dex_compilation_unit.GetDexFile();
   uint32_t method_idx = dex_compilation_unit.GetDexMethodIndex();
@@ -859,7 +848,7 @@
       compiler_options.GetInstructionSet(),
       kInvalidInvokeType,
       dead_reference_safe,
-      compiler_driver->GetCompilerOptions().GetDebuggable(),
+      compiler_options.GetDebuggable(),
       /* osr= */ osr);
 
   if (method != nullptr) {
@@ -874,13 +863,12 @@
     MaybeRecordStat(compilation_stats_.get(), MethodCompilationStat::kNotCompiledNoCodegen);
     return nullptr;
   }
-  codegen->GetAssembler()->cfi().SetEnabled(
-      compiler_driver->GetCompilerOptions().GenerateAnyDebugInfo());
+  codegen->GetAssembler()->cfi().SetEnabled(compiler_options.GenerateAnyDebugInfo());
 
   PassObserver pass_observer(graph,
                              codegen.get(),
                              visualizer_output_.get(),
-                             compiler_driver,
+                             compiler_options,
                              dump_mutex_);
 
   {
@@ -959,8 +947,7 @@
     ArtMethod* method,
     VariableSizedHandleScope* handles) const {
   MaybeRecordStat(compilation_stats_.get(), MethodCompilationStat::kAttemptIntrinsicCompilation);
-  CompilerDriver* compiler_driver = GetCompilerDriver();
-  const CompilerOptions& compiler_options = compiler_driver->GetCompilerOptions();
+  const CompilerOptions& compiler_options = GetCompilerOptions();
   InstructionSet instruction_set = compiler_options.GetInstructionSet();
   const DexFile& dex_file = *dex_compilation_unit.GetDexFile();
   uint32_t method_idx = dex_compilation_unit.GetDexMethodIndex();
@@ -1001,7 +988,7 @@
   PassObserver pass_observer(graph,
                              codegen.get(),
                              visualizer_output_.get(),
-                             compiler_driver,
+                             compiler_options,
                              dump_mutex_);
 
   {
@@ -1035,7 +1022,7 @@
   AllocateRegisters(graph,
                     codegen.get(),
                     &pass_observer,
-                    compiler_driver->GetCompilerOptions().GetRegisterAllocationStrategy(),
+                    compiler_options.GetRegisterAllocationStrategy(),
                     compilation_stats_.get());
   if (!codegen->IsLeafMethod()) {
     VLOG(compiler) << "Intrinsic method is not leaf: " << method->GetIntrinsic()
@@ -1060,8 +1047,7 @@
                                             Handle<mirror::ClassLoader> jclass_loader,
                                             const DexFile& dex_file,
                                             Handle<mirror::DexCache> dex_cache) const {
-  CompilerDriver* compiler_driver = GetCompilerDriver();
-  const CompilerOptions& compiler_options = compiler_driver->GetCompilerOptions();
+  const CompilerOptions& compiler_options = GetCompilerOptions();
   CompiledMethod* compiled_method = nullptr;
   Runtime* runtime = Runtime::Current();
   DCHECK(runtime->IsAotCompiler());
@@ -1194,7 +1180,7 @@
   ArenaAllocator allocator(runtime->GetArenaPool());
   ArenaStack arena_stack(runtime->GetArenaPool());
 
-  const CompilerOptions& compiler_options = GetCompilerDriver()->GetCompilerOptions();
+  const CompilerOptions& compiler_options = GetCompilerOptions();
   if (compiler_options.IsBootImage()) {
     ScopedObjectAccess soa(Thread::Current());
     ArtMethod* method = runtime->GetClassLinker()->LookupResolvedMethod(
@@ -1243,7 +1229,7 @@
   ScopedArenaVector<uint8_t> stack_map = CreateJniStackMap(
       &stack_map_allocator, jni_compiled_method, jni_compiled_method.GetCode().size());
   return CompiledMethod::SwapAllocCompiledMethod(
-      GetCompilerDriver()->GetCompiledMethodStorage(),
+      GetCompiledMethodStorage(),
       jni_compiled_method.GetInstructionSet(),
       jni_compiled_method.GetCode(),
       ArrayRef<const uint8_t>(stack_map),
@@ -1251,8 +1237,9 @@
       /* patches= */ ArrayRef<const linker::LinkerPatch>());
 }
 
-Compiler* CreateOptimizingCompiler(CompilerDriver* driver) {
-  return new OptimizingCompiler(driver);
+Compiler* CreateOptimizingCompiler(const CompilerOptions& compiler_options,
+                                   CompiledMethodStorage* storage) {
+  return new OptimizingCompiler(compiler_options, storage);
 }
 
 bool EncodeArtMethodInInlineInfo(ArtMethod* method ATTRIBUTE_UNUSED) {
@@ -1282,7 +1269,7 @@
   ArenaAllocator allocator(runtime->GetJitArenaPool());
 
   if (UNLIKELY(method->IsNative())) {
-    const CompilerOptions& compiler_options = GetCompilerDriver()->GetCompilerOptions();
+    const CompilerOptions& compiler_options = GetCompilerOptions();
     JniCompiledMethod jni_compiled_method = ArtQuickJniCompileMethod(
         compiler_options, access_flags, method_idx, *dex_file);
     std::vector<Handle<mirror::Object>> roots;
@@ -1431,7 +1418,7 @@
     return false;
   }
 
-  const CompilerOptions& compiler_options = GetCompilerDriver()->GetCompilerOptions();
+  const CompilerOptions& compiler_options = GetCompilerOptions();
   if (compiler_options.GenerateAnyDebugInfo()) {
     const auto* method_header = reinterpret_cast<const OatQuickMethodHeader*>(code);
     const uintptr_t code_address = reinterpret_cast<uintptr_t>(method_header->GetCode());
@@ -1478,7 +1465,7 @@
 
 void OptimizingCompiler::GenerateJitDebugInfo(ArtMethod* method ATTRIBUTE_UNUSED,
                                               const debug::MethodDebugInfo& info) {
-  const CompilerOptions& compiler_options = GetCompilerDriver()->GetCompilerOptions();
+  const CompilerOptions& compiler_options = GetCompilerOptions();
   DCHECK(compiler_options.GenerateAnyDebugInfo());
   TimingLogger logger("Generate JIT debug info logger", true, VLOG_IS_ON(jit));
   {
diff --git a/compiler/optimizing/optimizing_compiler.h b/compiler/optimizing/optimizing_compiler.h
index f5279e8..cd6d684 100644
--- a/compiler/optimizing/optimizing_compiler.h
+++ b/compiler/optimizing/optimizing_compiler.h
@@ -24,10 +24,12 @@
 
 class ArtMethod;
 class Compiler;
-class CompilerDriver;
+class CompiledMethodStorage;
+class CompilerOptions;
 class DexFile;
 
-Compiler* CreateOptimizingCompiler(CompilerDriver* driver);
+Compiler* CreateOptimizingCompiler(const CompilerOptions& compiler_options,
+                                   CompiledMethodStorage* storage);
 
 bool EncodeArtMethodInInlineInfo(ArtMethod* method);
 
diff --git a/compiler/optimizing/scheduler.h b/compiler/optimizing/scheduler.h
index 48e80f5..d2dbeca 100644
--- a/compiler/optimizing/scheduler.h
+++ b/compiler/optimizing/scheduler.h
@@ -23,7 +23,6 @@
 #include "base/scoped_arena_containers.h"
 #include "base/time_utils.h"
 #include "code_generator.h"
-#include "driver/compiler_driver.h"
 #include "load_store_analysis.h"
 #include "nodes.h"
 #include "optimization.h"