[llvm] [ThinLTO] Simplify checking for single external copy (NFCI) (PR #164861)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 10:57:14 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: Teresa Johnson (teresajohnson)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/164861.diff
1 Files Affected:
- (modified) llvm/lib/LTO/LTO.cpp (+7-7)
``````````diff
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 9d0fa116c85bf..7e4436a47f70d 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -471,16 +471,14 @@ static void thinLTOInternalizeAndPromoteGUID(
ValueInfo VI, function_ref<bool(StringRef, ValueInfo)> isExported,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
isPrevailing) {
- auto ExternallyVisibleCopies =
- llvm::count_if(VI.getSummaryList(),
- [](const std::unique_ptr<GlobalValueSummary> &Summary) {
- return !GlobalValue::isLocalLinkage(Summary->linkage());
- });
-
// Before performing index-based internalization and promotion for this GUID,
// the local flag should be consistent with the summary list linkage types.
VI.verifyLocal();
+ bool SingleExternallyVisibleCopy =
+ VI.getSummaryList().size() == 1 &&
+ !GlobalValue::isLocalLinkage(VI.getSummaryList().front()->linkage());
+
for (auto &S : VI.getSummaryList()) {
// First see if we need to promote an internal value because it is not
// exported.
@@ -543,7 +541,9 @@ static void thinLTOInternalizeAndPromoteGUID(
GlobalValue::isExternalWeakLinkage(S->linkage()))
continue;
- if (isPrevailing(VI.getGUID(), S.get()) && ExternallyVisibleCopies == 1)
+ // We may have a single summary copy that is externally visible but not
+ // prevailing if the prevailing copy is in a native object.
+ if (SingleExternallyVisibleCopy && isPrevailing(VI.getGUID(), S.get()))
S->setLinkage(GlobalValue::InternalLinkage);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/164861
More information about the llvm-commits
mailing list