Skip to content

Add a GUIDLIST table to bitcode #139497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: users/orodley/guid-2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/Bitcode/LLVMBitCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,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,
Expand Down Expand Up @@ -7162,9 +7165,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);
Expand Down Expand Up @@ -7387,6 +7388,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, ...]
Expand Down
25 changes: 25 additions & 0 deletions llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase {

protected:
void writePerModuleGlobalValueSummary();
void writeGUIDList();

private:
void writePerModuleFunctionSummaryRecord(
Expand Down Expand Up @@ -1583,6 +1584,8 @@ void ModuleBitcodeWriter::writeModuleInfo() {
Vals.clear();
}

writeGUIDList();

// Emit the global variable information.
for (const GlobalVariable &GV : M.globals()) {
unsigned AbbrevToUse = 0;
Expand Down Expand Up @@ -4790,6 +4793,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);
Expand Down Expand Up @@ -5578,6 +5601,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]
Expand Down
Loading