aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/LTO/LTO.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2023-06-01 08:57:35 -0700
committerTeresa Johnson <tejohnson@google.com>2023-06-01 09:08:43 -0700
commit06bb94832d0d9c23b9b4c735007700057aecb93b (patch)
tree865f38c71038e766740509699321ac5b16e915dd /llvm/lib/LTO/LTO.cpp
parent0b8c8bc87404d324120a88e08ee97cdd0f711b31 (diff)
downloadllvm-06bb94832d0d9c23b9b4c735007700057aecb93b.zip
llvm-06bb94832d0d9c23b9b4c735007700057aecb93b.tar.gz
llvm-06bb94832d0d9c23b9b4c735007700057aecb93b.tar.bz2
[ThinLTO] Restructure promotion / internalization decisions (NFC)
Restructures the combined index based promotion and internalization decision code so that it is a bit easier to follow. This is in preparation for a bugfix to this code that will modify one part of the logic.
Diffstat (limited to 'llvm/lib/LTO/LTO.cpp')
-rw-r--r--llvm/lib/LTO/LTO.cpp63
1 files changed, 38 insertions, 25 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 2f52a20..fa3e060 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -446,39 +446,52 @@ void llvm::thinLTOResolvePrevailingInIndex(
recordNewLinkage, GUIDPreservedSymbols);
}
-static bool isWeakObjectWithRWAccess(GlobalValueSummary *GVS) {
- if (auto *VarSummary = dyn_cast<GlobalVarSummary>(GVS->getBaseObject()))
- return !VarSummary->maybeReadOnly() && !VarSummary->maybeWriteOnly() &&
- (VarSummary->linkage() == GlobalValue::WeakODRLinkage ||
- VarSummary->linkage() == GlobalValue::LinkOnceODRLinkage);
- return false;
-}
-
static void thinLTOInternalizeAndPromoteGUID(
ValueInfo VI, function_ref<bool(StringRef, ValueInfo)> isExported,
function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
isPrevailing) {
for (auto &S : VI.getSummaryList()) {
+ // First see if we need to promote an internal value because it is not
+ // exported.
if (isExported(S->modulePath(), VI)) {
if (GlobalValue::isLocalLinkage(S->linkage()))
S->setLinkage(GlobalValue::ExternalLinkage);
- } else if (EnableLTOInternalization &&
- // Ignore local and appending linkage values since the linker
- // doesn't resolve them.
- !GlobalValue::isLocalLinkage(S->linkage()) &&
- (!GlobalValue::isInterposableLinkage(S->linkage()) ||
- isPrevailing(VI.getGUID(), S.get())) &&
- S->linkage() != GlobalValue::AppendingLinkage &&
- // We can't internalize available_externally globals because this
- // can break function pointer equality.
- S->linkage() != GlobalValue::AvailableExternallyLinkage &&
- // Functions and read-only variables with linkonce_odr and
- // weak_odr linkage can be internalized. We can't internalize
- // linkonce_odr and weak_odr variables which are both modified
- // and read somewhere in the program because reads and writes
- // will become inconsistent.
- !isWeakObjectWithRWAccess(S.get()))
- S->setLinkage(GlobalValue::InternalLinkage);
+ continue;
+ }
+
+ // Otherwise, see if we can internalize.
+ if (!EnableLTOInternalization)
+ continue;
+
+ // Ignore local and appending linkage values since the linker
+ // doesn't resolve them (and there is no need to internalize if this is
+ // already internal).
+ if (GlobalValue::isLocalLinkage(S->linkage()) ||
+ S->linkage() == GlobalValue::AppendingLinkage)
+ continue;
+
+ // We can't internalize available_externally globals because this
+ // can break function pointer equality.
+ if (S->linkage() == GlobalValue::AvailableExternallyLinkage)
+ continue;
+
+ bool IsPrevailing = isPrevailing(VI.getGUID(), S.get());
+
+ if (GlobalValue::isInterposableLinkage(S->linkage()) && !IsPrevailing)
+ continue;
+
+ // Functions and read-only variables with linkonce_odr and weak_odr linkage
+ // can be internalized. We can't internalize linkonce_odr and weak_odr
+ // variables which are both modified and read somewhere in the program
+ // because reads and writes will become inconsistent.
+ auto *VarSummary = dyn_cast<GlobalVarSummary>(S->getBaseObject());
+ if (VarSummary && !VarSummary->maybeReadOnly() &&
+ !VarSummary->maybeWriteOnly() &&
+ (VarSummary->linkage() == GlobalValue::WeakODRLinkage ||
+ VarSummary->linkage() == GlobalValue::LinkOnceODRLinkage))
+ continue;
+
+ S->setLinkage(GlobalValue::InternalLinkage);
}
}