Skip to content

Commit 44fa6fd

Browse files
committed
[ThinLTO] optimize propagateAttributes performance
ModuleSummaryIndex::propagateAttributes() was observed to take about 25 minutes to complete on a ThinLTO project. Profiling revealed that the majority of this time was spent operating on the MarkedNonReadWriteOnly set. By moving the storage to a per-GlobalValueSummaryInfo basis, the execution time is dramatically reduced to less than 10 seconds.
1 parent 9b060d1 commit 44fa6fd

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ struct alignas(8) GlobalValueSummaryInfo {
165165
/// in the GlobalValueMap. Requires a vector in the case of multiple
166166
/// COMDAT values of the same name.
167167
GlobalValueSummaryList SummaryList;
168+
169+
mutable bool MarkedNonReadWriteOnly = false;
168170
};
169171

170172
/// Map from global value GUID to corresponding summary structures. Use a

llvm/lib/IR/ModuleSummaryIndex.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ bool ModuleSummaryIndex::isGUIDLive(GlobalValue::GUID GUID) const {
199199
return false;
200200
}
201201

202-
static void
203-
propagateAttributesToRefs(GlobalValueSummary *S,
204-
DenseSet<ValueInfo> &MarkedNonReadWriteOnly) {
202+
static void propagateAttributesToRefs(GlobalValueSummary *S) {
205203
// If reference is not readonly or writeonly then referenced summary is not
206204
// read/writeonly either. Note that:
207205
// - All references from GlobalVarSummary are conservatively considered as
@@ -213,9 +211,10 @@ propagateAttributesToRefs(GlobalValueSummary *S,
213211
for (auto &VI : S->refs()) {
214212
assert(VI.getAccessSpecifier() == 0 || isa<FunctionSummary>(S));
215213
if (!VI.getAccessSpecifier()) {
216-
if (!MarkedNonReadWriteOnly.insert(VI).second)
214+
if (VI.getRef()->second.MarkedNonReadWriteOnly)
217215
continue;
218-
} else if (MarkedNonReadWriteOnly.contains(VI))
216+
VI.getRef()->second.MarkedNonReadWriteOnly = true;
217+
} else if (VI.getRef()->second.MarkedNonReadWriteOnly)
219218
continue;
220219
for (auto &Ref : VI.getSummaryList())
221220
// If references to alias is not read/writeonly then aliasee
@@ -260,7 +259,6 @@ void ModuleSummaryIndex::propagateAttributes(
260259
const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
261260
if (!PropagateAttrs)
262261
return;
263-
DenseSet<ValueInfo> MarkedNonReadWriteOnly;
264262
for (auto &P : *this) {
265263
bool IsDSOLocal = true;
266264
for (auto &S : P.second.SummaryList) {
@@ -299,7 +297,7 @@ void ModuleSummaryIndex::propagateAttributes(
299297
GVS->setReadOnly(false);
300298
GVS->setWriteOnly(false);
301299
}
302-
propagateAttributesToRefs(S.get(), MarkedNonReadWriteOnly);
300+
propagateAttributesToRefs(S.get());
303301

304302
// If the flag from any summary is false, the GV is not DSOLocal.
305303
IsDSOLocal &= S->isDSOLocal();

0 commit comments

Comments
 (0)