-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[ThinLTO] Simplify checking for single external copy (NFCI) #164861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ThinLTO] Simplify checking for single external copy (NFCI) #164861
Conversation
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.
|
@llvm/pr-subscribers-lto Author: Teresa Johnson (teresajohnson) ChangesReplace a loop over all summary copies with a simple check for a single Full diff: https://github.com/llvm/llvm-project/pull/164861.diff 1 Files Affected:
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);
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM since compiler won't internalize more by reading the diff itself.
If I understand correctly, the surrounding code and comment explains why ExternallyVisibleCopies before and SingleExternallyVisibleCopy are equivalent, and this change won't cause compiler to internalize less, most notably
llvm-project/llvm/lib/LTO/LTO.cpp
Lines 512 to 518 in ad75b3b
// However, we only get to this code for weak-for-linkage values in one of // two cases: // 1) The prevailing copy is not in IR (it is in native code). // 2) The prevailing copy in IR is not exported from its module. // Additionally, at least for the new LTO API, case 2 will only happen if // there is exactly one definition of the value (i.e. in exactly one // module), as duplicate defs are result in the value being marked exported. llvm-project/llvm/lib/LTO/LTO.cpp
Lines 538 to 544 in ad75b3b
// Therefore, only internalize linkonce/weak if there is a single copy, that // is prevailing in this IR module. We can do so aggressively, without // requiring the address to be insignificant, or that a variable be read or // write-only. if (!GlobalValue::isWeakForLinker(S->linkage()) || GlobalValue::isExternalWeakLinkage(S->linkage())) continue;
llvm/lib/LTO/LTO.cpp
Outdated
| // the local flag should be consistent with the summary list linkage types. | ||
| VI.verifyLocal(); | ||
|
|
||
| bool SingleExternallyVisibleCopy = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional suggestion: make this const bool so it's clearer it doesn't get modified later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/32102 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/22206 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/4/builds/9973 Here is the relevant piece of the build log for the reference |
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.