summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-04-27 13:28:35 +0000
committerTeresa Johnson <tejohnson@google.com>2016-04-27 13:28:35 +0000
commit02e98331c04b9235d4b54c524db4885053c9fce0 (patch)
tree2a88d8b2ac00f1e95deacc98436cee56f9bb90ba /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent68d2b881d28ac77933d2580a50e23ec2e89a6a13 (diff)
downloadbcm5719-llvm-02e98331c04b9235d4b54c524db4885053c9fce0.tar.gz
bcm5719-llvm-02e98331c04b9235d4b54c524db4885053c9fce0.zip
[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 llvm-svn: 267712
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp85
1 files changed, 29 insertions, 56 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 90934cc30a1..b2b25df5c5d 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -492,11 +492,6 @@ class ModuleSummaryIndexBitcodeReader {
DenseMap<unsigned, std::pair<GlobalValue::GUID, GlobalValue::GUID>>
ValueIdToCallGraphGUIDMap;
- /// Map to save the association between summary offset in the VST to the
- /// GUID created when parsing it. Used to add newly parsed summaries to
- /// the index.
- DenseMap<uint64_t, GlobalValue::GUID> SummaryOffsetToGUIDMap;
-
/// Map populated during module path string table parsing, from the
/// module ID to a string reference owned by the index's module
/// path string table, used to correlate with combined index
@@ -548,7 +543,6 @@ private:
std::error_code initLazyStream(std::unique_ptr<DataStreamer> Streamer);
std::pair<GlobalValue::GUID, GlobalValue::GUID>
getGUIDFromValueId(unsigned ValueId);
- GlobalValue::GUID getGUIDFromOffset(uint64_t Offset);
};
} // end anonymous namespace
@@ -5740,13 +5734,6 @@ ModuleSummaryIndexBitcodeReader::getGUIDFromValueId(unsigned ValueId) {
return VGI->second;
}
-GlobalValue::GUID
-ModuleSummaryIndexBitcodeReader::getGUIDFromOffset(uint64_t Offset) {
- auto I = SummaryOffsetToGUIDMap.find(Offset);
- assert(I != SummaryOffsetToGUIDMap.end());
- return I->second;
-}
-
// Specialized value symbol table parser used when reading module index
// blocks where we don't actually create global values. The parsed information
// is saved in the bitcode reader for use when later parsing summaries.
@@ -5832,18 +5819,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
ValueName.clear();
break;
}
- case bitc::VST_CODE_COMBINED_GVDEFENTRY: {
- // VST_CODE_COMBINED_GVDEFENTRY: [valueid, offset, guid]
- unsigned ValueID = Record[0];
- uint64_t GlobalValSummaryOffset = Record[1];
- GlobalValue::GUID GlobalValGUID = Record[2];
- SummaryOffsetToGUIDMap[GlobalValSummaryOffset] = GlobalValGUID;
- // The "original name", which is the second value of the pair will be
- // overriden later by a FS_COMBINED_ORIGINAL_NAME in the combined index.
- ValueIdToCallGraphGUIDMap[ValueID] =
- std::make_pair(GlobalValGUID, GlobalValGUID);
- break;
- }
case bitc::VST_CODE_COMBINED_ENTRY: {
// VST_CODE_COMBINED_ENTRY: [valueid, refguid]
unsigned ValueID = Record[0];
@@ -6030,11 +6005,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
// "OriginalName" attachement.
GlobalValueSummary *LastSeenSummary = nullptr;
bool Combined = false;
- // For aliases in the combined summary, we need to know which summary
- // corresponds to the aliasee offset saved in the alias summary. It isn't
- // sufficient to just map to the aliasee GUID, since in the combined summary
- // there may be multiple values with the same GUID.
- DenseMap<uint64_t, GlobalValueSummary *> OffsetToSummaryMap;
while (1) {
BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
@@ -6067,7 +6037,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
// in the combined index VST entries). The records also contain
// information used for ThinLTO renaming and importing.
Record.clear();
- uint64_t CurRecordBit = Stream.GetCurrentBitNo();
auto BitCode = Stream.readRecord(Entry.ID, Record);
switch (BitCode) {
default: // Default behavior: ignore.
@@ -6164,27 +6133,29 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
break;
}
- // FS_COMBINED: [modid, flags, instcount, numrefs, numrefs x valueid,
- // n x (valueid, callsitecount)]
- // FS_COMBINED_PROFILE: [modid, flags, instcount, numrefs,
+ // FS_COMBINED: [valueid, modid, flags, instcount, numrefs,
+ // numrefs x valueid, n x (valueid, callsitecount)]
+ // FS_COMBINED_PROFILE: [valueid, modid, flags, instcount, numrefs,
// numrefs x valueid,
// n x (valueid, callsitecount, profilecount)]
case bitc::FS_COMBINED:
case bitc::FS_COMBINED_PROFILE: {
- uint64_t ModuleId = Record[0];
- uint64_t RawFlags = Record[1];
- unsigned InstCount = Record[2];
- unsigned NumRefs = Record[3];
+ unsigned ValueID = Record[0];
+ uint64_t ModuleId = Record[1];
+ uint64_t RawFlags = Record[2];
+ unsigned InstCount = Record[3];
+ unsigned NumRefs = Record[4];
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
std::unique_ptr<FunctionSummary> FS =
llvm::make_unique<FunctionSummary>(Flags, InstCount);
LastSeenSummary = FS.get();
FS->setModulePath(ModuleIdMap[ModuleId]);
- static int RefListStartIndex = 4;
+ static int RefListStartIndex = 5;
int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
assert(Record.size() >= RefListStartIndex + NumRefs &&
"Record size inconsistent with number of references");
- for (unsigned I = 4, E = CallGraphEdgeStartIndex; I != E; ++I) {
+ for (unsigned I = RefListStartIndex, E = CallGraphEdgeStartIndex; I != E;
+ ++I) {
unsigned RefValueId = Record[I];
GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
FS->addRefEdge(RefGUID);
@@ -6199,50 +6170,52 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
FS->addCallGraphEdge(CalleeGUID,
CalleeInfo(CallsiteCount, ProfileCount));
}
- GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
- OffsetToSummaryMap[CurRecordBit] = FS.get();
+ GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
TheIndex->addGlobalValueSummary(GUID, std::move(FS));
Combined = true;
break;
}
- // FS_COMBINED_ALIAS: [modid, flags, offset]
+ // FS_COMBINED_ALIAS: [valueid, modid, flags, valueid]
// Aliases must be emitted (and parsed) after all FS_COMBINED entries, as
// they expect all aliasee summaries to be available.
case bitc::FS_COMBINED_ALIAS: {
- uint64_t ModuleId = Record[0];
- uint64_t RawFlags = Record[1];
- uint64_t AliaseeSummaryOffset = Record[2];
+ unsigned ValueID = Record[0];
+ uint64_t ModuleId = Record[1];
+ uint64_t RawFlags = Record[2];
+ unsigned AliaseeValueId = Record[3];
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
std::unique_ptr<AliasSummary> AS = llvm::make_unique<AliasSummary>(Flags);
LastSeenSummary = AS.get();
AS->setModulePath(ModuleIdMap[ModuleId]);
- auto *AliaseeSummary = OffsetToSummaryMap[AliaseeSummaryOffset];
- if (!AliaseeSummary)
+ auto AliaseeGUID = getGUIDFromValueId(AliaseeValueId).first;
+ auto AliaseeInModule =
+ TheIndex->findSummaryInModule(AliaseeGUID, AS->modulePath());
+ if (!AliaseeInModule)
return error("Alias expects aliasee summary to be parsed");
- AS->setAliasee(AliaseeSummary);
+ AS->setAliasee(AliaseeInModule);
- GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
+ GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
TheIndex->addGlobalValueSummary(GUID, std::move(AS));
Combined = true;
break;
}
- // FS_COMBINED_GLOBALVAR_INIT_REFS: [modid, flags, n x valueid]
+ // FS_COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid]
case bitc::FS_COMBINED_GLOBALVAR_INIT_REFS: {
- uint64_t ModuleId = Record[0];
- uint64_t RawFlags = Record[1];
+ unsigned ValueID = Record[0];
+ uint64_t ModuleId = Record[1];
+ uint64_t RawFlags = Record[2];
auto Flags = getDecodedGVSummaryFlags(RawFlags, Version);
std::unique_ptr<GlobalVarSummary> FS =
llvm::make_unique<GlobalVarSummary>(Flags);
LastSeenSummary = FS.get();
FS->setModulePath(ModuleIdMap[ModuleId]);
- for (unsigned I = 2, E = Record.size(); I != E; ++I) {
+ for (unsigned I = 3, E = Record.size(); I != E; ++I) {
unsigned RefValueId = Record[I];
GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
FS->addRefEdge(RefGUID);
}
- GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
- OffsetToSummaryMap[CurRecordBit] = FS.get();
+ GlobalValue::GUID GUID = getGUIDFromValueId(ValueID).first;
TheIndex->addGlobalValueSummary(GUID, std::move(FS));
Combined = true;
break;
OpenPOWER on IntegriCloud