Skip to content

Commit 750a583

Browse files
[ThinLTO] Simplify checking for single external copy (NFCI) (#164861)
Replace a loop over all summary copies with a simple check for a single externally available copy of a symbol. The usage of this result has changed since it was added and we now only need to know if there is a single one.
1 parent 0341fb6 commit 750a583

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

llvm/lib/LTO/LTO.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,16 +471,14 @@ static void thinLTOInternalizeAndPromoteGUID(
471471
ValueInfo VI, function_ref<bool(StringRef, ValueInfo)> isExported,
472472
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
473473
isPrevailing) {
474-
auto ExternallyVisibleCopies =
475-
llvm::count_if(VI.getSummaryList(),
476-
[](const std::unique_ptr<GlobalValueSummary> &Summary) {
477-
return !GlobalValue::isLocalLinkage(Summary->linkage());
478-
});
479-
480474
// Before performing index-based internalization and promotion for this GUID,
481475
// the local flag should be consistent with the summary list linkage types.
482476
VI.verifyLocal();
483477

478+
const bool SingleExternallyVisibleCopy =
479+
VI.getSummaryList().size() == 1 &&
480+
!GlobalValue::isLocalLinkage(VI.getSummaryList().front()->linkage());
481+
484482
for (auto &S : VI.getSummaryList()) {
485483
// First see if we need to promote an internal value because it is not
486484
// exported.
@@ -543,7 +541,9 @@ static void thinLTOInternalizeAndPromoteGUID(
543541
GlobalValue::isExternalWeakLinkage(S->linkage()))
544542
continue;
545543

546-
if (isPrevailing(VI.getGUID(), S.get()) && ExternallyVisibleCopies == 1)
544+
// We may have a single summary copy that is externally visible but not
545+
// prevailing if the prevailing copy is in a native object.
546+
if (SingleExternallyVisibleCopy && isPrevailing(VI.getGUID(), S.get()))
547547
S->setLinkage(GlobalValue::InternalLinkage);
548548
}
549549
}

0 commit comments

Comments
 (0)