Skip to content

Commit 683e2bf

Browse files
[ThinLTO] Make SummaryList private (NFC) (llvm#164355)
In preparation for a follow on change that will require checking every time a new summary is added to the SummaryList for a GUID, make the SummaryList private and require all accesses to go through one of two new interfaces. Most changes are to access the list via the read only getSummaryList() method, and the few that add new summaries (e.g. while building the combined summary) use the new addSummary() method.
1 parent 83927a6 commit 683e2bf

File tree

15 files changed

+65
-49
lines changed

15 files changed

+65
-49
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,24 @@ struct alignas(8) GlobalValueSummaryInfo {
164164

165165
inline GlobalValueSummaryInfo(bool HaveGVs);
166166

167+
/// Access a read-only list of global value summary structures for a
168+
/// particular value held in the GlobalValueMap.
169+
ArrayRef<std::unique_ptr<GlobalValueSummary>> getSummaryList() const {
170+
return SummaryList;
171+
}
172+
173+
/// Add a summary corresponding to a global value definition in a module with
174+
/// the corresponding GUID.
175+
void addSummary(std::unique_ptr<GlobalValueSummary> Summary) {
176+
return SummaryList.push_back(std::move(Summary));
177+
}
178+
179+
private:
167180
/// List of global value summary structures for a particular value held
168181
/// in the GlobalValueMap. Requires a vector in the case of multiple
169-
/// COMDAT values of the same name.
182+
/// COMDAT values of the same name, weak symbols, locals of the same name when
183+
/// compiling without sufficient distinguishing path, or (theoretically) hash
184+
/// collisions. Each summary is from a different module.
170185
GlobalValueSummaryList SummaryList;
171186
};
172187

@@ -201,7 +216,7 @@ struct ValueInfo {
201216
}
202217

203218
ArrayRef<std::unique_ptr<GlobalValueSummary>> getSummaryList() const {
204-
return getRef()->second.SummaryList;
219+
return getRef()->second.getSummaryList();
205220
}
206221

207222
// Even if the index is built with GVs available, we may not have one for
@@ -1607,8 +1622,8 @@ class ModuleSummaryIndex {
16071622

16081623
for (auto &S : *this) {
16091624
// Skip external functions
1610-
if (!S.second.SummaryList.size() ||
1611-
!isa<FunctionSummary>(S.second.SummaryList.front().get()))
1625+
if (!S.second.getSummaryList().size() ||
1626+
!isa<FunctionSummary>(S.second.getSummaryList().front().get()))
16121627
continue;
16131628
discoverNodes(ValueInfo(HaveGVs, &S), FunctionHasParent);
16141629
}
@@ -1748,7 +1763,7 @@ class ModuleSummaryIndex {
17481763
// Here we have a notionally const VI, but the value it points to is owned
17491764
// by the non-const *this.
17501765
const_cast<GlobalValueSummaryMapTy::value_type *>(VI.getRef())
1751-
->second.SummaryList.push_back(std::move(Summary));
1766+
->second.addSummary(std::move(Summary));
17521767
}
17531768

17541769
/// Add an original name for the value of the given GUID.
@@ -1937,7 +1952,7 @@ class ModuleSummaryIndex {
19371952
collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const {
19381953
for (const auto &GlobalList : *this) {
19391954
auto GUID = GlobalList.first;
1940-
for (const auto &Summary : GlobalList.second.SummaryList) {
1955+
for (const auto &Summary : GlobalList.second.getSummaryList()) {
19411956
ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
19421957
}
19431958
}
@@ -2035,7 +2050,7 @@ struct GraphTraits<ModuleSummaryIndex *> : public GraphTraits<ValueInfo> {
20352050
std::unique_ptr<GlobalValueSummary> Root =
20362051
std::make_unique<FunctionSummary>(I->calculateCallGraphRoot());
20372052
GlobalValueSummaryInfo G(I->haveGVs());
2038-
G.SummaryList.push_back(std::move(Root));
2053+
G.addSummary(std::move(Root));
20392054
static auto P =
20402055
GlobalValueSummaryMapTy::value_type(GlobalValue::GUID(0), std::move(G));
20412056
return ValueInfo(I->haveGVs(), &P);

llvm/include/llvm/IR/ModuleSummaryIndexYAML.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
237237
// This is done in fixAliaseeLinks() which is called in
238238
// MappingTraits<ModuleSummaryIndex>::mapping().
239239
ASum->setAliasee(AliaseeVI, /*Aliasee=*/nullptr);
240-
Elem.SummaryList.push_back(std::move(ASum));
240+
Elem.addSummary(std::move(ASum));
241241
continue;
242242
}
243243
SmallVector<ValueInfo, 0> Refs;
@@ -246,7 +246,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
246246
auto It = V.try_emplace(RefGUID, /*IsAnalysis=*/false).first;
247247
Refs.push_back(ValueInfo(/*IsAnalysis=*/false, &*It));
248248
}
249-
Elem.SummaryList.push_back(std::make_unique<FunctionSummary>(
249+
Elem.addSummary(std::make_unique<FunctionSummary>(
250250
GVFlags, /*NumInsts=*/0, FunctionSummary::FFlags{}, std::move(Refs),
251251
SmallVector<FunctionSummary::EdgeTy, 0>{}, std::move(GVSum.TypeTests),
252252
std::move(GVSum.TypeTestAssumeVCalls),
@@ -260,7 +260,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
260260
static void output(IO &io, GlobalValueSummaryMapTy &V) {
261261
for (auto &P : V) {
262262
std::vector<GlobalValueSummaryYaml> GVSums;
263-
for (auto &Sum : P.second.SummaryList) {
263+
for (auto &Sum : P.second.getSummaryList()) {
264264
if (auto *FSum = dyn_cast<FunctionSummary>(Sum.get())) {
265265
std::vector<uint64_t> Refs;
266266
Refs.reserve(FSum->refs().size());
@@ -295,7 +295,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
295295
}
296296
static void fixAliaseeLinks(GlobalValueSummaryMapTy &V) {
297297
for (auto &P : V) {
298-
for (auto &Sum : P.second.SummaryList) {
298+
for (auto &Sum : P.second.getSummaryList()) {
299299
if (auto *Alias = dyn_cast<AliasSummary>(Sum.get())) {
300300
ValueInfo AliaseeVI = Alias->getAliaseeVI();
301301
auto AliaseeSL = AliaseeVI.getSummaryList();

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,12 +1100,12 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
11001100

11011101
for (auto &GlobalList : Index) {
11021102
// Ignore entries for references that are undefined in the current module.
1103-
if (GlobalList.second.SummaryList.empty())
1103+
if (GlobalList.second.getSummaryList().empty())
11041104
continue;
11051105

1106-
assert(GlobalList.second.SummaryList.size() == 1 &&
1106+
assert(GlobalList.second.getSummaryList().size() == 1 &&
11071107
"Expected module's index to have one summary per GUID");
1108-
auto &Summary = GlobalList.second.SummaryList[0];
1108+
auto &Summary = GlobalList.second.getSummaryList()[0];
11091109
if (!IsThinLTO) {
11101110
Summary->setNotEligibleToImport();
11111111
continue;

llvm/lib/Analysis/StackSafetyAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ void llvm::generateParamAccessSummary(ModuleSummaryIndex &Index) {
11361136
if (!AreStatisticsEnabled())
11371137
return;
11381138
for (auto &GVS : Index)
1139-
for (auto &GV : GVS.second.SummaryList)
1139+
for (auto &GV : GVS.second.getSummaryList())
11401140
if (FunctionSummary *FS = dyn_cast<FunctionSummary>(GV.get()))
11411141
Stat += FS->paramAccesses().size();
11421142
};
@@ -1147,7 +1147,7 @@ void llvm::generateParamAccessSummary(ModuleSummaryIndex &Index) {
11471147

11481148
// Convert the ModuleSummaryIndex to a FunctionMap
11491149
for (auto &GVS : Index) {
1150-
for (auto &GV : GVS.second.SummaryList) {
1150+
for (auto &GV : GVS.second.getSummaryList()) {
11511151
FunctionSummary *FS = dyn_cast<FunctionSummary>(GV.get());
11521152
if (!FS || FS->paramAccesses().empty())
11531153
continue;

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class ModuleBitcodeWriterBase : public BitcodeWriterBase {
235235
return;
236236
for (const auto &GUIDSummaryLists : *Index)
237237
// Examine all summaries for this GUID.
238-
for (auto &Summary : GUIDSummaryLists.second.SummaryList)
238+
for (auto &Summary : GUIDSummaryLists.second.getSummaryList())
239239
if (auto FS = dyn_cast<FunctionSummary>(Summary.get())) {
240240
// For each call in the function summary, see if the call
241241
// is to a GUID (which means it is for an indirect call,
@@ -587,7 +587,7 @@ class IndexBitcodeWriter : public BitcodeWriterBase {
587587
}
588588
} else {
589589
for (auto &Summaries : Index)
590-
for (auto &Summary : Summaries.second.SummaryList)
590+
for (auto &Summary : Summaries.second.getSummaryList())
591591
Callback({Summaries.first, Summary.get()}, false);
592592
}
593593
}

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3196,7 +3196,7 @@ void AssemblyWriter::printModuleSummaryIndex() {
31963196
// for aliasee (then update BitcodeWriter.cpp and remove get/setAliaseeGUID).
31973197
for (auto &GlobalList : *TheIndex) {
31983198
auto GUID = GlobalList.first;
3199-
for (auto &Summary : GlobalList.second.SummaryList)
3199+
for (auto &Summary : GlobalList.second.getSummaryList())
32003200
SummaryToGUIDMap[Summary.get()] = GUID;
32013201
}
32023202

llvm/lib/IR/ModuleSummaryIndex.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void ModuleSummaryIndex::collectDefinedFunctionsForModule(
162162
StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
163163
for (auto &GlobalList : *this) {
164164
auto GUID = GlobalList.first;
165-
for (auto &GlobSummary : GlobalList.second.SummaryList) {
165+
for (auto &GlobSummary : GlobalList.second.getSummaryList()) {
166166
auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
167167
if (!Summary)
168168
// Ignore global variable, focus on functions
@@ -263,7 +263,7 @@ void ModuleSummaryIndex::propagateAttributes(
263263
DenseSet<ValueInfo> MarkedNonReadWriteOnly;
264264
for (auto &P : *this) {
265265
bool IsDSOLocal = true;
266-
for (auto &S : P.second.SummaryList) {
266+
for (auto &S : P.second.getSummaryList()) {
267267
if (!isGlobalValueLive(S.get())) {
268268
// computeDeadSymbolsAndUpdateIndirectCalls should have marked all
269269
// copies live. Note that it is possible that there is a GUID collision
@@ -273,7 +273,7 @@ void ModuleSummaryIndex::propagateAttributes(
273273
// all copies live we can assert here that all are dead if any copy is
274274
// dead.
275275
assert(llvm::none_of(
276-
P.second.SummaryList,
276+
P.second.getSummaryList(),
277277
[&](const std::unique_ptr<GlobalValueSummary> &Summary) {
278278
return isGlobalValueLive(Summary.get());
279279
}));
@@ -308,16 +308,16 @@ void ModuleSummaryIndex::propagateAttributes(
308308
// Mark the flag in all summaries false so that we can do quick check
309309
// without going through the whole list.
310310
for (const std::unique_ptr<GlobalValueSummary> &Summary :
311-
P.second.SummaryList)
311+
P.second.getSummaryList())
312312
Summary->setDSOLocal(false);
313313
}
314314
setWithAttributePropagation();
315315
setWithDSOLocalPropagation();
316316
if (llvm::AreStatisticsEnabled())
317317
for (auto &P : *this)
318-
if (P.second.SummaryList.size())
318+
if (P.second.getSummaryList().size())
319319
if (auto *GVS = dyn_cast<GlobalVarSummary>(
320-
P.second.SummaryList[0]->getBaseObject()))
320+
P.second.getSummaryList()[0]->getBaseObject()))
321321
if (isGlobalValueLive(GVS)) {
322322
if (GVS->maybeReadOnly())
323323
ReadOnlyLiveGVars++;

llvm/lib/LTO/LTO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void llvm::thinLTOResolvePrevailingInIndex(
457457
// when needed.
458458
DenseSet<GlobalValueSummary *> GlobalInvolvedWithAlias;
459459
for (auto &I : Index)
460-
for (auto &S : I.second.SummaryList)
460+
for (auto &S : I.second.getSummaryList())
461461
if (auto AS = dyn_cast<AliasSummary>(S.get()))
462462
GlobalInvolvedWithAlias.insert(&AS->getAliasee());
463463

@@ -1182,7 +1182,7 @@ Error LTO::checkPartiallySplit() {
11821182
// Otherwise check if there are any recorded in the combined summary from the
11831183
// ThinLTO modules.
11841184
for (auto &P : ThinLTO.CombinedIndex) {
1185-
for (auto &S : P.second.SummaryList) {
1185+
for (auto &S : P.second.getSummaryList()) {
11861186
auto *FS = dyn_cast<FunctionSummary>(S.get());
11871187
if (!FS)
11881188
continue;

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,11 @@ bool lto::initImportList(const Module &M,
770770
// via a WriteIndexesThinBackend.
771771
for (const auto &GlobalList : CombinedIndex) {
772772
// Ignore entries for undefined references.
773-
if (GlobalList.second.SummaryList.empty())
773+
if (GlobalList.second.getSummaryList().empty())
774774
continue;
775775

776776
auto GUID = GlobalList.first;
777-
for (const auto &Summary : GlobalList.second.SummaryList) {
777+
for (const auto &Summary : GlobalList.second.getSummaryList()) {
778778
// Skip the summaries for the importing module. These are included to
779779
// e.g. record required linkage changes.
780780
if (Summary->modulePath() == M.getModuleIdentifier())

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ static void saveTempBitcode(const Module &TheModule, StringRef TempDir,
101101
WriteBitcodeToFile(TheModule, OS, /* ShouldPreserveUseListOrder */ true);
102102
}
103103

104-
static const GlobalValueSummary *
105-
getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
104+
static const GlobalValueSummary *getFirstDefinitionForLinker(
105+
ArrayRef<std::unique_ptr<GlobalValueSummary>> GVSummaryList) {
106106
// If there is any strong definition anywhere, get it.
107107
auto StrongDefForLinker = llvm::find_if(
108108
GVSummaryList, [](const std::unique_ptr<GlobalValueSummary> &Summary) {
@@ -131,14 +131,15 @@ getFirstDefinitionForLinker(const GlobalValueSummaryList &GVSummaryList) {
131131
static void computePrevailingCopies(
132132
const ModuleSummaryIndex &Index,
133133
DenseMap<GlobalValue::GUID, const GlobalValueSummary *> &PrevailingCopy) {
134-
auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
135-
return GVSummaryList.size() > 1;
136-
};
134+
auto HasMultipleCopies =
135+
[&](ArrayRef<std::unique_ptr<GlobalValueSummary>> GVSummaryList) {
136+
return GVSummaryList.size() > 1;
137+
};
137138

138139
for (auto &I : Index) {
139-
if (HasMultipleCopies(I.second.SummaryList))
140+
if (HasMultipleCopies(I.second.getSummaryList()))
140141
PrevailingCopy[I.first] =
141-
getFirstDefinitionForLinker(I.second.SummaryList);
142+
getFirstDefinitionForLinker(I.second.getSummaryList());
142143
}
143144
}
144145

0 commit comments

Comments
 (0)