Skip to content

Commit 53061ee

Browse files
Revert "[ThinLTO][Bitcode] Generate import type in bitcode (#87600)" (#94502)
This reverts commit 6262763, to prepare for the revert of #92718. #92718 causes LTO indexing OOM in some applications.
1 parent 61589b8 commit 53061ee

File tree

9 files changed

+41
-119
lines changed

9 files changed

+41
-119
lines changed

llvm/include/llvm/Bitcode/BitcodeWriter.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ class BitcodeWriter {
102102

103103
void writeIndex(
104104
const ModuleSummaryIndex *Index,
105-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
106-
const GVSummaryPtrSet *DecSummaries);
105+
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex);
107106
};
108107

109108
/// Write the specified module to the specified raw output stream.
@@ -148,12 +147,10 @@ void writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
148147
/// where it will be written in a new bitcode block. This is used when
149148
/// writing the combined index file for ThinLTO. When writing a subset of the
150149
/// index for a distributed backend, provide the \p ModuleToSummariesForIndex
151-
/// map. \p DecSummaries specifies the set of summaries for which the
152-
/// corresponding value should be imported as a declaration (prototype).
150+
/// map.
153151
void writeIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
154152
const std::map<std::string, GVSummaryMapTy>
155-
*ModuleToSummariesForIndex = nullptr,
156-
const GVSummaryPtrSet *DecSummaries = nullptr);
153+
*ModuleToSummariesForIndex = nullptr);
157154

158155
/// If EmbedBitcode is set, save a copy of the llvm IR as data in the
159156
/// __LLVM,__bitcode section (.llvmbc on non-MacOS).

llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,12 @@ class ThinLTOCodeGenerator {
271271
const lto::InputFile &File);
272272

273273
/**
274-
* Compute the list of summaries and the subset of declaration summaries
275-
* needed for importing into module.
274+
* Compute the list of summaries needed for importing into module.
276275
*/
277276
void gatherImportedSummariesForModule(
278277
Module &Module, ModuleSummaryIndex &Index,
279278
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
280-
GVSummaryPtrSet &DecSummaries, const lto::InputFile &File);
279+
const lto::InputFile &File);
281280

282281
/**
283282
* Perform internalization. Index is updated to reflect linkage changes.

llvm/include/llvm/Transforms/IPO/FunctionImport.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,11 @@ bool convertToDeclaration(GlobalValue &GV);
212212
/// \p ModuleToSummariesForIndex will be populated with the needed summaries
213213
/// from each required module path. Use a std::map instead of StringMap to get
214214
/// stable order for bitcode emission.
215-
///
216-
/// \p DecSummaries will be popluated with the subset of of summary pointers
217-
/// that have 'declaration' import type among all summaries the module need.
218215
void gatherImportedSummariesForModule(
219216
StringRef ModulePath,
220217
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
221218
const FunctionImporter::ImportMapTy &ImportList,
222-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
223-
GVSummaryPtrSet &DecSummaries);
219+
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
224220

225221
/// Emit into \p OutputFilename the files module \p ModulePath will import from.
226222
std::error_code EmitImportsFiles(

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,6 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
424424
/// The combined index to write to bitcode.
425425
const ModuleSummaryIndex &Index;
426426

427-
/// When writing combined summaries, provides the set of global value
428-
/// summaries for which the value (function, function alias, etc) should be
429-
/// imported as a declaration.
430-
const GVSummaryPtrSet *DecSummaries = nullptr;
431-
432427
/// When writing a subset of the index for distributed backends, client
433428
/// provides a map of modules to the corresponding GUIDs/summaries to write.
434429
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex;
@@ -457,16 +452,11 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
457452
/// Constructs a IndexBitcodeWriter object for the given combined index,
458453
/// writing to the provided \p Buffer. When writing a subset of the index
459454
/// for a distributed backend, provide a \p ModuleToSummariesForIndex map.
460-
/// If provided, \p ModuleToDecSummaries specifies the set of summaries for
461-
/// which the corresponding functions or aliased functions should be imported
462-
/// as a declaration (but not definition) for each module.
463455
IndexBitcodeWriter(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder,
464456
const ModuleSummaryIndex &Index,
465-
const GVSummaryPtrSet *DecSummaries = nullptr,
466457
const std::map<std::string, GVSummaryMapTy>
467458
*ModuleToSummariesForIndex = nullptr)
468459
: BitcodeWriterBase(Stream, StrtabBuilder), Index(Index),
469-
DecSummaries(DecSummaries),
470460
ModuleToSummariesForIndex(ModuleToSummariesForIndex) {
471461

472462
// See if the StackIdIndex was already added to the StackId map and
@@ -1221,8 +1211,7 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) {
12211211

12221212
// Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags
12231213
// in BitcodeReader.cpp.
1224-
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
1225-
bool ImportAsDecl = false) {
1214+
static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) {
12261215
uint64_t RawFlags = 0;
12271216

12281217
RawFlags |= Flags.NotEligibleToImport; // bool
@@ -1237,8 +1226,7 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags,
12371226

12381227
RawFlags |= (Flags.Visibility << 8); // 2 bits
12391228

1240-
unsigned ImportType = Flags.ImportType | ImportAsDecl;
1241-
RawFlags |= (ImportType << 10); // 1 bit
1229+
RawFlags |= (Flags.ImportType << 10); // 1 bit
12421230

12431231
return RawFlags;
12441232
}
@@ -4565,12 +4553,6 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
45654553
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
45664554
unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv));
45674555

4568-
auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool {
4569-
if (DecSummaries == nullptr)
4570-
return false;
4571-
return DecSummaries->contains(GVS);
4572-
};
4573-
45744556
// The aliases are emitted as a post-pass, and will point to the value
45754557
// id of the aliasee. Save them in a vector for post-processing.
45764558
SmallVector<AliasSummary *, 64> Aliases;
@@ -4681,8 +4663,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
46814663
NameVals.push_back(*ValueId);
46824664
assert(ModuleIdMap.count(FS->modulePath()));
46834665
NameVals.push_back(ModuleIdMap[FS->modulePath()]);
4684-
NameVals.push_back(
4685-
getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS)));
4666+
NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
46864667
NameVals.push_back(FS->instCount());
46874668
NameVals.push_back(getEncodedFFlags(FS->fflags()));
46884669
NameVals.push_back(FS->entryCount());
@@ -4731,8 +4712,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
47314712
NameVals.push_back(AliasValueId);
47324713
assert(ModuleIdMap.count(AS->modulePath()));
47334714
NameVals.push_back(ModuleIdMap[AS->modulePath()]);
4734-
NameVals.push_back(
4735-
getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDecl(AS)));
4715+
NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
47364716
auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
47374717
assert(AliaseeValueId);
47384718
NameVals.push_back(AliaseeValueId);
@@ -5073,9 +5053,8 @@ void BitcodeWriter::writeModule(const Module &M,
50735053

50745054
void BitcodeWriter::writeIndex(
50755055
const ModuleSummaryIndex *Index,
5076-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5077-
const GVSummaryPtrSet *DecSummaries) {
5078-
IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries,
5056+
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
5057+
IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index,
50795058
ModuleToSummariesForIndex);
50805059
IndexWriter.write();
50815060
}
@@ -5130,13 +5109,12 @@ void IndexBitcodeWriter::write() {
51305109
// index for a distributed backend, provide a \p ModuleToSummariesForIndex map.
51315110
void llvm::writeIndexToFile(
51325111
const ModuleSummaryIndex &Index, raw_ostream &Out,
5133-
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex,
5134-
const GVSummaryPtrSet *DecSummaries) {
5112+
const std::map<std::string, GVSummaryMapTy> *ModuleToSummariesForIndex) {
51355113
SmallVector<char, 0> Buffer;
51365114
Buffer.reserve(256 * 1024);
51375115

51385116
BitcodeWriter Writer(Buffer);
5139-
Writer.writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries);
5117+
Writer.writeIndex(&Index, ModuleToSummariesForIndex);
51405118
Writer.writeStrtab();
51415119

51425120
Out.write((char *)&Buffer.front(), Buffer.size());

llvm/lib/LTO/LTO.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,20 +1400,18 @@ class lto::ThinBackendProc {
14001400
llvm::StringRef ModulePath,
14011401
const std::string &NewModulePath) {
14021402
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
1403-
GVSummaryPtrSet DeclarationSummaries;
14041403

14051404
std::error_code EC;
14061405
gatherImportedSummariesForModule(ModulePath, ModuleToDefinedGVSummaries,
1407-
ImportList, ModuleToSummariesForIndex,
1408-
DeclarationSummaries);
1406+
ImportList, ModuleToSummariesForIndex);
14091407

14101408
raw_fd_ostream OS(NewModulePath + ".thinlto.bc", EC,
14111409
sys::fs::OpenFlags::OF_None);
14121410
if (EC)
14131411
return errorCodeToError(EC);
14141412

1415-
writeIndexToFile(CombinedIndex, OS, &ModuleToSummariesForIndex,
1416-
&DeclarationSummaries);
1413+
// TODO: Serialize declaration bits to bitcode.
1414+
writeIndexToFile(CombinedIndex, OS, &ModuleToSummariesForIndex);
14171415

14181416
if (ShouldEmitImportsFiles) {
14191417
EC = EmitImportsFiles(ModulePath, NewModulePath + ".imports",

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void ThinLTOCodeGenerator::crossModuleImport(Module &TheModule,
766766
void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
767767
Module &TheModule, ModuleSummaryIndex &Index,
768768
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
769-
GVSummaryPtrSet &DecSummaries, const lto::InputFile &File) {
769+
const lto::InputFile &File) {
770770
auto ModuleCount = Index.modulePaths().size();
771771
auto ModuleIdentifier = TheModule.getModuleIdentifier();
772772

@@ -796,7 +796,7 @@ void ThinLTOCodeGenerator::gatherImportedSummariesForModule(
796796

797797
llvm::gatherImportedSummariesForModule(
798798
ModuleIdentifier, ModuleToDefinedGVSummaries,
799-
ImportLists[ModuleIdentifier], ModuleToSummariesForIndex, DecSummaries);
799+
ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
800800
}
801801

802802
/**
@@ -832,14 +832,10 @@ void ThinLTOCodeGenerator::emitImports(Module &TheModule, StringRef OutputName,
832832
IsPrevailing(PrevailingCopy), ImportLists,
833833
ExportLists);
834834

835-
// 'EmitImportsFiles' emits the list of modules from which to import from, and
836-
// the set of keys in `ModuleToSummariesForIndex` should be a superset of keys
837-
// in `DecSummaries`, so no need to use `DecSummaries` in `EmitImportFiles`.
838-
GVSummaryPtrSet DecSummaries;
839835
std::map<std::string, GVSummaryMapTy> ModuleToSummariesForIndex;
840836
llvm::gatherImportedSummariesForModule(
841837
ModuleIdentifier, ModuleToDefinedGVSummaries,
842-
ImportLists[ModuleIdentifier], ModuleToSummariesForIndex, DecSummaries);
838+
ImportLists[ModuleIdentifier], ModuleToSummariesForIndex);
843839

844840
std::error_code EC;
845841
if ((EC = EmitImportsFiles(ModuleIdentifier, OutputName,

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,7 @@ void llvm::gatherImportedSummariesForModule(
14351435
StringRef ModulePath,
14361436
const DenseMap<StringRef, GVSummaryMapTy> &ModuleToDefinedGVSummaries,
14371437
const FunctionImporter::ImportMapTy &ImportList,
1438-
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex,
1439-
GVSummaryPtrSet &DecSummaries) {
1438+
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex) {
14401439
// Include all summaries from the importing module.
14411440
ModuleToSummariesForIndex[std::string(ModulePath)] =
14421441
ModuleToDefinedGVSummaries.lookup(ModulePath);
@@ -1451,7 +1450,7 @@ void llvm::gatherImportedSummariesForModule(
14511450
assert(DS != DefinedGVSummaries.end() &&
14521451
"Expected a defined summary for imported global value");
14531452
if (Type == GlobalValueSummary::Declaration)
1454-
DecSummaries.insert(DS->second);
1453+
continue;
14551454

14561455
SummariesForIndex[GUID] = DS->second;
14571456
}

0 commit comments

Comments
 (0)