Index: tools/gold/gold-plugin.cpp =================================================================== --- tools/gold/gold-plugin.cpp +++ tools/gold/gold-plugin.cpp @@ -199,6 +199,7 @@ static bool new_pass_manager = false; // Debug new pass manager static bool debug_pass_manager = false; + static bool save_stats_obj = false; static void process_plugin_option(const char *opt_) { @@ -262,6 +263,8 @@ new_pass_manager = true; } else if (opt == "debug-pass-manager") { debug_pass_manager = true; + } else if (opt == "-save-stats=obj") { + save_stats_obj = true; } else { // Save this option to pass to the code generator. // ParseCommandLineOptions() expects argv[0] to be program name. Lazily @@ -1030,6 +1033,9 @@ if (unsigned NumOpts = options::extra.size()) cl::ParseCommandLineOptions(NumOpts, &options::extra[0]); + if (options::save_stats_obj) + llvm::EnableStatistics(false); + std::vector, bool>> Files = runLTO(); if (options::TheOutputType == options::OT_DISABLE || @@ -1051,6 +1057,14 @@ set_extra_library_path(options::extra_library_path.c_str()) != LDPS_OK) message(LDPL_FATAL, "Unable to set the extra library path."); + if (options::save_stats_obj) { + std::error_code EC; + raw_fd_ostream OS(output_name+".stats", EC, sys::fs::OpenFlags::F_None); + if (EC) + message(LDPL_FATAL, "Failed to write the stats file."); + else + llvm::PrintStatisticsJSON(OS); + } return LDPS_OK; }