Add option to append to the cfg dump.

This makes life easier when verifying tests with unresolved classes
(which call dex2oat at rutime).

Change-Id: I7985b2b7c0f343462e03a26b8395297c810b1d95
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 4b67884..1727657 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -192,7 +192,7 @@
                                               GetImageClasses(),
                                               GetCompiledClasses(),
                                               GetCompiledMethods(),
-                                              2, true, true, "", timer_.get(), -1, ""));
+                                              2, true, true, "", false, timer_.get(), -1, ""));
   }
   // We typically don't generate an image in unit tests, disable this optimization by default.
   compiler_driver_->SetSupportBootImageFixup(false);
diff --git a/compiler/dex/quick/quick_cfi_test.cc b/compiler/dex/quick/quick_cfi_test.cc
index 16c161e..18c2e55 100644
--- a/compiler/dex/quick/quick_cfi_test.cc
+++ b/compiler/dex/quick/quick_cfi_test.cc
@@ -77,7 +77,7 @@
     isa_features.reset(InstructionSetFeatures::FromVariant(isa, "default", &error));
     CompilerDriver driver(&compiler_options, &verification_results, &method_inliner_map,
                           Compiler::kQuick, isa, isa_features.get(),
-                          false, nullptr, nullptr, nullptr, 0, false, false, "", 0, -1, "");
+                          false, nullptr, nullptr, nullptr, 0, false, false, "", false, 0, -1, "");
     ClassLinker* linker = nullptr;
     CompilationUnit cu(&pool, isa, &driver, linker);
     DexFile::CodeItem code_item { 0, 0, 0, 0, 0, 0, { 0 } };  // NOLINT
diff --git a/compiler/dex/quick/x86/quick_assemble_x86_test.cc b/compiler/dex/quick/x86/quick_assemble_x86_test.cc
index 98e9f38..d9571c5 100644
--- a/compiler/dex/quick/x86/quick_assemble_x86_test.cc
+++ b/compiler/dex/quick/x86/quick_assemble_x86_test.cc
@@ -70,6 +70,7 @@
         false,
         false,
         "",
+        false,
         0,
         -1,
         ""));
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index 4c1408a..8d41595 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -345,8 +345,9 @@
                                std::unordered_set<std::string>* compiled_classes,
                                std::unordered_set<std::string>* compiled_methods,
                                size_t thread_count, bool dump_stats, bool dump_passes,
-                               const std::string& dump_cfg_file_name, CumulativeLogger* timer,
-                               int swap_fd, const std::string& profile_file)
+                               const std::string& dump_cfg_file_name, bool dump_cfg_append,
+                               CumulativeLogger* timer, int swap_fd,
+                               const std::string& profile_file)
     : swap_space_(swap_fd == -1 ? nullptr : new SwapSpace(swap_fd, 10 * MB)),
       swap_space_allocator_(new SwapAllocator<void>(swap_space_.get())),
       profile_present_(false), compiler_options_(compiler_options),
@@ -372,6 +373,7 @@
       dump_stats_(dump_stats),
       dump_passes_(dump_passes),
       dump_cfg_file_name_(dump_cfg_file_name),
+      dump_cfg_append_(dump_cfg_append),
       timings_logger_(timer),
       compiler_context_(nullptr),
       support_boot_image_fixup_(instruction_set != kMips && instruction_set != kMips64),
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index b229184..11e782f 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -99,7 +99,7 @@
                  std::unordered_set<std::string>* compiled_classes,
                  std::unordered_set<std::string>* compiled_methods,
                  size_t thread_count, bool dump_stats, bool dump_passes,
-                 const std::string& dump_cfg_file_name,
+                 const std::string& dump_cfg_file_name, bool dump_cfg_append,
                  CumulativeLogger* timer, int swap_fd,
                  const std::string& profile_file);
 
@@ -426,6 +426,10 @@
     return dump_cfg_file_name_;
   }
 
+  bool GetDumpCfgAppend() const {
+    return dump_cfg_append_;
+  }
+
   CumulativeLogger* GetTimingsLogger() const {
     return timings_logger_;
   }
@@ -667,6 +671,7 @@
   bool dump_stats_;
   const bool dump_passes_;
   const std::string dump_cfg_file_name_;
+  const bool dump_cfg_append_;
 
   CumulativeLogger* const timings_logger_;
 
diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc
index 4215f3c..b6a40a2 100644
--- a/compiler/jit/jit_compiler.cc
+++ b/compiler/jit/jit_compiler.cc
@@ -108,6 +108,7 @@
       /* dump_stats */ false,
       /* dump_passes */ false,
       /* dump_cfg_file_name */ "",
+      /* dump_cfg_append */ false,
       cumulative_logger_.get(),
       /* swap_fd */ -1,
       /* profile_file */ ""));
diff --git a/compiler/linker/relative_patcher_test.h b/compiler/linker/relative_patcher_test.h
index 1f7500a..31d1bce 100644
--- a/compiler/linker/relative_patcher_test.h
+++ b/compiler/linker/relative_patcher_test.h
@@ -46,7 +46,7 @@
         driver_(&compiler_options_, &verification_results_, &inliner_map_,
                 Compiler::kQuick, instruction_set, nullptr,
                 false, nullptr, nullptr, nullptr, 1u,
-                false, false, "", nullptr, -1, ""),
+                false, false, "", false, nullptr, -1, ""),
         error_msg_(),
         instruction_set_(instruction_set),
         features_(InstructionSetFeatures::FromVariant(instruction_set, variant, &error_msg_)),
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index 88dc29e..2d9d91a 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -94,7 +94,7 @@
                                             method_inliner_map_.get(),
                                             compiler_kind, insn_set,
                                             insn_features.get(), false, nullptr, nullptr, nullptr,
-                                            2, true, true, "", timer_.get(), -1, ""));
+                                            2, true, true, "", false, timer_.get(), -1, ""));
   jobject class_loader = nullptr;
   if (kCompile) {
     TimingLogger timings2("OatTest::WriteRead", false, false);
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 4421460..4d1a1ad 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -333,7 +333,9 @@
     CHECK_EQ(driver->GetThreadCount(), 1U)
       << "Graph visualizer requires the compiler to run single-threaded. "
       << "Invoke the compiler with '-j1'.";
-    visualizer_output_.reset(new std::ofstream(cfg_file_name));
+    std::ios_base::openmode cfg_file_mode =
+        driver->GetDumpCfgAppend() ? std::ofstream::app : std::ofstream::out;
+    visualizer_output_.reset(new std::ofstream(cfg_file_name, cfg_file_mode));
   }
   if (driver->GetDumpStats()) {
     compilation_stats_.reset(new OptimizingCompilerStats());
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index f9520be..68e2ef5 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -523,6 +523,7 @@
       dump_passes_(false),
       dump_timing_(false),
       dump_slow_timing_(kIsDebugBuild),
+      dump_cfg_append_(false),
       swap_fd_(-1),
       timings_(timings) {}
 
@@ -1096,6 +1097,8 @@
         dump_passes_ = true;
       } else if (option.starts_with("--dump-cfg=")) {
         dump_cfg_file_name_ = option.substr(strlen("--dump-cfg=")).data();
+      } else if (option.starts_with("--dump-cfg-append")) {
+        dump_cfg_append_ = true;
       } else if (option == "--dump-stats") {
         dump_stats_ = true;
       } else if (option == "--generate-debug-info" || option == "-g") {
@@ -1474,6 +1477,7 @@
                                      dump_stats_,
                                      dump_passes_,
                                      dump_cfg_file_name_,
+                                     dump_cfg_append_,
                                      compiler_phases_timings_.get(),
                                      swap_fd_,
                                      profile_file_));
@@ -1982,6 +1986,7 @@
   bool dump_timing_;
   bool dump_slow_timing_;
   std::string dump_cfg_file_name_;
+  bool dump_cfg_append_;
   std::string swap_file_name_;
   int swap_fd_;
   std::string profile_file_;  // Profile file to use