diff options
author | Min-Yih Hsu <min.hsu@sifive.com> | 2024-06-04 14:01:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 14:01:15 -0700 |
commit | cd3255abede5e3687c1538f2d3857deb2c51af1b (patch) | |
tree | 858d648a5cd741d9baddf6ecb3a243ca65a88c68 /llvm/tools | |
parent | eca9caf419d420604ab372ddcab4781e999c1fe4 (diff) | |
download | llvm-cd3255abede5e3687c1538f2d3857deb2c51af1b.zip llvm-cd3255abede5e3687c1538f2d3857deb2c51af1b.tar.gz llvm-cd3255abede5e3687c1538f2d3857deb2c51af1b.tar.bz2 |
[gold] Enable time trace profiler in LLVMgold (#94293)
To get the time trace of LTO in the gold plugin, now we can pass the
`time-trace=<time trace file>` as well as
`time-trace-granularity=<granularity>` flags to LLVMgold.
Note that we still have to populate `LTOConfig::TimeTraceEnabled` and
`LTOConfig::TimeTraceGranularity` because ThinLTO backend needs them.
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/gold/gold-plugin.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp index 5503f73..265ebcb 100644 --- a/llvm/tools/gold/gold-plugin.cpp +++ b/llvm/tools/gold/gold-plugin.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/Statistic.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" @@ -31,6 +32,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/Threading.h" +#include "llvm/Support/TimeProfiler.h" #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" #include <list> @@ -220,6 +222,10 @@ namespace options { static std::string cs_profile_path; static bool cs_pgo_gen = false; + // Time trace options. + static std::string time_trace_file; + static unsigned time_trace_granularity = 500; + static void process_plugin_option(const char *opt_) { if (opt_ == nullptr) @@ -308,6 +314,14 @@ namespace options { RemarksFormat = std::string(opt); } else if (opt.consume_front("stats-file=")) { stats_file = std::string(opt); + } else if (opt.consume_front("time-trace=")) { + time_trace_file = std::string(opt); + } else if (opt.consume_front("time-trace-granularity=")) { + unsigned Granularity; + if (opt.getAsInteger(10, Granularity)) + message(LDPL_FATAL, "Invalid time trace granularity: %s", opt); + else + time_trace_granularity = Granularity; } else { // Save this option to pass to the code generator. // ParseCommandLineOptions() expects argv[0] to be program name. Lazily @@ -953,6 +967,10 @@ static std::unique_ptr<LTO> createLTO(IndexWriteCallback OnIndexWrite, Conf.HasWholeProgramVisibility = options::whole_program_visibility; Conf.StatsFile = options::stats_file; + + Conf.TimeTraceEnabled = !options::time_trace_file.empty(); + Conf.TimeTraceGranularity = options::time_trace_granularity; + return std::make_unique<LTO>(std::move(Conf), Backend, options::ParallelCodeGenParallelismLevel); } @@ -1113,6 +1131,19 @@ static ld_plugin_status allSymbolsReadHook() { if (unsigned NumOpts = options::extra.size()) cl::ParseCommandLineOptions(NumOpts, &options::extra[0]); + // Initialize time trace profiler + if (!options::time_trace_file.empty()) + llvm::timeTraceProfilerInitialize(options::time_trace_granularity, + options::extra.size() ? options::extra[0] + : "LLVMgold"); + auto FinalizeTimeTrace = llvm::make_scope_exit([&]() { + if (!llvm::timeTraceProfilerEnabled()) + return; + assert(!options::time_trace_file.empty()); + check(llvm::timeTraceProfilerWrite(options::time_trace_file, output_name)); + llvm::timeTraceProfilerCleanup(); + }); + std::vector<std::pair<SmallString<128>, bool>> Files = runLTO(); if (options::TheOutputType == options::OT_DISABLE || |