OSDN Git Service

Add dex2oat --print-pass-names and --disable-passes= options.
authorChao-ying Fu <chao-ying.fu@intel.com>
Tue, 11 Mar 2014 21:57:19 +0000 (14:57 -0700)
committerChao-ying Fu <chao-ying.fu@intel.com>
Wed, 12 Mar 2014 17:44:11 +0000 (10:44 -0700)
Add --print-pass-names to print a list of pass names.
Add --disable-passes= to disable one ore more passes
separated by comma.
Ex: Using --disable-passes=UseCount,BBOptimizations can disable UseCount
and BBOptimizations passes.

Change-Id: I0dffaf10547afdcca78a20d8e0e6b358bfb2ee8c
Signed-off-by: Chao-ying Fu <chao-ying.fu@intel.com>
compiler/dex/pass_driver.cc
compiler/dex/pass_driver.h
dex2oat/dex2oat.cc

index 291012f..72d3ea6 100644 (file)
@@ -82,31 +82,48 @@ void PassDriver::InsertPass(const Pass* new_pass) {
   pass_list_.push_back(new_pass);
 }
 
-void PassDriver::CreatePasses() {
-  /*
-   * Create the pass list. These passes are immutable and are shared across the threads.
-   *
-   * Advantage is that there will be no race conditions here.
-   * Disadvantage is the passes can't change their internal states depending on CompilationUnit:
-   *   - This is not yet an issue: no current pass would require it.
-   */
-  static const Pass* const passes[] = {
-      GetPassInstance<CacheFieldLoweringInfo>(),
-      GetPassInstance<CacheMethodLoweringInfo>(),
-      GetPassInstance<CodeLayout>(),
-      GetPassInstance<SSATransformation>(),
-      GetPassInstance<ConstantPropagation>(),
-      GetPassInstance<InitRegLocations>(),
-      GetPassInstance<MethodUseCount>(),
-      GetPassInstance<NullCheckEliminationAndTypeInferenceInit>(),
-      GetPassInstance<NullCheckEliminationAndTypeInference>(),
-      GetPassInstance<BBCombine>(),
-      GetPassInstance<BBOptimizations>(),
-  };
+/*
+ * Create the pass list. These passes are immutable and are shared across the threads.
+ *
+ * Advantage is that there will be no race conditions here.
+ * Disadvantage is the passes can't change their internal states depending on CompilationUnit:
+ *   - This is not yet an issue: no current pass would require it.
+ */
+static const Pass* const gPasses[] = {
+  GetPassInstance<CacheFieldLoweringInfo>(),
+  GetPassInstance<CacheMethodLoweringInfo>(),
+  GetPassInstance<CodeLayout>(),
+  GetPassInstance<SSATransformation>(),
+  GetPassInstance<ConstantPropagation>(),
+  GetPassInstance<InitRegLocations>(),
+  GetPassInstance<MethodUseCount>(),
+  GetPassInstance<NullCheckEliminationAndTypeInferenceInit>(),
+  GetPassInstance<NullCheckEliminationAndTypeInference>(),
+  GetPassInstance<BBCombine>(),
+  GetPassInstance<BBOptimizations>(),
+};
+
+// The default pass list is used by CreatePasses to initialize pass_list_.
+static std::vector<const Pass*> gDefaultPassList(gPasses, gPasses + arraysize(gPasses));
+
+void PassDriver::CreateDefaultPassList(const std::string& disable_passes) {
+  // Insert each pass from gPasses into gDefaultPassList.
+  gDefaultPassList.clear();
+  gDefaultPassList.reserve(arraysize(gPasses));
+  for (const Pass* pass : gPasses) {
+    // Check if we should disable this pass.
+    if (disable_passes.find(pass->GetName()) != std::string::npos) {
+      LOG(INFO) << "Skipping " << pass->GetName();
+    } else {
+      gDefaultPassList.push_back(pass);
+    }
+  }
+}
 
+void PassDriver::CreatePasses() {
   // Insert each pass into the list via the InsertPass method.
-  pass_list_.reserve(arraysize(passes));
-  for (const Pass* pass : passes) {
+  pass_list_.reserve(gDefaultPassList.size());
+  for (const Pass* pass : gDefaultPassList) {
     InsertPass(pass);
   }
 }
@@ -221,10 +238,10 @@ void PassDriver::Launch() {
   }
 }
 
-void PassDriver::PrintPassNames() const {
+void PassDriver::PrintPassNames() {
   LOG(INFO) << "Loop Passes are:";
 
-  for (const Pass* cur_pass : pass_list_) {
+  for (const Pass* cur_pass : gPasses) {
     LOG(INFO) << "\t-" << cur_pass->GetName();
   }
 }
index c734d3e..2b7196e 100644 (file)
@@ -73,7 +73,8 @@ class PassDriver {
    */
   void DispatchPass(CompilationUnit* c_unit, const Pass* pass);
 
-  void PrintPassNames() const;
+  static void PrintPassNames();
+  static void CreateDefaultPassList(const std::string& disable_passes);
 
   const Pass* GetPass(const char* name) const;
 
index cc78816..b51efc4 100644 (file)
@@ -33,6 +33,7 @@
 #include "compiler_backend.h"
 #include "compiler_callbacks.h"
 #include "dex_file-inl.h"
+#include "dex/pass_driver.h"
 #include "dex/verification_results.h"
 #include "driver/compiler_callbacks_impl.h"
 #include "driver/compiler_driver.h"
@@ -203,6 +204,11 @@ static void Usage(const char* fmt, ...) {
     UsageError("");
     UsageError("  --profile-file=<filename>: specify profiler output file to use for compilation.");
   UsageError("");
+  UsageError("  --print-pass-names: print a list of pass names");
+  UsageError("");
+  UsageError("  --disable-passes=<pass-names>:  disable one or more passes separated by comma.");
+  UsageError("      Example: --disable-passes=UseCount,BBOptimizations");
+  UsageError("");
   std::cerr << "See log for usage error information\n";
   exit(EXIT_FAILURE);
 }
@@ -908,6 +914,11 @@ static int dex2oat(int argc, char** argv) {
     } else if (option == "--no-profile-file") {
       LOG(INFO) << "dex2oat: no profile file supplied (explictly)";
       // No profile
+    } else if (option == "--print-pass-names") {
+      PassDriver::PrintPassNames();
+    } else if (option.starts_with("--disable-passes=")) {
+      std::string disable_passes = option.substr(strlen("--disable-passes=")).data();
+      PassDriver::CreateDefaultPassList(disable_passes);
     } else {
       Usage("Unknown argument %s", option.data());
     }