llvm.org GIT mirror llvm / e74c64e
Write summaries for merged modules when splitting modules for ThinLTO. This is to prepare to allow for dead stripping of globals in the merged modules. Differential Revision: https://reviews.llvm.org/D33921 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305027 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 2 years ago
6 changed file(s) with 38 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
5454 METADATA_KIND_BLOCK_ID,
5555
5656 STRTAB_BLOCK_ID,
57
58 FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID,
5759 };
5860
5961 /// Identification block contains a string that describes the producer details,
446446 });
447447 }
448448
449 bool IsThinLTO = true;
450 if (auto *MD =
451 mdconst::extract_or_null(M.getModuleFlag("ThinLTO")))
452 IsThinLTO = MD->getZExtValue();
453
449454 for (auto &GlobalList : Index) {
450455 // Ignore entries for references that are undefined in the current module.
451456 if (GlobalList.second.SummaryList.empty())
454459 assert(GlobalList.second.SummaryList.size() == 1 &&
455460 "Expected module's index to have one summary per GUID");
456461 auto &Summary = GlobalList.second.SummaryList[0];
462 if (!IsThinLTO) {
463 Summary->setNotEligibleToImport();
464 continue;
465 }
466
457467 bool AllRefsCanBeExternallyReferenced =
458468 llvm::all_of(Summary->refs(), [&](const ValueInfo &VI) {
459469 return !CantBePromoted.count(VI.getGUID());
33043304 /// Emit the per-module summary section alongside the rest of
33053305 /// the module's bitcode.
33063306 void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() {
3307 Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4);
3307 // By default we compile with ThinLTO if the module has a summary, but the
3308 // client can request full LTO with a module flag.
3309 bool IsThinLTO = true;
3310 if (auto *MD =
3311 mdconst::extract_or_null(M.getModuleFlag("ThinLTO")))
3312 IsThinLTO = MD->getZExtValue();
3313 Stream.EnterSubblock(IsThinLTO ? bitc::GLOBALVAL_SUMMARY_BLOCK_ID
3314 : bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID,
3315 4);
33083316
33093317 Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION});
33103318
317317 ProfileSummaryInfo PSI(M);
318318 ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
319319
320 // Mark the merged module as requiring full LTO. We still want an index for
321 // it though, so that it can participate in summary-based dead stripping.
322 MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
323 ModuleSummaryIndex MergedMIndex =
324 buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
325
320326 SmallVector Buffer;
321327
322328 BitcodeWriter W(Buffer);
326332 ModuleHash ModHash = {{0}};
327333 W.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
328334 /*GenerateHash=*/true, &ModHash);
329 W.writeModule(MergedM.get());
335 W.writeModule(MergedM.get(), /*ShouldPreserveUseListOrder=*/false,
336 &MergedMIndex);
330337 W.writeStrtab();
331338 OS << Buffer;
332339
339346 StripDebugInfo(M);
340347 W2.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
341348 /*GenerateHash=*/false, &ModHash);
342 W2.writeModule(MergedM.get());
349 W2.writeModule(MergedM.get(), /*ShouldPreserveUseListOrder=*/false,
350 &MergedMIndex);
343351 W2.writeStrtab();
344352 *ThinLinkOS << Buffer;
345353 }
2424 ; ERROR: llvm-modextract: error: module index out of range; bitcode file contains 2 module(s)
2525
2626 ; BCA0:
27 ; BCA1:
28 ; 16 = not eligible to import
29 ; BCA1:
2730 ; BCA1-NOT:
2831
2932 $g = comdat any
4649 ; NODEBUG-NOT: !llvm.dbg.cu
4750 !llvm.dbg.cu = !{}
4851
52 ; M1: !{i32 1, !"ThinLTO", i32 0}
4953 !1 = !{i32 2, !"Debug Info Version", i32 3}
5054 !llvm.module.flags = !{!1}
120120 case bitc::USELIST_BLOCK_ID: return "USELIST_BLOCK_ID";
121121 case bitc::GLOBALVAL_SUMMARY_BLOCK_ID:
122122 return "GLOBALVAL_SUMMARY_BLOCK";
123 case bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID:
124 return "FULL_LTO_GLOBALVAL_SUMMARY_BLOCK";
123125 case bitc::MODULE_STRTAB_BLOCK_ID: return "MODULE_STRTAB_BLOCK";
124126 case bitc::STRTAB_BLOCK_ID: return "STRTAB_BLOCK";
125127 }
297299 STRINGIFY_CODE(MST_CODE, HASH)
298300 }
299301 case bitc::GLOBALVAL_SUMMARY_BLOCK_ID:
302 case bitc::FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID:
300303 switch (CodeID) {
301304 default:
302305 return nullptr;