@@ -631,6 +631,7 @@ LTO::~LTO() = default;
631631void LTO::addModuleToGlobalRes (ArrayRef<InputFile::Symbol> Syms,
632632 ArrayRef<SymbolResolution> Res,
633633 unsigned Partition, bool InSummary) {
634+ llvm::TimeTraceScope timeScope (" LTO add module to global resolution" );
634635 auto *ResI = Res.begin ();
635636 auto *ResE = Res.end ();
636637 (void )ResE;
@@ -731,6 +732,7 @@ static void writeToResolutionFile(raw_ostream &OS, InputFile *Input,
731732
732733Error LTO::add (std::unique_ptr<InputFile> Input,
733734 ArrayRef<SymbolResolution> Res) {
735+ llvm::TimeTraceScope timeScope (" LTO add input" , Input->getName ());
734736 assert (!CalledGetMaxTasks);
735737
736738 if (Conf.ResolutionFile )
@@ -756,6 +758,7 @@ Error LTO::add(std::unique_ptr<InputFile> Input,
756758Expected<ArrayRef<SymbolResolution>>
757759LTO::addModule (InputFile &Input, ArrayRef<SymbolResolution> InputRes,
758760 unsigned ModI, ArrayRef<SymbolResolution> Res) {
761+ llvm::TimeTraceScope timeScope (" LTO add module" , Input.getName ());
759762 Expected<BitcodeLTOInfo> LTOInfo = Input.Mods [ModI].getLTOInfo ();
760763 if (!LTOInfo)
761764 return LTOInfo.takeError ();
@@ -850,6 +853,7 @@ Expected<
850853LTO::addRegularLTO (InputFile &Input, ArrayRef<SymbolResolution> InputRes,
851854 BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
852855 ArrayRef<SymbolResolution> Res) {
856+ llvm::TimeTraceScope timeScope (" LTO add regular LTO" );
853857 RegularLTOState::AddedModule Mod;
854858 Expected<std::unique_ptr<Module>> MOrErr =
855859 BM.getLazyModule (RegularLTO.Ctx , /* ShouldLazyLoadMetadata*/ true ,
@@ -1024,6 +1028,7 @@ LTO::addRegularLTO(InputFile &Input, ArrayRef<SymbolResolution> InputRes,
10241028
10251029Error LTO::linkRegularLTO (RegularLTOState::AddedModule Mod,
10261030 bool LivenessFromIndex) {
1031+ llvm::TimeTraceScope timeScope (" LTO link regular LTO" );
10271032 std::vector<GlobalValue *> Keep;
10281033 for (GlobalValue *GV : Mod.Keep ) {
10291034 if (LivenessFromIndex && !ThinLTO.CombinedIndex .isGUIDLive (GV->getGUID ())) {
@@ -1063,6 +1068,7 @@ Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
10631068Expected<ArrayRef<SymbolResolution>>
10641069LTO::addThinLTO (BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
10651070 ArrayRef<SymbolResolution> Res) {
1071+ llvm::TimeTraceScope timeScope (" LTO add thin LTO" );
10661072 ArrayRef<SymbolResolution> ResTmp = Res;
10671073 for (const InputFile::Symbol &Sym : Syms) {
10681074 assert (!ResTmp.empty ());
@@ -1252,6 +1258,7 @@ Error LTO::run(AddStreamFn AddStream, FileCache Cache) {
12521258
12531259void lto::updateMemProfAttributes (Module &Mod,
12541260 const ModuleSummaryIndex &Index) {
1261+ llvm::TimeTraceScope timeScope (" LTO update memprof attributes" );
12551262 if (Index.withSupportsHotColdNew ())
12561263 return ;
12571264
@@ -1282,6 +1289,7 @@ void lto::updateMemProfAttributes(Module &Mod,
12821289}
12831290
12841291Error LTO::runRegularLTO (AddStreamFn AddStream) {
1292+ llvm::TimeTraceScope timeScope (" Run regular LTO" );
12851293 // Setup optimization remarks.
12861294 auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks (
12871295 RegularLTO.CombinedModule ->getContext (), Conf.RemarksFilename ,
@@ -1294,10 +1302,12 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
12941302
12951303 // Finalize linking of regular LTO modules containing summaries now that
12961304 // we have computed liveness information.
1297- for (auto &M : RegularLTO.ModsWithSummaries )
1298- if (Error Err = linkRegularLTO (std::move (M),
1299- /* LivenessFromIndex=*/ true ))
1300- return Err;
1305+ {
1306+ llvm::TimeTraceScope timeScope (" Link regular LTO" );
1307+ for (auto &M : RegularLTO.ModsWithSummaries )
1308+ if (Error Err = linkRegularLTO (std::move (M), /* LivenessFromIndex=*/ true ))
1309+ return Err;
1310+ }
13011311
13021312 // Ensure we don't have inconsistently split LTO units with type tests.
13031313 // FIXME: this checks both LTO and ThinLTO. It happens to work as we take
@@ -1526,6 +1536,9 @@ class InProcessThinBackend : public CGThinBackend {
15261536 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
15271537 const GVSummaryMapTy &DefinedGlobals,
15281538 MapVector<StringRef, BitcodeModule> &ModuleMap) {
1539+ auto ModuleID = BM.getModuleIdentifier ();
1540+ llvm::TimeTraceScope timeScope (" Run ThinLTO backend thread (in-process)" ,
1541+ ModuleID);
15291542 auto RunThinBackend = [&](AddStreamFn AddStream) {
15301543 LTOLLVMContext BackendContext (Conf);
15311544 Expected<std::unique_ptr<Module>> MOrErr = BM.parseModule (BackendContext);
@@ -1536,9 +1549,6 @@ class InProcessThinBackend : public CGThinBackend {
15361549 ImportList, DefinedGlobals, &ModuleMap,
15371550 Conf.CodeGenOnly );
15381551 };
1539-
1540- auto ModuleID = BM.getModuleIdentifier ();
1541-
15421552 if (ShouldEmitIndexFiles) {
15431553 if (auto E = emitFiles (ImportList, ModuleID, ModuleID.str ()))
15441554 return E;
@@ -1639,6 +1649,9 @@ class FirstRoundThinBackend : public InProcessThinBackend {
16391649 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
16401650 const GVSummaryMapTy &DefinedGlobals,
16411651 MapVector<StringRef, BitcodeModule> &ModuleMap) override {
1652+ auto ModuleID = BM.getModuleIdentifier ();
1653+ llvm::TimeTraceScope timeScope (" Run ThinLTO backend thread (first round)" ,
1654+ ModuleID);
16421655 auto RunThinBackend = [&](AddStreamFn CGAddStream,
16431656 AddStreamFn IRAddStream) {
16441657 LTOLLVMContext BackendContext (Conf);
@@ -1650,8 +1663,6 @@ class FirstRoundThinBackend : public InProcessThinBackend {
16501663 ImportList, DefinedGlobals, &ModuleMap,
16511664 Conf.CodeGenOnly , IRAddStream);
16521665 };
1653-
1654- auto ModuleID = BM.getModuleIdentifier ();
16551666 // Like InProcessThinBackend, we produce index files as needed for
16561667 // FirstRoundThinBackend. However, these files are not generated for
16571668 // SecondRoundThinBackend.
@@ -1735,6 +1746,9 @@ class SecondRoundThinBackend : public InProcessThinBackend {
17351746 const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
17361747 const GVSummaryMapTy &DefinedGlobals,
17371748 MapVector<StringRef, BitcodeModule> &ModuleMap) override {
1749+ auto ModuleID = BM.getModuleIdentifier ();
1750+ llvm::TimeTraceScope timeScope (" Run ThinLTO backend thread (second round)" ,
1751+ ModuleID);
17381752 auto RunThinBackend = [&](AddStreamFn AddStream) {
17391753 LTOLLVMContext BackendContext (Conf);
17401754 std::unique_ptr<Module> LoadedModule =
@@ -1744,8 +1758,6 @@ class SecondRoundThinBackend : public InProcessThinBackend {
17441758 ImportList, DefinedGlobals, &ModuleMap,
17451759 /* CodeGenOnly=*/ true );
17461760 };
1747-
1748- auto ModuleID = BM.getModuleIdentifier ();
17491761 if (!Cache.isValid () || !CombinedIndex.modulePaths ().count (ModuleID) ||
17501762 all_of (CombinedIndex.getModuleHash (ModuleID),
17511763 [](uint32_t V) { return V == 0 ; }))
@@ -1915,6 +1927,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
19151927
19161928Error LTO::runThinLTO (AddStreamFn AddStream, FileCache Cache,
19171929 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
1930+ llvm::TimeTraceScope timeScope (" Run ThinLTO" );
19181931 LLVM_DEBUG (dbgs () << " Running ThinLTO\n " );
19191932 ThinLTO.CombinedIndex .releaseTemporaryMemory ();
19201933 timeTraceProfilerBegin (" ThinLink" , StringRef (" " ));
0 commit comments