Index: llvm/lib/LTO/LTO.cpp =================================================================== --- llvm/lib/LTO/LTO.cpp +++ llvm/lib/LTO/LTO.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "llvm/LTO/LTO.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" @@ -1398,6 +1399,11 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, const DenseSet &GUIDPreservedSymbols) { + timeTraceProfilerBegin("ThinLink", StringRef("")); + auto TimeTraceScopeExit = llvm::make_scope_exit([]() { + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerEnd(); + }); if (ThinLTO.ModuleMap.empty()) return Error::success(); @@ -1512,6 +1518,11 @@ generateParamAccessSummary(ThinLTO.CombinedIndex); + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerEnd(); + + TimeTraceScopeExit.release(); + std::unique_ptr BackendProc = ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries, AddStream, Cache); Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -14,6 +14,7 @@ #include "llvm/LTO/legacy/ThinLTOCodeGenerator.h" #include "llvm/Support/CommandLine.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/AliasAnalysis.h" @@ -996,6 +997,11 @@ // Main entry point for the ThinLTO processing void ThinLTOCodeGenerator::run() { + timeTraceProfilerBegin("ThinLink", StringRef("")); + auto TimeTraceScopeExit = llvm::make_scope_exit([]() { + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerEnd(); + }); // Prepare the resulting object vector assert(ProducedBinaries.empty() && "The generator should not be reused"); if (SavedObjectsDirectoryPath.empty()) @@ -1141,6 +1147,11 @@ ModulesVec.push_back(&Mod->getSingleBitcodeModule()); std::vector ModulesOrdering = lto::generateModulesOrdering(ModulesVec); + if (llvm::timeTraceProfilerEnabled()) + llvm::timeTraceProfilerEnd(); + + TimeTraceScopeExit.release(); + // Parallel optimizer + codegen { ThreadPool Pool(heavyweight_hardware_concurrency(ThreadCount));