summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/ModuleSummaryAnalysis.cpp19
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp84
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp77
-rw-r--r--llvm/lib/IR/ModuleSummaryIndex.cpp59
-rw-r--r--llvm/lib/LTO/ThinLTOCodeGenerator.cpp24
-rw-r--r--llvm/lib/Transforms/IPO/FunctionImport.cpp61
6 files changed, 150 insertions, 174 deletions
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index d0731eda73d..ed1b57124b6 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -61,8 +61,8 @@ static void findRefEdges(const User *CurUser, DenseSet<const Value *> &RefEdges,
}
}
-void ModuleSummaryIndexBuilder::computeFunctionInfo(const Function &F,
- BlockFrequencyInfo *BFI) {
+void ModuleSummaryIndexBuilder::computeFunctionSummary(
+ const Function &F, BlockFrequencyInfo *BFI) {
// Summary not currently supported for anonymous functions, they must
// be renamed.
if (!F.hasName())
@@ -100,12 +100,11 @@ void ModuleSummaryIndexBuilder::computeFunctionInfo(const Function &F,
llvm::make_unique<FunctionSummary>(Flags, NumInsts);
FuncSummary->addCallGraphEdges(CallGraphEdges);
FuncSummary->addRefEdges(RefEdges);
- std::unique_ptr<GlobalValueInfo> GVInfo =
- llvm::make_unique<GlobalValueInfo>(0, std::move(FuncSummary));
- Index->addGlobalValueInfo(F.getName(), std::move(GVInfo));
+ Index->addGlobalValueSummary(F.getName(), std::move(FuncSummary));
}
-void ModuleSummaryIndexBuilder::computeVariableInfo(const GlobalVariable &V) {
+void ModuleSummaryIndexBuilder::computeVariableSummary(
+ const GlobalVariable &V) {
DenseSet<const Value *> RefEdges;
SmallPtrSet<const User *, 8> Visited;
findRefEdges(&V, RefEdges, Visited);
@@ -113,9 +112,7 @@ void ModuleSummaryIndexBuilder::computeVariableInfo(const GlobalVariable &V) {
std::unique_ptr<GlobalVarSummary> GVarSummary =
llvm::make_unique<GlobalVarSummary>(Flags);
GVarSummary->addRefEdges(RefEdges);
- std::unique_ptr<GlobalValueInfo> GVInfo =
- llvm::make_unique<GlobalValueInfo>(0, std::move(GVarSummary));
- Index->addGlobalValueInfo(V.getName(), std::move(GVInfo));
+ Index->addGlobalValueSummary(V.getName(), std::move(GVarSummary));
}
ModuleSummaryIndexBuilder::ModuleSummaryIndexBuilder(
@@ -164,7 +161,7 @@ ModuleSummaryIndexBuilder::ModuleSummaryIndexBuilder(
BFI = BFIPtr.get();
}
- computeFunctionInfo(F, BFI);
+ computeFunctionSummary(F, BFI);
}
// Compute summaries for all variables defined in module, and save in the
@@ -172,7 +169,7 @@ ModuleSummaryIndexBuilder::ModuleSummaryIndexBuilder(
for (const GlobalVariable &G : M->globals()) {
if (G.isDeclaration())
continue;
- computeVariableInfo(G);
+ computeVariableSummary(G);
}
}
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);
diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp
index 8ca5e27ea21..4c122c7241e 100644
--- a/llvm/lib/IR/ModuleSummaryIndex.cpp
+++ b/llvm/lib/IR/ModuleSummaryIndex.cpp
@@ -22,38 +22,34 @@ void ModuleSummaryIndex::mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other,
uint64_t NextModuleId) {
StringRef ModPath;
- for (auto &OtherGlobalValInfoLists : *Other) {
- GlobalValue::GUID ValueGUID = OtherGlobalValInfoLists.first;
- GlobalValueInfoList &List = OtherGlobalValInfoLists.second;
+ for (auto &OtherGlobalValSummaryLists : *Other) {
+ GlobalValue::GUID ValueGUID = OtherGlobalValSummaryLists.first;
+ GlobalValueSummaryList &List = OtherGlobalValSummaryLists.second;
- // Assert that the value info list only has one entry, since we shouldn't
+ // Assert that the value summary list only has one entry, since we shouldn't
// have duplicate names within a single per-module index.
assert(List.size() == 1);
- std::unique_ptr<GlobalValueInfo> Info = std::move(List.front());
-
- // Skip if there was no summary section.
- if (!Info->summary())
- continue;
+ std::unique_ptr<GlobalValueSummary> Summary = std::move(List.front());
// Add the module path string ref for this module if we haven't already
// saved a reference to it.
if (ModPath.empty()) {
- auto Path = Info->summary()->modulePath();
+ auto Path = Summary->modulePath();
ModPath = addModulePath(Path, NextModuleId, Other->getModuleHash(Path))
->first();
} else
- assert(ModPath == Info->summary()->modulePath() &&
+ assert(ModPath == Summary->modulePath() &&
"Each module in the combined map should have a unique ID");
// Note the module path string ref was copied above and is still owned by
// the original per-module index. Reset it to the new module path
// string reference owned by the combined index.
- Info->summary()->setModulePath(ModPath);
+ Summary->setModulePath(ModPath);
- // Add new value info to existing list. There may be duplicates when
+ // Add new value summary to existing list. There may be duplicates when
// combining GlobalValueMap entries, due to COMDAT values. Any local
// values were given unique global IDs.
- addGlobalValueInfo(ValueGUID, std::move(Info));
+ addGlobalValueSummary(ValueGUID, std::move(Summary));
}
}
@@ -62,7 +58,7 @@ void ModuleSummaryIndex::removeEmptySummaryEntries() {
// Only expect this to be called on a per-module index, which has a single
// entry per value entry list.
assert(MI->second.size() == 1);
- if (!MI->second[0]->summary())
+ if (!MI->second[0])
MI = GlobalValueMap.erase(MI);
else
++MI;
@@ -73,42 +69,41 @@ void ModuleSummaryIndex::removeEmptySummaryEntries() {
// (GUID -> Summary).
void ModuleSummaryIndex::collectDefinedFunctionsForModule(
StringRef ModulePath,
- std::map<GlobalValue::GUID, GlobalValueSummary *> &FunctionInfoMap) const {
+ std::map<GlobalValue::GUID, GlobalValueSummary *> &GVSummaryMap) const {
for (auto &GlobalList : *this) {
auto GUID = GlobalList.first;
- for (auto &GlobInfo : GlobalList.second) {
- auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobInfo->summary());
+ for (auto &GlobSummary : GlobalList.second) {
+ auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
if (!Summary)
// Ignore global variable, focus on functions
continue;
// Ignore summaries from other modules.
if (Summary->modulePath() != ModulePath)
continue;
- FunctionInfoMap[GUID] = Summary;
+ GVSummaryMap[GUID] = Summary;
}
}
}
// Collect for each module the list of function it defines (GUID -> Summary).
void ModuleSummaryIndex::collectDefinedGVSummariesPerModule(
- StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>> &
- Module2FunctionInfoMap) const {
+ StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>>
+ &ModuleToDefinedGVSummaries) const {
for (auto &GlobalList : *this) {
auto GUID = GlobalList.first;
- for (auto &GlobInfo : GlobalList.second) {
- auto *Summary = GlobInfo->summary();
- Module2FunctionInfoMap[Summary->modulePath()][GUID] = Summary;
+ for (auto &Summary : GlobalList.second) {
+ ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
}
}
}
-GlobalValueInfo *
-ModuleSummaryIndex::getGlobalValueInfo(uint64_t ValueGUID,
- bool PerModuleIndex) const {
- auto InfoList = findGlobalValueInfoList(ValueGUID);
- assert(InfoList != end() && "GlobalValue not found in index");
- assert((!PerModuleIndex || InfoList->second.size() == 1) &&
+GlobalValueSummary *
+ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID,
+ bool PerModuleIndex) const {
+ auto SummaryList = findGlobalValueSummaryList(ValueGUID);
+ assert(SummaryList != end() && "GlobalValue not found in index");
+ assert((!PerModuleIndex || SummaryList->second.size() == 1) &&
"Expected a single entry per global value in per-module index");
- auto &Info = InfoList->second[0];
- return Info.get();
+ auto &Summary = SummaryList->second[0];
+ return Summary.get();
}
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 9fef1326610..21ba1e92a3a 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -109,23 +109,24 @@ static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
WriteBitcodeToFile(&TheModule, OS, /* ShouldPreserveUseListOrder */ true);
}
-bool IsFirstDefinitionForLinker(const GlobalValueInfoList &GVInfo,
+bool IsFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList,
const ModuleSummaryIndex &Index,
StringRef ModulePath) {
// Get the first *linker visible* definition for this global in the summary
// list.
auto FirstDefForLinker = llvm::find_if(
- GVInfo, [](const std::unique_ptr<GlobalValueInfo> &FuncInfo) {
- auto Linkage = FuncInfo->summary()->linkage();
+ GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
+ auto Linkage = Summary->linkage();
return !GlobalValue::isAvailableExternallyLinkage(Linkage);
});
// If \p GV is not the first definition, give up...
- if ((*FirstDefForLinker)->summary()->modulePath() != ModulePath)
+ if ((*FirstDefForLinker)->modulePath() != ModulePath)
return false;
// If there is any strong definition anywhere, do not bother emitting this.
if (llvm::any_of(
- GVInfo, [](const std::unique_ptr<GlobalValueInfo> &FuncInfo) {
- auto Linkage = FuncInfo->summary()->linkage();
+ GVSummaryList,
+ [](const std::unique_ptr<GlobalValueSummary> &Summary) {
+ auto Linkage = Summary->linkage();
return !GlobalValue::isAvailableExternallyLinkage(Linkage) &&
!GlobalValue::isWeakForLinker(Linkage);
}))
@@ -138,8 +139,9 @@ ResolveODR(const ModuleSummaryIndex &Index,
const FunctionImporter::ExportSetTy &ExportList,
StringRef ModuleIdentifier, GlobalValue::GUID GUID,
const GlobalValueSummary &GV) {
- auto HasMultipleCopies =
- [&](const GlobalValueInfoList &GVInfo) { return GVInfo.size() > 1; };
+ auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
+ return GVSummaryList.size() > 1;
+ };
auto OriginalLinkage = GV.linkage();
switch (OriginalLinkage) {
@@ -155,17 +157,17 @@ ResolveODR(const ModuleSummaryIndex &Index,
break;
case GlobalValue::LinkOnceODRLinkage:
case GlobalValue::WeakODRLinkage: {
- auto &GVInfo = Index.findGlobalValueInfoList(GUID)->second;
+ auto &GVSummaryList = Index.findGlobalValueSummaryList(GUID)->second;
// We need to emit only one of these, the first module will keep
// it, but turned into a weak while the others will drop it.
- if (!HasMultipleCopies(GVInfo)) {
+ if (!HasMultipleCopies(GVSummaryList)) {
// Exported LinkonceODR needs to be promoted to not be discarded
if (GlobalValue::isDiscardableIfUnused(OriginalLinkage) &&
ExportList.count(GUID))
return GlobalValue::WeakODRLinkage;
break;
}
- if (IsFirstDefinitionForLinker(GVInfo, Index, ModuleIdentifier))
+ if (IsFirstDefinitionForLinker(GVSummaryList, Index, ModuleIdentifier))
return GlobalValue::WeakODRLinkage;
else if (isa<AliasSummary>(&GV))
// Alias can't be turned into available_externally.
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp
index 15d55a14621..b6c8993a6f0 100644
--- a/llvm/lib/Transforms/IPO/FunctionImport.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp
@@ -86,12 +86,12 @@ namespace {
/// - One that has PGO data attached.
/// - [insert you fancy metric here]
static const GlobalValueSummary *
-selectCallee(const GlobalValueInfoList &CalleeInfoList, unsigned Threshold) {
+selectCallee(const GlobalValueSummaryList &CalleeSummaryList,
+ unsigned Threshold) {
auto It = llvm::find_if(
- CalleeInfoList, [&](const std::unique_ptr<GlobalValueInfo> &GlobInfo) {
- assert(GlobInfo->summary() &&
- "We should not have a Global Info without summary");
- auto *GVSummary = GlobInfo->summary();
+ CalleeSummaryList,
+ [&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) {
+ auto *GVSummary = SummaryPtr.get();
if (GlobalValue::isWeakAnyLinkage(GVSummary->linkage()))
// There is no point in importing weak symbols, we can't inline them
return false;
@@ -113,10 +113,10 @@ selectCallee(const GlobalValueInfoList &CalleeInfoList, unsigned Threshold) {
return true;
});
- if (It == CalleeInfoList.end())
+ if (It == CalleeSummaryList.end())
return nullptr;
- return cast<GlobalValueSummary>((*It)->summary());
+ return cast<GlobalValueSummary>(It->get());
}
/// Return the summary for the function \p GUID that fits the \p Threshold, or
@@ -124,11 +124,11 @@ selectCallee(const GlobalValueInfoList &CalleeInfoList, unsigned Threshold) {
static const GlobalValueSummary *selectCallee(GlobalValue::GUID GUID,
unsigned Threshold,
const ModuleSummaryIndex &Index) {
- auto CalleeInfoList = Index.findGlobalValueInfoList(GUID);
- if (CalleeInfoList == Index.end()) {
+ auto CalleeSummaryList = Index.findGlobalValueSummaryList(GUID);
+ if (CalleeSummaryList == Index.end()) {
return nullptr; // This function does not have a summary
}
- return selectCallee(CalleeInfoList->second, Threshold);
+ return selectCallee(CalleeSummaryList->second, Threshold);
}
/// Mark the global \p GUID as export by module \p ExportModulePath if found in
@@ -138,32 +138,29 @@ static void exportGlobalInModule(const ModuleSummaryIndex &Index,
StringRef ExportModulePath,
GlobalValue::GUID GUID,
FunctionImporter::ExportSetTy &ExportList) {
- auto FindGlobalInfoInModule =
- [&](GlobalValue::GUID GUID) -> GlobalValueInfo *{
- auto InfoList = Index.findGlobalValueInfoList(GUID);
- if (InfoList == Index.end())
+ auto FindGlobalSummaryInModule =
+ [&](GlobalValue::GUID GUID) -> GlobalValueSummary *{
+ auto SummaryList = Index.findGlobalValueSummaryList(GUID);
+ if (SummaryList == Index.end())
// This global does not have a summary, it is not part of the ThinLTO
// process
return nullptr;
- auto Info = llvm::find_if(
- InfoList->second,
- [&](const std::unique_ptr<GlobalValueInfo> &GlobInfo) {
- auto *Summary = GlobInfo->summary();
- assert(Summary && "Unexpected GlobalValueInfo without summary");
+ auto SummaryIter = llvm::find_if(
+ SummaryList->second,
+ [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
return Summary->modulePath() == ExportModulePath;
});
- if (Info == InfoList->second.end())
+ if (SummaryIter == SummaryList->second.end())
return nullptr;
- return Info->get();
+ return SummaryIter->get();
};
- auto *GVInfo = FindGlobalInfoInModule(GUID);
- if (!GVInfo)
+ auto *Summary = FindGlobalSummaryInModule(GUID);
+ if (!Summary)
return;
// We found it in the current module, mark as exported
ExportList.insert(GUID);
- auto *Summary = GVInfo->summary();
auto GVS = dyn_cast<GlobalVarSummary>(Summary);
if (!GVS)
return;
@@ -174,8 +171,8 @@ static void exportGlobalInModule(const ModuleSummaryIndex &Index,
// FIXME: with a "isConstant" flag in the summary we could be more targetted.
for (auto &Ref : GVS->refs()) {
auto GUID = Ref.getGUID();
- auto *RefInfo = FindGlobalInfoInModule(GUID);
- if (RefInfo)
+ auto *RefSummary = FindGlobalSummaryInModule(GUID);
+ if (RefSummary)
// Found a ref in the current module, mark it as exported
ExportList.insert(GUID);
}
@@ -269,15 +266,15 @@ static void ComputeImportForModule(
// Populate the worklist with the import for the functions in the current
// module
- for (auto &GVInfo : DefinedGVSummaries) {
- auto *Summary = GVInfo.second;
+ for (auto &GVSummary : DefinedGVSummaries) {
+ auto *Summary = GVSummary.second;
if (auto *AS = dyn_cast<AliasSummary>(Summary))
Summary = &AS->getAliasee();
auto *FuncSummary = dyn_cast<FunctionSummary>(Summary);
if (!FuncSummary)
// Skip import for global variables
continue;
- DEBUG(dbgs() << "Initalize import for " << GVInfo.first << "\n");
+ DEBUG(dbgs() << "Initalize import for " << GVSummary.first << "\n");
computeImportForFunction(*FuncSummary, Index, ImportInstrLimit,
DefinedGVSummaries, Worklist, ImportsForModule,
ExportLists);
@@ -340,12 +337,12 @@ void llvm::ComputeCrossModuleImportForModule(
// Collect the list of functions this module defines.
// GUID -> Summary
- std::map<GlobalValue::GUID, GlobalValueSummary *> FunctionInfoMap;
- Index.collectDefinedFunctionsForModule(ModulePath, FunctionInfoMap);
+ std::map<GlobalValue::GUID, GlobalValueSummary *> FunctionSummaryMap;
+ Index.collectDefinedFunctionsForModule(ModulePath, FunctionSummaryMap);
// Compute the import list for this module.
DEBUG(dbgs() << "Computing import for Module '" << ModulePath << "'\n");
- ComputeImportForModule(FunctionInfoMap, Index, ImportList);
+ ComputeImportForModule(FunctionSummaryMap, Index, ImportList);
#ifndef NDEBUG
DEBUG(dbgs() << "* Module " << ModulePath << " imports from "
OpenPOWER on IntegriCloud