From bbe8cd13335300958b04db5318c31ff52714f96f Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 31 Jul 2023 11:32:11 -0700 Subject: [LTO] Remove module id from summary index The module paths string table mapped to both an id sequentially assigned during LTO linking, and the module hash. The former is leftover from before the module hash was added for caching and subsequently replaced use of the module id when renaming promoted symbols (to avoid affects due to link order changes). The sequentially assigned module id was not removed, however, as it was still a convenience when serializing to/from bitcode and assembly. This patch removes the module id from this table, since it isn't strictly needed and can lead to confusion on when it is appropriate to use (e.g. see fix in D156525). It also takes a (likely not significant) amount of overhead. Where an integer module id is needed (e.g. bitcode writing), one is assigned on the fly. There are a couple of test changes since the paths are now sorted alphanumerically when assigning ids on the fly during assembly writing, in order to ensure deterministic behavior. Differential Revision: https://reviews.llvm.org/D156730 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 02afc73..1d1ec98 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -904,10 +904,6 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// path to the bitcode file. StringRef ModulePath; - /// For per-module summary indexes, the unique numerical identifier given to - /// this module by the client. - unsigned ModuleId; - /// Callback to ask whether a symbol is the prevailing copy when invoked /// during combined index building. std::function IsPrevailing; @@ -919,7 +915,7 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, - StringRef ModulePath, unsigned ModuleId, + StringRef ModulePath, std::function IsPrevailing = nullptr); Error parseModule(); @@ -6699,13 +6695,12 @@ std::vector BitcodeReader::getIdentifiedStructTypes() const { ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader( BitstreamCursor Cursor, StringRef Strtab, ModuleSummaryIndex &TheIndex, - StringRef ModulePath, unsigned ModuleId, - std::function IsPrevailing) + StringRef ModulePath, std::function IsPrevailing) : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex), - ModulePath(ModulePath), ModuleId(ModuleId), IsPrevailing(IsPrevailing) {} + ModulePath(ModulePath), IsPrevailing(IsPrevailing) {} void ModuleSummaryIndexBitcodeReader::addThisModule() { - TheIndex.addModule(ModulePath, ModuleId); + TheIndex.addModule(ModulePath); } ModuleSummaryIndex::ModuleInfo * @@ -6936,7 +6931,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() { case bitc::MODULE_CODE_HASH: { if (Record.size() != 5) return error("Invalid hash length " + Twine(Record.size()).str()); - auto &Hash = getThisModule()->second.second; + auto &Hash = getThisModule()->second; int Pos = 0; for (auto &Val : Record) { assert(!(Val >> 32) && "Unexpected high bits set"); @@ -7697,7 +7692,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() { if (convertToString(Record, 1, ModulePath)) return error("Invalid record"); - LastSeenModule = TheIndex.addModule(ModulePath, ModuleId); + LastSeenModule = TheIndex.addModule(ModulePath); ModuleIdMap[ModuleId] = LastSeenModule->first(); ModulePath.clear(); @@ -7712,7 +7707,7 @@ Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() { int Pos = 0; for (auto &Val : Record) { assert(!(Val >> 32) && "Unexpected high bits set"); - LastSeenModule->second.second[Pos++] = Val; + LastSeenModule->second[Pos++] = Val; } // Reset LastSeenModule to avoid overriding the hash unexpectedly. LastSeenModule = nullptr; @@ -7970,14 +7965,14 @@ BitcodeModule::getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, // module path used in the combined summary (e.g. when reading summaries for // regular LTO modules). Error BitcodeModule::readSummary( - ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, uint64_t ModuleId, + ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, std::function IsPrevailing) { BitstreamCursor Stream(Buffer); if (Error JumpFailed = Stream.JumpToBit(ModuleBit)) return JumpFailed; ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex, - ModulePath, ModuleId, IsPrevailing); + ModulePath, IsPrevailing); return R.parseModule(); } @@ -8183,13 +8178,12 @@ Expected llvm::getBitcodeProducerString(MemoryBufferRef Buffer) { } Error llvm::readModuleSummaryIndex(MemoryBufferRef Buffer, - ModuleSummaryIndex &CombinedIndex, - uint64_t ModuleId) { + ModuleSummaryIndex &CombinedIndex) { Expected BM = getSingleModule(Buffer); if (!BM) return BM.takeError(); - return BM->readSummary(CombinedIndex, BM->getModuleIdentifier(), ModuleId); + return BM->readSummary(CombinedIndex, BM->getModuleIdentifier()); } Expected> -- cgit v1.1