Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6c14deb

Browse files
teresajohnsonjoker-eph
authored andcommitted
[ThinLTO] Use valueid instead of bitcode offsets in combined index file
Summary: With the removal of support for lazy parsing of combined index summary records (e.g. r267344), we no longer need to include the summary record bitcode offset in the VST entries for definitions. Change the combined index format to be similar to the per-module index format in using value ids to cross-reference from the summary record to the VST entry (rather than the summary record bitcode offset to cross-reference in the other direction). The visible changes are: 1) Add the value id to the combined summary records 2) Remove the summary offset from the combined VST records, which has the following effects: - No longer need the VST_CODE_COMBINED_GVDEFENTRY record, as all combined index VST entries now only contain the value id and corresponding GUID. - No longer have duplicate VST entries in the case where there are multiple definitions of a symbol (e.g. weak/linkonce), as they all have the same value id and GUID. An implication of #2 above is that in order to hook up an alias to the correct aliasee based on the value id of the aliasee recorded in the combined index alias record, we need to scan the entries in the index for that GUID to find the one from the same module (i.e. the case where there are multiple entries for the aliasee). But the reader no longer has to maintain a special map to hook up the alias/aliasee. Reviewers: joker.eph Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D19481 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267712 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 595b083 commit 6c14deb

13 files changed

+101
-151
lines changed

include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ enum ValueSymtabCodes {
177177
VST_CODE_ENTRY = 1, // VST_ENTRY: [valueid, namechar x N]
178178
VST_CODE_BBENTRY = 2, // VST_BBENTRY: [bbid, namechar x N]
179179
VST_CODE_FNENTRY = 3, // VST_FNENTRY: [valueid, offset, namechar x N]
180-
// VST_COMBINED_GVDEFENTRY: [valueid, sumoffset, guid]
181-
VST_CODE_COMBINED_GVDEFENTRY = 4,
182180
// VST_COMBINED_ENTRY: [valueid, refguid]
183181
VST_CODE_COMBINED_ENTRY = 5
184182
};
@@ -201,18 +199,18 @@ enum GlobalValueSummarySymtabCodes {
201199
FS_PERMODULE_PROFILE = 2,
202200
// PERMODULE_GLOBALVAR_INIT_REFS: [valueid, flags, n x valueid]
203201
FS_PERMODULE_GLOBALVAR_INIT_REFS = 3,
204-
// COMBINED: [modid, flags, instcount, numrefs, numrefs x valueid,
202+
// COMBINED: [valueid, modid, flags, instcount, numrefs, numrefs x valueid,
205203
// n x (valueid, callsitecount)]
206204
FS_COMBINED = 4,
207-
// COMBINED_PROFILE: [modid, flags, instcount, numrefs,
205+
// COMBINED_PROFILE: [valueid, modid, flags, instcount, numrefs,
208206
// numrefs x valueid,
209207
// n x (valueid, callsitecount, profilecount)]
210208
FS_COMBINED_PROFILE = 5,
211-
// COMBINED_GLOBALVAR_INIT_REFS: [modid, flags, n x valueid]
209+
// COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid]
212210
FS_COMBINED_GLOBALVAR_INIT_REFS = 6,
213211
// ALIAS: [valueid, flags, valueid]
214212
FS_ALIAS = 7,
215-
// COMBINED_ALIAS: [modid, flags, offset]
213+
// COMBINED_ALIAS: [valueid, modid, flags, valueid]
216214
FS_COMBINED_ALIAS = 8,
217215
// COMBINED_ORIGINAL_NAME: [original_name_hash]
218216
FS_COMBINED_ORIGINAL_NAME = 9,

include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,24 @@ class ModuleSummaryIndex {
376376
GlobalValueMap[ValueGUID].push_back(std::move(Summary));
377377
}
378378

379+
/// Find the summary for global \p GUID in module \p ModuleId, or nullptr if
380+
/// not found.
381+
GlobalValueSummary *findSummaryInModule(GlobalValue::GUID ValueGUID,
382+
StringRef ModuleId) const {
383+
auto CalleeInfoList = findGlobalValueSummaryList(ValueGUID);
384+
if (CalleeInfoList == end()) {
385+
return nullptr; // This function does not have a summary
386+
}
387+
auto Summary =
388+
llvm::find_if(CalleeInfoList->second,
389+
[&](const std::unique_ptr<GlobalValueSummary> &Summary) {
390+
return Summary->modulePath() == ModuleId;
391+
});
392+
if (Summary == CalleeInfoList->second.end())
393+
return nullptr;
394+
return Summary->get();
395+
}
396+
379397
/// Returns the first GlobalValueSummary for \p GV, asserting that there
380398
/// is only one if \p PerModuleIndex.
381399
GlobalValueSummary *getGlobalValueSummary(const GlobalValue &GV,

lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,6 @@ class ModuleSummaryIndexBitcodeReader {
491491
DenseMap<unsigned, std::pair<GlobalValue::GUID, GlobalValue::GUID>>
492492
ValueIdToCallGraphGUIDMap;
493493

494-
/// Map to save the association between summary offset in the VST to the
495-
/// GUID created when parsing it. Used to add newly parsed summaries to
496-
/// the index.
497-
DenseMap<uint64_t, GlobalValue::GUID> SummaryOffsetToGUIDMap;
498-
499494
/// Map populated during module path string table parsing, from the
500495
/// module ID to a string reference owned by the index's module
501496
/// path string table, used to correlate with combined index
@@ -547,7 +542,6 @@ class ModuleSummaryIndexBitcodeReader {
547542
std::error_code initLazyStream(std::unique_ptr<DataStreamer> Streamer);
548543
std::pair<GlobalValue::GUID, GlobalValue::GUID>
549544
getGUIDFromValueId(unsigned ValueId);
550-
GlobalValue::GUID getGUIDFromOffset(uint64_t Offset);
551545
};
552546
} // namespace
553547

@@ -5738,13 +5732,6 @@ ModuleSummaryIndexBitcodeReader::getGUIDFromValueId(unsigned ValueId) {
57385732
return VGI->second;
57395733
}
57405734

5741-
GlobalValue::GUID
5742-
ModuleSummaryIndexBitcodeReader::getGUIDFromOffset(uint64_t Offset) {
5743-
auto I = SummaryOffsetToGUIDMap.find(Offset);
5744-
assert(I != SummaryOffsetToGUIDMap.end());
5745-
return I->second;
5746-
}
5747-
57485735
// Specialized value symbol table parser used when reading module index
57495736
// blocks where we don't actually create global values. The parsed information
57505737
// is saved in the bitcode reader for use when later parsing summaries.
@@ -5830,18 +5817,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
58305817
ValueName.clear();
58315818
break;
58325819
}
5833-
case bitc::VST_CODE_COMBINED_GVDEFENTRY: {
5834-
// VST_CODE_COMBINED_GVDEFENTRY: [valueid, offset, guid]
5835-
unsigned ValueID = Record[0];
5836-
uint64_t GlobalValSummaryOffset = Record[1];
5837-
GlobalValue::GUID GlobalValGUID = Record[2];
5838-
SummaryOffsetToGUIDMap[GlobalValSummaryOffset] = GlobalValGUID;
5839-
// The "original name", which is the second value of the pair will be
5840-
// overriden later by a FS_COMBINED_ORIGINAL_NAME in the combined index.
5841-
ValueIdToCallGraphGUIDMap[ValueID] =
5842-
std::make_pair(GlobalValGUID, GlobalValGUID);
5843-
break;
5844-
}
58455820
case bitc::VST_CODE_COMBINED_ENTRY: {
58465821
// VST_CODE_COMBINED_ENTRY: [valueid, refguid]
58475822
unsigned ValueID = Record[0];
@@ -6028,11 +6003,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
60286003
// "OriginalName" attachement.
60296004
GlobalValueSummary *LastSeenSummary = nullptr;
60306005
bool Combined = false;
6031-
// For aliases in the combined summary, we need to know which summary
6032-
// corresponds to the aliasee offset saved in the alias summary. It isn't
6033-
// sufficient to just map to the aliasee GUID, since in the combined summary
6034-
// there may be multiple values with the same GUID.
6035-
DenseMap<uint64_t, GlobalValueSummary *> OffsetToSummaryMap;
60366006
while (1) {
60376007
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
60386008

@@ -6065,7 +6035,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
60656035
// in the combined index VST entries). The records also contain
60666036
// information used for ThinLTO renaming and importing.
60676037
Record.clear();
6068-
uint64_t CurRecordBit = Stream.GetCurrentBitNo();
60696038
auto BitCode = Stream.readRecord(Entry.ID, Record);
60706039
switch (BitCode) {
60716040
default: // Default behavior: ignore.
@@ -6162,27 +6131,29 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
61626131
TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
61636132
break;
61646133
}
6165-
// FS_COMBINED: [modid, flags, instcount, numrefs, numrefs x valueid,
6166-
// n x (valueid, callsitecount)]
6167-
// FS_COMBINED_PROFILE: [modid, flags, instcount, numrefs,
6134+
// FS_COMBINED: [valueid, modid, flags, instcount, numrefs,
6135+
// numrefs x valueid, n x (valueid, callsitecount)]
6136+
// FS_COMBINED_PROFILE: [valueid, modid, flags, instcount, numrefs,
61686137
// numrefs x valueid,
61696138
// n x (valueid, callsitecount, profilecount)]
61706139
case bitc::FS_COMBINED:
61716140
case bitc::FS_COMBINED_PROFILE: {
6172-
uint64_t ModuleId = Record[0];
6173-
uint64_t RawFlags = Record[1];
6174-
unsigned InstCount = Record[2];
6175-
unsigned NumRefs = Record[3];
6141+
unsigned ValueID = Record[0];
6142+
uint64_t ModuleId = Record[1];
6143+
uint64_t RawFlags = Record[2];
6144+
unsigned InstCount = Record[3];
6145+
unsigned NumRefs = Record[4];
61766146
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
61776147
std::unique_ptr<FunctionSummary> FS =
61786148
llvm::make_unique<FunctionSummary>(Flags, InstCount);
61796149
LastSeenSummary = FS.get();
61806150
FS->setModulePath(ModuleIdMap[ModuleId]);
6181-
static int RefListStartIndex = 4;
6151+
static int RefListStartIndex = 5;
61826152
int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
61836153
assert(Record.size() >= RefListStartIndex + NumRefs &&
61846154
"Record size inconsistent with number of references");
6185-
for (unsigned I = 4, E = CallGraphEdgeStartIndex; I != E; ++I) {
6155+
for (unsigned I = RefListStartIndex, E = CallGraphEdgeStartIndex; I != E;
6156+
++I) {
61866157
unsigned RefValueId = Record[I];
61876158
GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
61886159
FS->addRefEdge(RefGUID);
@@ -6197,50 +6168,52 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
61976168
FS->addCallGraphEdge(CalleeGUID,
61986169
CalleeInfo(CallsiteCount, ProfileCount));
61996170
}
6200-
GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
6201-
OffsetToSummaryMap[CurRecordBit] = FS.get();
6171+
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
62026172
TheIndex->addGlobalValueSummary(GUID, std::move(FS));
62036173
Combined = true;
62046174
break;
62056175
}
6206-
// FS_COMBINED_ALIAS: [modid, flags, offset]
6176+
// FS_COMBINED_ALIAS: [valueid, modid, flags, valueid]
62076177
// Aliases must be emitted (and parsed) after all FS_COMBINED entries, as
62086178
// they expect all aliasee summaries to be available.
62096179
case bitc::FS_COMBINED_ALIAS: {
6210-
uint64_t ModuleId = Record[0];
6211-
uint64_t RawFlags = Record[1];
6212-
uint64_t AliaseeSummaryOffset = Record[2];
6180+
unsigned ValueID = Record[0];
6181+
uint64_t ModuleId = Record[1];
6182+
uint64_t RawFlags = Record[2];
6183+
unsigned AliaseeValueId = Record[3];
62136184
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
62146185
std::unique_ptr<AliasSummary> AS = llvm::make_unique<AliasSummary>(Flags);
62156186
LastSeenSummary = AS.get();
62166187
AS->setModulePath(ModuleIdMap[ModuleId]);
62176188

6218-
auto *AliaseeSummary = OffsetToSummaryMap[AliaseeSummaryOffset];
6219-
if (!AliaseeSummary)
6189+
auto AliaseeGUID = getGUIDFromValueId(AliaseeValueId).first;
6190+
auto AliaseeInModule =
6191+
TheIndex->findSummaryInModule(AliaseeGUID, AS->modulePath());
6192+
if (!AliaseeInModule)
62206193
return error("Alias expects aliasee summary to be parsed");
6221-
AS->setAliasee(AliaseeSummary);
6194+
AS->setAliasee(AliaseeInModule);
62226195

6223-
GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
6196+
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
62246197
TheIndex->addGlobalValueSummary(GUID, std::move(AS));
62256198
Combined = true;
62266199
break;
62276200
}
6228-
// FS_COMBINED_GLOBALVAR_INIT_REFS: [modid, flags, n x valueid]
6201+
// FS_COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid]
62296202
case bitc::FS_COMBINED_GLOBALVAR_INIT_REFS: {
6230-
uint64_t ModuleId = Record[0];
6231-
uint64_t RawFlags = Record[1];
6203+
unsigned ValueID = Record[0];
6204+
uint64_t ModuleId = Record[1];
6205+
uint64_t RawFlags = Record[2];
62326206
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
62336207
std::unique_ptr<GlobalVarSummary> FS =
62346208
llvm::make_unique<GlobalVarSummary>(Flags);
62356209
LastSeenSummary = FS.get();
62366210
FS->setModulePath(ModuleIdMap[ModuleId]);
6237-
for (unsigned I = 2, E = Record.size(); I != E; ++I) {
6211+
for (unsigned I = 3, E = Record.size(); I != E; ++I) {
62386212
unsigned RefValueId = Record[I];
62396213
GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
62406214
FS->addRefEdge(RefGUID);
62416215
}
6242-
GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
6243-
OffsetToSummaryMap[CurRecordBit] = FS.get();
6216+
GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
62446217
TheIndex->addGlobalValueSummary(GUID, std::move(FS));
62456218
Combined = true;
62466219
break;

0 commit comments

Comments
 (0)