From 53061eecdbd9ffc77a43f85b6c4e145a242a27a4 Mon Sep 17 00:00:00 2001 From: Mingming Liu Date: Wed, 5 Jun 2024 09:59:46 -0700 Subject: Revert "[ThinLTO][Bitcode] Generate import type in bitcode (#87600)" (#94502) This reverts commit 6262763341fcd71a2b0708cf7485f9abd1d26ba8, to prepare for the revert of https://github.com/llvm/llvm-project/pull/92718. https://github.com/llvm/llvm-project/pull/92718 causes LTO indexing OOM in some applications. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 38 +++++++------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 3c99bde..35ea3c1 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -424,11 +424,6 @@ class IndexBitcodeWriter : public BitcodeWriterBase { /// The combined index to write to bitcode. const ModuleSummaryIndex &Index; - /// When writing combined summaries, provides the set of global value - /// summaries for which the value (function, function alias, etc) should be - /// imported as a declaration. - const GVSummaryPtrSet *DecSummaries = nullptr; - /// When writing a subset of the index for distributed backends, client /// provides a map of modules to the corresponding GUIDs/summaries to write. const std::map *ModuleToSummariesForIndex; @@ -457,16 +452,11 @@ public: /// Constructs a IndexBitcodeWriter object for the given combined index, /// writing to the provided \p Buffer. When writing a subset of the index /// for a distributed backend, provide a \p ModuleToSummariesForIndex map. - /// If provided, \p ModuleToDecSummaries specifies the set of summaries for - /// which the corresponding functions or aliased functions should be imported - /// as a declaration (but not definition) for each module. IndexBitcodeWriter(BitstreamWriter &Stream, StringTableBuilder &StrtabBuilder, const ModuleSummaryIndex &Index, - const GVSummaryPtrSet *DecSummaries = nullptr, const std::map *ModuleToSummariesForIndex = nullptr) : BitcodeWriterBase(Stream, StrtabBuilder), Index(Index), - DecSummaries(DecSummaries), ModuleToSummariesForIndex(ModuleToSummariesForIndex) { // See if the StackIdIndex was already added to the StackId map and @@ -1221,8 +1211,7 @@ static uint64_t getEncodedFFlags(FunctionSummary::FFlags Flags) { // Decode the flags for GlobalValue in the summary. See getDecodedGVSummaryFlags // in BitcodeReader.cpp. -static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, - bool ImportAsDecl = false) { +static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) { uint64_t RawFlags = 0; RawFlags |= Flags.NotEligibleToImport; // bool @@ -1237,8 +1226,7 @@ static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags, RawFlags |= (Flags.Visibility << 8); // 2 bits - unsigned ImportType = Flags.ImportType | ImportAsDecl; - RawFlags |= (ImportType << 10); // 1 bit + RawFlags |= (Flags.ImportType << 10); // 1 bit return RawFlags; } @@ -4565,12 +4553,6 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); unsigned AllocAbbrev = Stream.EmitAbbrev(std::move(Abbv)); - auto shouldImportValueAsDecl = [&](GlobalValueSummary *GVS) -> bool { - if (DecSummaries == nullptr) - return false; - return DecSummaries->contains(GVS); - }; - // The aliases are emitted as a post-pass, and will point to the value // id of the aliasee. Save them in a vector for post-processing. SmallVector Aliases; @@ -4681,8 +4663,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { NameVals.push_back(*ValueId); assert(ModuleIdMap.count(FS->modulePath())); NameVals.push_back(ModuleIdMap[FS->modulePath()]); - NameVals.push_back( - getEncodedGVSummaryFlags(FS->flags(), shouldImportValueAsDecl(FS))); + NameVals.push_back(getEncodedGVSummaryFlags(FS->flags())); NameVals.push_back(FS->instCount()); NameVals.push_back(getEncodedFFlags(FS->fflags())); NameVals.push_back(FS->entryCount()); @@ -4731,8 +4712,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { NameVals.push_back(AliasValueId); assert(ModuleIdMap.count(AS->modulePath())); NameVals.push_back(ModuleIdMap[AS->modulePath()]); - NameVals.push_back( - getEncodedGVSummaryFlags(AS->flags(), shouldImportValueAsDecl(AS))); + NameVals.push_back(getEncodedGVSummaryFlags(AS->flags())); auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()]; assert(AliaseeValueId); NameVals.push_back(AliaseeValueId); @@ -5073,9 +5053,8 @@ void BitcodeWriter::writeModule(const Module &M, void BitcodeWriter::writeIndex( const ModuleSummaryIndex *Index, - const std::map *ModuleToSummariesForIndex, - const GVSummaryPtrSet *DecSummaries) { - IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, DecSummaries, + const std::map *ModuleToSummariesForIndex) { + IndexBitcodeWriter IndexWriter(*Stream, StrtabBuilder, *Index, ModuleToSummariesForIndex); IndexWriter.write(); } @@ -5130,13 +5109,12 @@ void IndexBitcodeWriter::write() { // index for a distributed backend, provide a \p ModuleToSummariesForIndex map. void llvm::writeIndexToFile( const ModuleSummaryIndex &Index, raw_ostream &Out, - const std::map *ModuleToSummariesForIndex, - const GVSummaryPtrSet *DecSummaries) { + const std::map *ModuleToSummariesForIndex) { SmallVector Buffer; Buffer.reserve(256 * 1024); BitcodeWriter Writer(Buffer); - Writer.writeIndex(&Index, ModuleToSummariesForIndex, DecSummaries); + Writer.writeIndex(&Index, ModuleToSummariesForIndex); Writer.writeStrtab(); Out.write((char *)&Buffer.front(), Buffer.size()); -- cgit v1.1