summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-04-24 14:57:11 +0000
committerTeresa Johnson <tejohnson@google.com>2016-04-24 14:57:11 +0000
commit28e457bccd6d1dd6ba91d36253073372a1bb5d75 (patch)
tree5368e89d5262e31ef567218d31c72a894cde3f5c /llvm/lib/Bitcode
parent9f5697ef6803acededad77a51b40a3fbec905c81 (diff)
downloadbcm5719-llvm-28e457bccd6d1dd6ba91d36253073372a1bb5d75.tar.gz
bcm5719-llvm-28e457bccd6d1dd6ba91d36253073372a1bb5d75.zip
[ThinLTO] Remove GlobalValueInfo class from index
Summary: Remove the GlobalValueInfo and change the ModuleSummaryIndex to directly reference summary objects. The info structure was there to support lazy parsing of the combined index summary objects, which is no longer needed and not supported. Reviewers: joker.eph Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D19462 llvm-svn: 267344
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp84
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp77
2 files changed, 73 insertions, 88 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 7dbf4e64cf2..571306ef2be 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -493,9 +493,9 @@ class ModuleSummaryIndexBitcodeReader {
ValueIdToCallGraphGUIDMap;
/// Map to save the association between summary offset in the VST to the
- /// GlobalValueInfo object created when parsing it. Used to access the
- /// info object when parsing the summary section.
- DenseMap<uint64_t, GlobalValueInfo *> SummaryOffsetToInfoMap;
+ /// 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
@@ -548,7 +548,7 @@ private:
std::error_code initLazyStream(std::unique_ptr<DataStreamer> Streamer);
std::pair<GlobalValue::GUID, GlobalValue::GUID>
getGUIDFromValueId(unsigned ValueId);
- GlobalValueInfo *getInfoFromSummaryOffset(uint64_t Offset);
+ GlobalValue::GUID getGUIDFromOffset(uint64_t Offset);
};
} // end anonymous namespace
@@ -5736,19 +5736,16 @@ ModuleSummaryIndexBitcodeReader::getGUIDFromValueId(unsigned ValueId) {
return VGI->second;
}
-GlobalValueInfo *
-ModuleSummaryIndexBitcodeReader::getInfoFromSummaryOffset(uint64_t Offset) {
- auto I = SummaryOffsetToInfoMap.find(Offset);
- assert(I != SummaryOffsetToInfoMap.end());
+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.
-// At the end of this routine the module index is populated with a map
-// from global value name to GlobalValueInfo. The global value info contains
-// the function block's bitcode offset (if applicable), or the offset into the
-// summary section for the combined 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.
std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
uint64_t Offset,
DenseMap<unsigned, GlobalValue::LinkageTypes> &ValueIdToLinkageMap) {
@@ -5787,8 +5784,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
if (convertToString(Record, 1, ValueName))
return error("Invalid record");
unsigned ValueID = Record[0];
- std::unique_ptr<GlobalValueInfo> GlobalValInfo =
- llvm::make_unique<GlobalValueInfo>();
assert(!SourceFileName.empty());
auto VLI = ValueIdToLinkageMap.find(ValueID);
assert(VLI != ValueIdToLinkageMap.end() &&
@@ -5803,7 +5798,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
if (PrintSummaryGUIDs)
dbgs() << "GUID " << ValueGUID << "(" << OriginalNameID << ") is "
<< ValueName << "\n";
- TheIndex->addGlobalValueInfo(ValueGUID, std::move(GlobalValInfo));
ValueIdToCallGraphGUIDMap[ValueID] =
std::make_pair(ValueGUID, OriginalNameID);
ValueName.clear();
@@ -5814,9 +5808,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
if (convertToString(Record, 2, ValueName))
return error("Invalid record");
unsigned ValueID = Record[0];
- uint64_t FuncOffset = Record[1];
- std::unique_ptr<GlobalValueInfo> FuncInfo =
- llvm::make_unique<GlobalValueInfo>(FuncOffset);
assert(!SourceFileName.empty());
auto VLI = ValueIdToLinkageMap.find(ValueID);
assert(VLI != ValueIdToLinkageMap.end() &&
@@ -5831,7 +5822,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
if (PrintSummaryGUIDs)
dbgs() << "GUID " << FunctionGUID << "(" << OriginalNameID << ") is "
<< ValueName << "\n";
- TheIndex->addGlobalValueInfo(FunctionGUID, std::move(FuncInfo));
ValueIdToCallGraphGUIDMap[ValueID] =
std::make_pair(FunctionGUID, OriginalNameID);
@@ -5843,10 +5833,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
unsigned ValueID = Record[0];
uint64_t GlobalValSummaryOffset = Record[1];
GlobalValue::GUID GlobalValGUID = Record[2];
- std::unique_ptr<GlobalValueInfo> GlobalValInfo =
- llvm::make_unique<GlobalValueInfo>(GlobalValSummaryOffset);
- SummaryOffsetToInfoMap[GlobalValSummaryOffset] = GlobalValInfo.get();
- TheIndex->addGlobalValueInfo(GlobalValGUID, std::move(GlobalValInfo));
+ 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] =
@@ -5868,8 +5855,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
// Parse just the blocks needed for building the index out of the module.
// At the end of this routine the module Index is populated with a map
-// from global value name to GlobalValueInfo. The global value info contains
-// the parsed summary information (when parsing summaries eagerly).
+// from global value id to GlobalValueSummary objects.
std::error_code ModuleSummaryIndexBitcodeReader::parseModule() {
if (Stream.EnterSubBlock(bitc::MODULE_BLOCK_ID))
return error("Invalid record");
@@ -6040,6 +6026,11 @@ 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();
@@ -6119,9 +6110,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
}
auto GUID = getGUIDFromValueId(ValueID);
FS->setOriginalName(GUID.second);
- auto *Info = TheIndex->getGlobalValueInfo(GUID.first);
- assert(!Info->summary() && "Expected a single summary per VST entry");
- Info->setSummary(std::move(FS));
+ TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
break;
}
// FS_ALIAS: [valueid, flags, valueid]
@@ -6142,16 +6131,14 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
TheIndex->addModulePath(Buffer->getBufferIdentifier(), 0)->first());
GlobalValue::GUID AliaseeGUID = getGUIDFromValueId(AliaseeID).first;
- auto *AliaseeInfo = TheIndex->getGlobalValueInfo(AliaseeGUID);
- if (!AliaseeInfo->summary())
+ auto *AliaseeSummary = TheIndex->getGlobalValueSummary(AliaseeGUID);
+ if (!AliaseeSummary)
return error("Alias expects aliasee summary to be parsed");
- AS->setAliasee(AliaseeInfo->summary());
+ AS->setAliasee(AliaseeSummary);
auto GUID = getGUIDFromValueId(ValueID);
AS->setOriginalName(GUID.second);
- auto *Info = TheIndex->getGlobalValueInfo(GUID.first);
- assert(!Info->summary() && "Expected a single summary per VST entry");
- Info->setSummary(std::move(AS));
+ TheIndex->addGlobalValueSummary(GUID.first, std::move(AS));
break;
}
// FS_PERMODULE_GLOBALVAR_INIT_REFS: [valueid, flags, n x valueid]
@@ -6170,9 +6157,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
}
auto GUID = getGUIDFromValueId(ValueID);
FS->setOriginalName(GUID.second);
- auto *Info = TheIndex->getGlobalValueInfo(GUID.first);
- assert(!Info->summary() && "Expected a single summary per VST entry");
- Info->setSummary(std::move(FS));
+ TheIndex->addGlobalValueSummary(GUID.first, std::move(FS));
break;
}
// FS_COMBINED: [modid, flags, instcount, numrefs, numrefs x valueid,
@@ -6210,9 +6195,9 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
FS->addCallGraphEdge(CalleeGUID,
CalleeInfo(CallsiteCount, ProfileCount));
}
- auto *Info = getInfoFromSummaryOffset(CurRecordBit);
- assert(!Info->summary() && "Expected a single summary per VST entry");
- Info->setSummary(std::move(FS));
+ GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
+ OffsetToSummaryMap[CurRecordBit] = FS.get();
+ TheIndex->addGlobalValueSummary(GUID, std::move(FS));
Combined = true;
break;
}
@@ -6228,14 +6213,13 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
LastSeenSummary = AS.get();
AS->setModulePath(ModuleIdMap[ModuleId]);
- auto *AliaseeInfo = getInfoFromSummaryOffset(AliaseeSummaryOffset);
- if (!AliaseeInfo->summary())
+ auto *AliaseeSummary = OffsetToSummaryMap[AliaseeSummaryOffset];
+ if (!AliaseeSummary)
return error("Alias expects aliasee summary to be parsed");
- AS->setAliasee(AliaseeInfo->summary());
+ AS->setAliasee(AliaseeSummary);
- auto *Info = getInfoFromSummaryOffset(CurRecordBit);
- assert(!Info->summary() && "Expected a single summary per VST entry");
- Info->setSummary(std::move(AS));
+ GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
+ TheIndex->addGlobalValueSummary(GUID, std::move(AS));
Combined = true;
break;
}
@@ -6253,9 +6237,9 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() {
GlobalValue::GUID RefGUID = getGUIDFromValueId(RefValueId).first;
FS->addRefEdge(RefGUID);
}
- auto *Info = getInfoFromSummaryOffset(CurRecordBit);
- assert(!Info->summary() && "Expected a single summary per VST entry");
- Info->setSummary(std::move(FS));
+ GlobalValue::GUID GUID = getGUIDFromOffset(CurRecordBit);
+ OffsetToSummaryMap[CurRecordBit] = FS.get();
+ 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 715d66f052e..c68a2929dbe 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -246,7 +246,7 @@ private:
DenseMap<const Function *, uint64_t> &FunctionToBitcodeIndex);
void writeBlockInfo();
void writePerModuleFunctionSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
- GlobalValueInfo *Info,
+ GlobalValueSummary *Summary,
unsigned ValueID,
unsigned FSCallsAbbrev,
unsigned FSCallsProfileAbbrev,
@@ -270,6 +270,10 @@ 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.
@@ -2639,15 +2643,17 @@ void IndexBitcodeWriter::writeCombinedValueSymbolTable() {
SmallVector<uint64_t, 64> NameVals;
- for (const auto &FII : Index) {
- GlobalValue::GUID FuncGUID = FII.first;
- unsigned ValueId = popValueId(FuncGUID);
+ for (const auto &GSI : Index) {
+ GlobalValue::GUID ValGUID = GSI.first;
+ unsigned ValueId = popValueId(ValGUID);
- for (const auto &FI : FII.second) {
+ for (const auto &SI : GSI.second) {
// VST_CODE_COMBINED_GVDEFENTRY: [valueid, sumoffset, guid]
NameVals.push_back(ValueId);
- NameVals.push_back(FI->bitcodeIndex());
- NameVals.push_back(FuncGUID);
+ 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,
@@ -3031,12 +3037,12 @@ void IndexBitcodeWriter::writeModStrings() {
// Helper to emit a single function summary record.
void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord(
- SmallVector<uint64_t, 64> &NameVals, GlobalValueInfo *Info,
+ SmallVector<uint64_t, 64> &NameVals, GlobalValueSummary *Summary,
unsigned ValueID, unsigned FSCallsAbbrev, unsigned FSCallsProfileAbbrev,
const Function &F) {
NameVals.push_back(ValueID);
- FunctionSummary *FS = cast<FunctionSummary>(Info->summary());
+ FunctionSummary *FS = cast<FunctionSummary>(Summary);
NameVals.push_back(getEncodedGVSummaryFlags(FS->flags()));
NameVals.push_back(FS->instCount());
NameVals.push_back(FS->refs().size());
@@ -3072,8 +3078,8 @@ void ModuleBitcodeWriter::writeModuleLevelReferences(
return;
NameVals.push_back(VE.getValueID(&V));
NameVals.push_back(getEncodedGVSummaryFlags(V));
- auto *Info = Index->getGlobalValueInfo(V);
- GlobalVarSummary *VS = cast<GlobalVarSummary>(Info->summary());
+ auto *Summary = Index->getGlobalValueSummary(V);
+ GlobalVarSummary *VS = cast<GlobalVarSummary>(Summary);
for (auto Ref : VS->refs())
NameVals.push_back(VE.getValueID(Ref.getValue()));
Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals,
@@ -3151,9 +3157,9 @@ void ModuleBitcodeWriter::writePerModuleGlobalValueSummary() {
if (!F.hasName())
report_fatal_error("Unexpected anonymous function when writing summary");
- auto *Info = Index->getGlobalValueInfo(F);
+ auto *Summary = Index->getGlobalValueSummary(F);
writePerModuleFunctionSummaryRecord(
- NameVals, Info,
+ NameVals, Summary,
VE.getValueID(M.getValueSymbolTable().lookup(F.getName())),
FSCallsAbbrev, FSCallsProfileAbbrev, F);
}
@@ -3227,10 +3233,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
unsigned FSAliasAbbrev = Stream.EmitAbbrev(Abbv);
// The aliases are emitted as a post-pass, and will point to the summary
- // offset id of the aliasee. For this purpose we need to be able to get back
- // from the summary to the offset
- SmallVector<GlobalValueInfo *, 64> Aliases;
- DenseMap<const GlobalValueSummary *, uint64_t> SummaryToOffsetMap;
+ // offset id of the aliasee. Save them in a vector for post-processing.
+ SmallVector<AliasSummary *, 64> Aliases;
SmallVector<uint64_t, 64> NameVals;
@@ -3244,14 +3248,14 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.clear();
};
- for (const auto &FII : Index) {
- for (auto &FI : FII.second) {
- GlobalValueSummary *S = FI->summary();
+ for (const auto &GSI : Index) {
+ for (auto &SI : GSI.second) {
+ GlobalValueSummary *S = SI.get();
assert(S);
- if (isa<AliasSummary>(S)) {
+ if (auto *AS = dyn_cast<AliasSummary>(S)) {
// Will process aliases as a post-pass because the reader wants all
// global to be loaded first.
- Aliases.push_back(FI.get());
+ Aliases.push_back(AS);
continue;
}
@@ -3262,13 +3266,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.push_back(getValueId(RI.getGUID()));
}
- // 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.
- FI->setBitcodeIndex(Stream.GetCurrentBitNo() +
- Stream.GetAbbrevIDWidth());
- // Store temporarily the offset in the map for a possible alias.
- SummaryToOffsetMap[S] = FI->bitcodeIndex();
+ // 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,
@@ -3307,12 +3309,11 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
NameVals.push_back(EI.second.ProfileCount);
}
- // 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.
- FI->setBitcodeIndex(Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth());
- // Store temporarily the offset in the map for a possible alias.
- SummaryToOffsetMap[S] = FI->bitcodeIndex();
+ // 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);
@@ -3326,8 +3327,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
}
}
- for (auto GVI : Aliases) {
- AliasSummary *AS = cast<AliasSummary>(GVI->summary());
+ for (auto *AS : Aliases) {
NameVals.push_back(Index.getModuleId(AS->modulePath()));
NameVals.push_back(getEncodedGVSummaryFlags(AS->flags()));
auto AliaseeOffset = SummaryToOffsetMap[&AS->getAliasee()];
@@ -3337,7 +3337,8 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
// 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.
- GVI->setBitcodeIndex(Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth());
+ SummaryToOffsetMap[AS] =
+ Stream.GetCurrentBitNo() + Stream.GetAbbrevIDWidth();
// Emit the finished record.
Stream.EmitRecord(bitc::FS_COMBINED_ALIAS, NameVals, FSAliasAbbrev);
OpenPOWER on IntegriCloud