summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp85
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp84
2 files changed, 52 insertions, 117 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;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index c68a2929dbe..6764e779e0a 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -270,10 +270,6 @@ class IndexBitcodeWriter : public BitcodeWriter {
/// Tracks the last value id recorded in the GUIDToValueMap.
unsigned GlobalValueId = 0;
- /// Record the starting offset of each summary entry for use in the VST
- /// entry, and for any possible alias.
- DenseMap<const GlobalValueSummary *, uint64_t> SummaryToOffsetMap;
-
public:
/// Constructs a IndexBitcodeWriter object for the given combined index,
/// writing to the provided \p Buffer.
@@ -312,13 +308,6 @@ private:
return VMI->second;
}
}
- unsigned popValueId(GlobalValue::GUID ValGUID) {
- const auto &VMI = GUIDToValueIdMap.find(ValGUID);
- assert(VMI != GUIDToValueIdMap.end());
- unsigned ValueId = VMI->second;
- GUIDToValueIdMap.erase(VMI);
- return ValueId;
- }
std::map<GlobalValue::GUID, unsigned> &valueIds() { return GUIDToValueIdMap; }
};
@@ -2629,38 +2618,12 @@ void IndexBitcodeWriter::writeCombinedValueSymbolTable() {
Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
- Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_COMBINED_GVDEFENTRY));
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // sumoffset
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // guid
- unsigned DefEntryAbbrev = Stream.EmitAbbrev(Abbv);
-
- Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_COMBINED_ENTRY));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // refguid
unsigned EntryAbbrev = Stream.EmitAbbrev(Abbv);
SmallVector<uint64_t, 64> NameVals;
-
- for (const auto &GSI : Index) {
- GlobalValue::GUID ValGUID = GSI.first;
- unsigned ValueId = popValueId(ValGUID);
-
- for (const auto &SI : GSI.second) {
- // VST_CODE_COMBINED_GVDEFENTRY: [valueid, sumoffset, guid]
- NameVals.push_back(ValueId);
- auto Offset = SummaryToOffsetMap[SI.get()];
- assert(Offset);
- NameVals.push_back(Offset);
- NameVals.push_back(ValGUID);
-
- // Emit the finished record.
- Stream.EmitRecord(bitc::VST_CODE_COMBINED_GVDEFENTRY, NameVals,
- DefEntryAbbrev);
- NameVals.clear();
- }
- }
for (const auto &GVI : valueIds()) {
// VST_CODE_COMBINED_ENTRY: [valueid, refguid]
NameVals.push_back(GVI.second);
@@ -3194,6 +3157,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
// Abbrev for FS_COMBINED.
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // instcount
@@ -3206,6 +3170,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
// Abbrev for FS_COMBINED_PROFILE.
Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // instcount
@@ -3218,6 +3183,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
// Abbrev for FS_COMBINED_GLOBALVAR_INIT_REFS.
Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); // valueids
@@ -3227,15 +3193,19 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
// Abbrev for FS_COMBINED_ALIAS.
Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_ALIAS));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // flags
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // offset
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
unsigned FSAliasAbbrev = Stream.EmitAbbrev(Abbv);
- // The aliases are emitted as a post-pass, and will point to the summary
- // offset id of the aliasee. Save them in a vector for post-processing.
+ // The aliases are emitted as a post-pass, and will point to the value
+ // id of the aliasee. Save them in a vector for post-processing.
SmallVector<AliasSummary *, 64> Aliases;
+ // Save the value id for each summary for alias emission.
+ DenseMap<const GlobalValueSummary *, unsigned> SummaryToValueIdMap;
+
SmallVector<uint64_t, 64> NameVals;
// For local linkage, we also emit the original name separately
@@ -3252,6 +3222,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
for (auto &SI : GSI.second) {
GlobalValueSummary *S = SI.get();
assert(S);
+
+ assert(hasValueId(GSI.first));
+ unsigned ValueId = getValueId(GSI.first);
+ SummaryToValueIdMap[S] = ValueId;
+
if (auto *AS = dyn_cast<AliasSummary>(S)) {
// Will process aliases as a post-pass because the reader wants all
// global to be loaded first.
@@ -3260,18 +3235,13 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
}
if (auto *VS = dyn_cast<GlobalVarSummary>(S)) {
+ NameVals.push_back(ValueId);
NameVals.push_back(Index.getModuleId(VS->modulePath()));
NameVals.push_back(getEncodedGVSummaryFlags(VS->flags()));
for (auto &RI : VS->refs()) {
NameVals.push_back(getValueId(RI.getGUID()));
}
- // Record the starting offset of this summary entry for use in the VST
- // entry, and for any possible alias. Add the current code size since
- // the reader will invoke readRecord after the abbrev id read.
- SummaryToOffsetMap[S] =
- Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
-
// Emit the finished record.
Stream.EmitRecord(bitc::FS_COMBINED_GLOBALVAR_INIT_REFS, NameVals,
FSModRefsAbbrev);
@@ -3281,6 +3251,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
}
auto *FS = cast<FunctionSummary>(S);
+ NameVals.push_back(ValueId);
NameVals.push_back(Index.getModuleId(FS->modulePath()));
NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
NameVals.push_back(FS->instCount());
@@ -3309,12 +3280,6 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.push_back(EI.second.ProfileCount);
}
- // Record the starting offset of this summary entry for use in the VST
- // entry, and for any possible alias. Add the current code size since
- // the reader will invoke readRecord after the abbrev id read.
- SummaryToOffsetMap[S] =
- Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
-
unsigned FSAbbrev =
(HasProfileData ? FSCallsProfileAbbrev : FSCallsAbbrev);
unsigned Code =
@@ -3328,17 +3293,14 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
}
for (auto *AS : Aliases) {
+ auto AliasValueId = SummaryToValueIdMap[AS];
+ assert(AliasValueId);
+ NameVals.push_back(AliasValueId);
NameVals.push_back(Index.getModuleId(AS->modulePath()));
NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
- auto AliaseeOffset = SummaryToOffsetMap[&AS->getAliasee()];
- assert(AliaseeOffset);
- NameVals.push_back(AliaseeOffset);
-
- // Record the starting offset of this summary entry for use
- // in the VST entry. Add the current code size since the
- // reader will invoke readRecord after the abbrev id read.
- SummaryToOffsetMap[AS] =
- Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
+ auto AliaseeValueId = SummaryToValueIdMap[&AS->getAliasee()];
+ assert(AliaseeValueId);
+ NameVals.push_back(AliaseeValueId);
// Emit the finished record.
Stream.EmitRecord(bitc::FS_COMBINED_ALIAS, NameVals, FSAliasAbbrev);
OpenPOWER on IntegriCloud