Skip to content

Commit 553845e

Browse files
committed
Add a GUIDLIST table to bitcode
1 parent 61108c7 commit 553845e

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ enum ModuleCodes {
120120

121121
// IFUNC: [ifunc value type, addrspace, resolver val#, linkage, visibility]
122122
MODULE_CODE_IFUNC = 18,
123+
124+
// GUIDLIST: [n x i64]
125+
MODULE_CODE_GUIDLIST = 19,
123126
};
124127

125128
/// PARAMATTR blocks have code for defining a parameter attribute set.

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
980980
/// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format.
981981
std::vector<uint64_t> RadixArray;
982982

983+
// A table which maps ValueID to the GUID for that value.
984+
std::vector<uint64_t> DefinedGUIDs;
985+
983986
public:
984987
ModuleSummaryIndexBitcodeReader(
985988
BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex,
@@ -7164,9 +7167,7 @@ ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) {
71647167
void ModuleSummaryIndexBitcodeReader::setValueGUID(
71657168
uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage,
71667169
StringRef SourceFileName) {
7167-
std::string GlobalId =
7168-
GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName);
7169-
auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId);
7170+
auto ValueGUID = DefinedGUIDs[ValueID];
71707171
auto OriginalNameID = ValueGUID;
71717172
if (GlobalValue::isLocalLinkage(Linkage))
71727173
OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName);
@@ -7389,6 +7390,10 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() {
73897390
// was historically always the start of the regular bitcode header.
73907391
VSTOffset = Record[0] - 1;
73917392
break;
7393+
// MODULE_CODE_GUIDLIST: [i64 x N]
7394+
case bitc::MODULE_CODE_GUIDLIST:
7395+
llvm::append_range(DefinedGUIDs, Record);
7396+
break;
73927397
// v1 GLOBALVAR: [pointer type, isconst, initid, linkage, ...]
73937398
// v1 FUNCTION: [type, callingconv, isproto, linkage, ...]
73947399
// v1 ALIAS: [alias type, addrspace, aliasee val#, linkage, ...]

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase {
227227

228228
protected:
229229
void writePerModuleGlobalValueSummary();
230+
void writeGUIDList();
230231

231232
private:
232233
void writePerModuleFunctionSummaryRecord(
@@ -1560,6 +1561,8 @@ void ModuleBitcodeWriter::writeModuleInfo() {
15601561
Vals.clear();
15611562
}
15621563

1564+
writeGUIDList();
1565+
15631566
// Emit the global variable information.
15641567
for (const GlobalVariable &GV : M.globals()) {
15651568
unsigned AbbrevToUse = 0;
@@ -4755,6 +4758,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
47554758
Stream.ExitBlock();
47564759
}
47574760

4761+
void ModuleBitcodeWriterBase::writeGUIDList() {
4762+
std::vector<uint64_t> GUIDs;
4763+
GUIDs.reserve(M.global_size() + M.size() + M.alias_size());
4764+
4765+
for (const GlobalValue &GV : M.global_objects()) {
4766+
if (GV.isDeclaration()) {
4767+
GUIDs.push_back(
4768+
GlobalValue::getGUIDAssumingExternalLinkage(GV.getName()));
4769+
} else {
4770+
GUIDs.push_back(GV.getGUID());
4771+
}
4772+
}
4773+
for (const GlobalAlias &GA : M.aliases()) {
4774+
// Equivalent to the above loop, as GlobalAliases are always definitions.
4775+
GUIDs.push_back(GA.getGUID());
4776+
}
4777+
4778+
Stream.EmitRecord(bitc::MODULE_CODE_GUIDLIST, GUIDs);
4779+
}
4780+
47584781
/// Emit the combined summary section into the combined index file.
47594782
void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
47604783
Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4);
@@ -5538,6 +5561,8 @@ void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
55385561
Vals.clear();
55395562
}
55405563

5564+
writeGUIDList();
5565+
55415566
// Emit the global variable information.
55425567
for (const GlobalVariable &GV : M.globals()) {
55435568
// GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage]

0 commit comments

Comments
 (0)