@@ -631,6 +631,7 @@ LTO::~LTO() = default;
631
631
void LTO::addModuleToGlobalRes (ArrayRef<InputFile::Symbol> Syms,
632
632
ArrayRef<SymbolResolution> Res,
633
633
unsigned Partition, bool InSummary) {
634
+ llvm::TimeTraceScope timeScope (" LTO add module to global resolution" );
634
635
auto *ResI = Res.begin ();
635
636
auto *ResE = Res.end ();
636
637
(void )ResE;
@@ -731,6 +732,7 @@ static void writeToResolutionFile(raw_ostream &OS, InputFile *Input,
731
732
732
733
Error LTO::add (std::unique_ptr<InputFile> Input,
733
734
ArrayRef<SymbolResolution> Res) {
735
+ llvm::TimeTraceScope timeScope (" LTO add input" , Input->getName ());
734
736
assert (!CalledGetMaxTasks);
735
737
736
738
if (Conf.ResolutionFile )
@@ -756,6 +758,7 @@ Error LTO::add(std::unique_ptr<InputFile> Input,
756
758
Expected<ArrayRef<SymbolResolution>>
757
759
LTO::addModule (InputFile &Input, ArrayRef<SymbolResolution> InputRes,
758
760
unsigned ModI, ArrayRef<SymbolResolution> Res) {
761
+ llvm::TimeTraceScope timeScope (" LTO add module" , Input.getName ());
759
762
Expected<BitcodeLTOInfo> LTOInfo = Input.Mods [ModI].getLTOInfo ();
760
763
if (!LTOInfo)
761
764
return LTOInfo.takeError ();
@@ -850,6 +853,7 @@ Expected<
850
853
LTO::addRegularLTO (InputFile &Input, ArrayRef<SymbolResolution> InputRes,
851
854
BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
852
855
ArrayRef<SymbolResolution> Res) {
856
+ llvm::TimeTraceScope timeScope (" LTO add regular LTO" );
853
857
RegularLTOState::AddedModule Mod;
854
858
Expected<std::unique_ptr<Module>> MOrErr =
855
859
BM.getLazyModule (RegularLTO.Ctx , /* ShouldLazyLoadMetadata*/ true ,
@@ -1024,6 +1028,7 @@ LTO::addRegularLTO(InputFile &Input, ArrayRef<SymbolResolution> InputRes,
1024
1028
1025
1029
Error LTO::linkRegularLTO (RegularLTOState::AddedModule Mod,
1026
1030
bool LivenessFromIndex) {
1031
+ llvm::TimeTraceScope timeScope (" LTO link regular LTO" );
1027
1032
std::vector<GlobalValue *> Keep;
1028
1033
for (GlobalValue *GV : Mod.Keep ) {
1029
1034
if (LivenessFromIndex && !ThinLTO.CombinedIndex .isGUIDLive (GV->getGUID ())) {
@@ -1063,6 +1068,7 @@ Error LTO::linkRegularLTO(RegularLTOState::AddedModule Mod,
1063
1068
Expected<ArrayRef<SymbolResolution>>
1064
1069
LTO::addThinLTO (BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
1065
1070
ArrayRef<SymbolResolution> Res) {
1071
+ llvm::TimeTraceScope timeScope (" LTO add thin LTO" );
1066
1072
ArrayRef<SymbolResolution> ResTmp = Res;
1067
1073
for (const InputFile::Symbol &Sym : Syms) {
1068
1074
assert (!ResTmp.empty ());
@@ -1252,6 +1258,7 @@ Error LTO::run(AddStreamFn AddStream, FileCache Cache) {
1252
1258
1253
1259
void lto::updateMemProfAttributes (Module &Mod,
1254
1260
const ModuleSummaryIndex &Index) {
1261
+ llvm::TimeTraceScope timeScope (" LTO update memprof attributes" );
1255
1262
if (Index.withSupportsHotColdNew ())
1256
1263
return ;
1257
1264
@@ -1282,6 +1289,7 @@ void lto::updateMemProfAttributes(Module &Mod,
1282
1289
}
1283
1290
1284
1291
Error LTO::runRegularLTO (AddStreamFn AddStream) {
1292
+ llvm::TimeTraceScope timeScope (" Run regular LTO" );
1285
1293
// Setup optimization remarks.
1286
1294
auto DiagFileOrErr = lto::setupLLVMOptimizationRemarks (
1287
1295
RegularLTO.CombinedModule ->getContext (), Conf.RemarksFilename ,
@@ -1294,10 +1302,12 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
1294
1302
1295
1303
// Finalize linking of regular LTO modules containing summaries now that
1296
1304
// 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
+ }
1301
1311
1302
1312
// Ensure we don't have inconsistently split LTO units with type tests.
1303
1313
// FIXME: this checks both LTO and ThinLTO. It happens to work as we take
@@ -1526,6 +1536,9 @@ class InProcessThinBackend : public CGThinBackend {
1526
1536
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1527
1537
const GVSummaryMapTy &DefinedGlobals,
1528
1538
MapVector<StringRef, BitcodeModule> &ModuleMap) {
1539
+ auto ModuleID = BM.getModuleIdentifier ();
1540
+ llvm::TimeTraceScope timeScope (" Run ThinLTO backend thread (in-process)" ,
1541
+ ModuleID);
1529
1542
auto RunThinBackend = [&](AddStreamFn AddStream) {
1530
1543
LTOLLVMContext BackendContext (Conf);
1531
1544
Expected<std::unique_ptr<Module>> MOrErr = BM.parseModule (BackendContext);
@@ -1536,9 +1549,6 @@ class InProcessThinBackend : public CGThinBackend {
1536
1549
ImportList, DefinedGlobals, &ModuleMap,
1537
1550
Conf.CodeGenOnly );
1538
1551
};
1539
-
1540
- auto ModuleID = BM.getModuleIdentifier ();
1541
-
1542
1552
if (ShouldEmitIndexFiles) {
1543
1553
if (auto E = emitFiles (ImportList, ModuleID, ModuleID.str ()))
1544
1554
return E;
@@ -1639,6 +1649,9 @@ class FirstRoundThinBackend : public InProcessThinBackend {
1639
1649
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1640
1650
const GVSummaryMapTy &DefinedGlobals,
1641
1651
MapVector<StringRef, BitcodeModule> &ModuleMap) override {
1652
+ auto ModuleID = BM.getModuleIdentifier ();
1653
+ llvm::TimeTraceScope timeScope (" Run ThinLTO backend thread (first round)" ,
1654
+ ModuleID);
1642
1655
auto RunThinBackend = [&](AddStreamFn CGAddStream,
1643
1656
AddStreamFn IRAddStream) {
1644
1657
LTOLLVMContext BackendContext (Conf);
@@ -1650,8 +1663,6 @@ class FirstRoundThinBackend : public InProcessThinBackend {
1650
1663
ImportList, DefinedGlobals, &ModuleMap,
1651
1664
Conf.CodeGenOnly , IRAddStream);
1652
1665
};
1653
-
1654
- auto ModuleID = BM.getModuleIdentifier ();
1655
1666
// Like InProcessThinBackend, we produce index files as needed for
1656
1667
// FirstRoundThinBackend. However, these files are not generated for
1657
1668
// SecondRoundThinBackend.
@@ -1735,6 +1746,9 @@ class SecondRoundThinBackend : public InProcessThinBackend {
1735
1746
const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
1736
1747
const GVSummaryMapTy &DefinedGlobals,
1737
1748
MapVector<StringRef, BitcodeModule> &ModuleMap) override {
1749
+ auto ModuleID = BM.getModuleIdentifier ();
1750
+ llvm::TimeTraceScope timeScope (" Run ThinLTO backend thread (second round)" ,
1751
+ ModuleID);
1738
1752
auto RunThinBackend = [&](AddStreamFn AddStream) {
1739
1753
LTOLLVMContext BackendContext (Conf);
1740
1754
std::unique_ptr<Module> LoadedModule =
@@ -1744,8 +1758,6 @@ class SecondRoundThinBackend : public InProcessThinBackend {
1744
1758
ImportList, DefinedGlobals, &ModuleMap,
1745
1759
/* CodeGenOnly=*/ true );
1746
1760
};
1747
-
1748
- auto ModuleID = BM.getModuleIdentifier ();
1749
1761
if (!Cache.isValid () || !CombinedIndex.modulePaths ().count (ModuleID) ||
1750
1762
all_of (CombinedIndex.getModuleHash (ModuleID),
1751
1763
[](uint32_t V) { return V == 0 ; }))
@@ -1915,6 +1927,7 @@ ThinBackend lto::createWriteIndexesThinBackend(
1915
1927
1916
1928
Error LTO::runThinLTO (AddStreamFn AddStream, FileCache Cache,
1917
1929
const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
1930
+ llvm::TimeTraceScope timeScope (" Run ThinLTO" );
1918
1931
LLVM_DEBUG (dbgs () << " Running ThinLTO\n " );
1919
1932
ThinLTO.CombinedIndex .releaseTemporaryMemory ();
1920
1933
timeTraceProfilerBegin (" ThinLink" , StringRef (" " ));
0 commit comments