https://github.com/orodley created https://github.com/llvm/llvm-project/pull/139497
None >From bfb6cb21243f043ea1edf6f00cf27d08549066dc Mon Sep 17 00:00:00 2001 From: Owen Rodley <orod...@google.com> 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 92b6e68d9d0a7..8acba6477c4a1 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 1d7aa189026a5..6d36b007956a0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -980,6 +980,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, @@ -7164,9 +7167,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); @@ -7389,6 +7390,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 73bed85c65b3d..3e19220d1bde7 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -227,6 +227,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase { protected: void writePerModuleGlobalValueSummary(); + void writeGUIDList(); private: void writePerModuleFunctionSummaryRecord( @@ -1560,6 +1561,8 @@ void ModuleBitcodeWriter::writeModuleInfo() { Vals.clear(); } + writeGUIDList(); + // Emit the global variable information. for (const GlobalVariable &GV : M.globals()) { unsigned AbbrevToUse = 0; @@ -4755,6 +4758,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); @@ -5538,6 +5561,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 llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits