summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Rodley <orodley@google.com>2025-05-12 15:50:22 +1000
committerOwen Rodley <orodley@google.com>2025-08-05 09:54:59 +1000
commit7f599c76af7fc371c6f8d54febc90e28a0b7a93c (patch)
treee342e2fc6030b725a5c4e96c392ced1aa5389167
parent3da1ceb81c1f17248babf0c0e2c07f23bd6b138b (diff)
-rw-r--r--llvm/include/llvm/Bitcode/LLVMBitCodes.h3
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp11
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp25
3 files changed, 36 insertions, 3 deletions
diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h
index dc78eb4164ac..9fffa9695d21 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 290d873c632c..b393fcb99b10 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 05680fa5c0f5..5234deba4ade 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -250,6 +250,7 @@ public:
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]