ART: Add compiler option for code deduplication

Add --deduplicate-code and --no-deduplicate-code to ease in
experiments with deduplication, e.g., profiling.

Add dex2oat test.

Test: m test-art-host
Change-Id: Ib6c7fe082f43c5f76c8463cc563e2503c9a50480
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index bd78af4..a9d27ef 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -320,6 +320,8 @@
   if (GetCompilerOptions().IsBootImage()) {
     CHECK(image_classes_.get() != nullptr) << "Expected image classes for boot image";
   }
+
+  compiled_method_storage_.SetDedupeEnabled(compiler_options_->DeduplicateCode());
 }
 
 CompilerDriver::~CompilerDriver() {
diff --git a/compiler/driver/compiler_options.cc b/compiler/driver/compiler_options.cc
index f789314..032763c 100644
--- a/compiler/driver/compiler_options.cc
+++ b/compiler/driver/compiler_options.cc
@@ -56,6 +56,7 @@
       dump_cfg_file_name_(""),
       dump_cfg_append_(false),
       force_determinism_(false),
+      deduplicate_code_(true),
       register_allocation_strategy_(RegisterAllocator::kRegisterAllocatorDefault),
       passes_to_run_(nullptr) {
 }
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 12de9be..ab2a681 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -254,6 +254,10 @@
     return force_determinism_;
   }
 
+  bool DeduplicateCode() const {
+    return deduplicate_code_;
+  }
+
   RegisterAllocator::Strategy GetRegisterAllocationStrategy() const {
     return register_allocation_strategy_;
   }
@@ -319,6 +323,9 @@
   // outcomes.
   bool force_determinism_;
 
+  // Whether code should be deduplicated.
+  bool deduplicate_code_;
+
   RegisterAllocator::Strategy register_allocation_strategy_;
 
   // If not null, specifies optimization passes which will be run instead of defaults.
diff --git a/compiler/driver/compiler_options_map-inl.h b/compiler/driver/compiler_options_map-inl.h
index 772d1b4..e28d499 100644
--- a/compiler/driver/compiler_options_map-inl.h
+++ b/compiler/driver/compiler_options_map-inl.h
@@ -76,6 +76,7 @@
     }
   }
   map.AssignIfExists(Base::VerboseMethods, &options->verbose_methods_);
+  options->deduplicate_code_ = map.GetOrDefault(Base::DeduplicateCode);
 
   return true;
 }
@@ -123,6 +124,11 @@
           .WithValues({true, false})
           .IntoKey(Map::GenerateBuildID)
 
+      .Define({"--deduplicate-code=_"})
+          .template WithType<bool>()
+          .WithValueMap({{"false", false}, {"true", true}})
+          .IntoKey(Map::DeduplicateCode)
+
       .Define("--debuggable")
           .IntoKey(Map::Debuggable)
 
diff --git a/compiler/driver/compiler_options_map.def b/compiler/driver/compiler_options_map.def
index cc75634..cccd618 100644
--- a/compiler/driver/compiler_options_map.def
+++ b/compiler/driver/compiler_options_map.def
@@ -57,5 +57,6 @@
 // TODO: Add type parser.
 COMPILER_OPTIONS_KEY (std::string,                 RegisterAllocationStrategy)
 COMPILER_OPTIONS_KEY (ParseStringList<','>,        VerboseMethods)
+COMPILER_OPTIONS_KEY (bool,                        DeduplicateCode,        true)
 
 #undef COMPILER_OPTIONS_KEY