Skip to content

Commit bf53f87

Browse files
committed
Add a GUIDLIST table to bitcode
1 parent e40c56f commit bf53f87

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
@@ -976,6 +976,9 @@ class ModuleSummaryIndexBitcodeReader : public BitcodeReaderBase {
976976
/// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format.
977977
std::vector<uint64_t> RadixArray;
978978

979+
// A table which maps ValueID to the GUID for that value.
980+
std::vector<uint64_t> DefinedGUIDs;
981+
979982
public:
980983
ModuleSummaryIndexBitcodeReader(
981984
BitstreamCursor Stream, StringRef Strtab, ModuleSummaryIndex &TheIndex,
@@ -7162,9 +7165,7 @@ ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(unsigned ValueId) {
71627165
void ModuleSummaryIndexBitcodeReader::setValueGUID(
71637166
uint64_t ValueID, StringRef ValueName, GlobalValue::LinkageTypes Linkage,
71647167
StringRef SourceFileName) {
7165-
std::string GlobalId =
7166-
GlobalValue::getGlobalIdentifier(ValueName, Linkage, SourceFileName);
7167-
auto ValueGUID = GlobalValue::getGUIDAssumingExternalLinkage(GlobalId);
7168+
auto ValueGUID = DefinedGUIDs[ValueID];
71687169
auto OriginalNameID = ValueGUID;
71697170
if (GlobalValue::isLocalLinkage(Linkage))
71707171
OriginalNameID = GlobalValue::getGUIDAssumingExternalLinkage(ValueName);
@@ -7387,6 +7388,10 @@ Error ModuleSummaryIndexBitcodeReader::parseModule() {
73877388
// was historically always the start of the regular bitcode header.
73887389
VSTOffset = Record[0] - 1;
73897390
break;
7391+
// MODULE_CODE_GUIDLIST: [i64 x N]
7392+
case bitc::MODULE_CODE_GUIDLIST:
7393+
llvm::append_range(DefinedGUIDs, Record);
7394+
break;
73907395
// v1 GLOBALVAR: [pointer type, isconst, initid, linkage, ...]
73917396
// v1 FUNCTION: [type, callingconv, isproto, linkage, ...]
73927397
// 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
@@ -244,6 +244,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase {
244244

245245
protected:
246246
void writePerModuleGlobalValueSummary();
247+
void writeGUIDList();
247248

248249
private:
249250
void writePerModuleFunctionSummaryRecord(
@@ -1583,6 +1584,8 @@ void ModuleBitcodeWriter::writeModuleInfo() {
15831584
Vals.clear();
15841585
}
15851586

1587+
writeGUIDList();
1588+
15861589
// Emit the global variable information.
15871590
for (const GlobalVariable &GV : M.globals()) {
15881591
unsigned AbbrevToUse = 0;
@@ -4790,6 +4793,26 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
47904793
Stream.ExitBlock();
47914794
}
47924795

4796+
void ModuleBitcodeWriterBase::writeGUIDList() {
4797+
std::vector<uint64_t> GUIDs;
4798+
GUIDs.reserve(M.global_size() + M.size() + M.alias_size());
4799+
4800+
for (const GlobalValue &GV : M.global_objects()) {
4801+
if (GV.isDeclaration()) {
4802+
GUIDs.push_back(
4803+
GlobalValue::getGUIDAssumingExternalLinkage(GV.getName()));
4804+
} else {
4805+
GUIDs.push_back(GV.getGUID());
4806+
}
4807+
}
4808+
for (const GlobalAlias &GA : M.aliases()) {
4809+
// Equivalent to the above loop, as GlobalAliases are always definitions.
4810+
GUIDs.push_back(GA.getGUID());
4811+
}
4812+
4813+
Stream.EmitRecord(bitc::MODULE_CODE_GUIDLIST, GUIDs);
4814+
}
4815+
47934816
/// Emit the combined summary section into the combined index file.
47944817
void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
47954818
Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 4);
@@ -5578,6 +5601,8 @@ void ThinLinkBitcodeWriter::writeSimplifiedModuleInfo() {
55785601
Vals.clear();
55795602
}
55805603

5604+
writeGUIDList();
5605+
55815606
// Emit the global variable information.
55825607
for (const GlobalVariable &GV : M.globals()) {
55835608
// GLOBALVAR: [strtab offset, strtab size, 0, 0, 0, linkage]

0 commit comments

Comments
 (0)