https://github.com/orodley updated https://github.com/llvm/llvm-project/pull/139497
>From 7f599c76af7fc371c6f8d54febc90e28a0b7a93c Mon Sep 17 00:00:00 2001 From: Owen Rodley <[email protected]> Date: Mon, 12 May 2025 15:50:22 +1000 Subject: [PATCH] Add a GUIDLIST table to bitcode --- llvm/include/llvm/Bitcode/LLVMBitCodes.h | 3 +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 +++++++--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 25 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index dc78eb4164acf..9fffa9695d210 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -120,6 +120,9 @@ enum ModuleCodes { // IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility] MODULE_CODE_IFUNC = 18, + + // GUIDLIST: [n x i64] + MODULE_CODE_GUIDLIST = 19, }; /// PARAMATTR blocks have code for defining a parameter attribute set. diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 290d873c632c9..b393fcb99b109 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -984,6 +984,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase { /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. std::vector<uint64_t> RadixArray; + // A table which maps ValueID to the GUID for that value. + std::vector<uint64_t> DefinedGUIDs; + public: ModuleSummaryIndexBitcodeReader( BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex, @@ -7177,9 +7180,7 @@ ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) { void ModuleSummaryIndexBitcodeReader::setValueGUID( uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage, StringRef SourceFileName) { - std::string GlobalId = - GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName); - auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId); + auto ValueGUID = DefinedGUIDs[ValueID]; auto OriginalNameID = ValueGUID; if (GlobalValue::isLocalLinkage(Linkage)) OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName); @@ -7402,6 +7403,10 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() { // was historically always the start of the regular bitcode header. VSTOffset = Record[0] - 1; break; + // MODULE_CODE_GUIDLIST: [i64 x N] + case bitc::MODULE_CODE_GUIDLIST: + llvm::append_range(DefinedGUIDs, Record); + break; // v1 GLOBALVAR: [pointer type, isconst, initid, linkage, ...] // v1 FUNCTION: [type, callingconv, isproto, linkage, ...] // v1 ALIAS: [alias type, addrspace, aliasee val#, linkage, ...] diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 05680fa5c0f5f..5234deba4ade3 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -250,6 +250,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1591,6 +1592,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4896,6 +4899,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.ExitBlock(); } +void ModuleBitcodeWriterBase::writeGUIDList() { + std::vector<uint64_t> GUIDs; + GUIDs.reserve(M.global_size() + M.size() + M.alias_size()); + + for (const GlobalValue &GV : M.global_objects()) { + if (GV.isDeclaration()) { + GUIDs.push_back( + GlobalValue::getGUIDAssumingExternalLinkage(GV.getName())); + } else { + GUIDs.push_back(GV.getGUID()); + } + } + for (const GlobalAlias &GA : M.aliases()) { + // Equivalent to the above loop, as GlobalAliases are always definitions. + GUIDs.push_back(GA.getGUID()); + } + + Stream.EmitRecord(bitc::MODULE_CODE_GUIDLIST, GUIDs); +} + /// Emit the combined summary section into the combined index file. void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4); @@ -5684,6 +5707,8 @@ void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { // GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage] _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
