aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ModuleSummaryIndex.cpp
diff options
context:
space:
mode:
authorMingming Liu <mingmingl@google.com>2024-12-02 16:15:52 -0800
committerGitHub <noreply@github.com>2024-12-02 16:15:52 -0800
commit6faf17b7626bfdeea977a7a333c6e20ed677615d (patch)
tree5646cc635378ec694875da2c23d115f3d95b5567 /llvm/lib/IR/ModuleSummaryIndex.cpp
parent7267c85959aa2490e2950f7fb817a76af7e94043 (diff)
downloadllvm-6faf17b7626bfdeea977a7a333c6e20ed677615d.zip
llvm-6faf17b7626bfdeea977a7a333c6e20ed677615d.tar.gz
llvm-6faf17b7626bfdeea977a7a333c6e20ed677615d.tar.bz2
[ThinLTO]Supports declaration import for global variables in distributed ThinLTO (#117616)
When `-import-declaration` option is enabled, declaration import is supported for functions. https://github.com/llvm/llvm-project/pull/88024 has the context for this option. This patch supports declaration import for global variables in distributed ThinLTO. The motivating use case is to propagate `dso_local` attribute of global variables across modules, to optimize global variable access when a binary is built with `-fno-direct-access-external-data`. * With `-fdirect-access-external-data`, non thread-local global variables will [have `dso_local` attributes](https://github.com/llvm/llvm-project/blob/fe3c23b439b9a2d00442d9bc6a4ca86f73066a3d/clang/lib/CodeGen/CodeGenModule.cpp#L1730-L1746). This optimizes the global variable access as shown by https://gcc.godbolt.org/z/vMzWcKdh3
Diffstat (limited to 'llvm/lib/IR/ModuleSummaryIndex.cpp')
-rw-r--r--llvm/lib/IR/ModuleSummaryIndex.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp
index 12a558b..d9024b0 100644
--- a/llvm/lib/IR/ModuleSummaryIndex.cpp
+++ b/llvm/lib/IR/ModuleSummaryIndex.cpp
@@ -328,6 +328,13 @@ void ModuleSummaryIndex::propagateAttributes(
bool ModuleSummaryIndex::canImportGlobalVar(const GlobalValueSummary *S,
bool AnalyzeRefs) const {
+ bool CanImportDecl;
+ return canImportGlobalVar(S, AnalyzeRefs, CanImportDecl);
+}
+
+bool ModuleSummaryIndex::canImportGlobalVar(const GlobalValueSummary *S,
+ bool AnalyzeRefs,
+ bool &CanImportDecl) const {
auto HasRefsPreventingImport = [this](const GlobalVarSummary *GVS) {
// We don't analyze GV references during attribute propagation, so
// GV with non-trivial initializer can be marked either read or
@@ -348,13 +355,20 @@ bool ModuleSummaryIndex::canImportGlobalVar(const GlobalValueSummary *S,
};
auto *GVS = cast<GlobalVarSummary>(S->getBaseObject());
+ const bool nonInterposable =
+ !GlobalValue::isInterposableLinkage(S->linkage());
+ const bool eligibleToImport = !S->notEligibleToImport();
+
+ // It's correct to import a global variable only when it is not interposable
+ // and eligible to import.
+ CanImportDecl = (nonInterposable && eligibleToImport);
+
// Global variable with non-trivial initializer can be imported
// if it's readonly. This gives us extra opportunities for constant
// folding and converting indirect calls to direct calls. We don't
// analyze GV references during attribute propagation, because we
// don't know yet if it is readonly or not.
- return !GlobalValue::isInterposableLinkage(S->linkage()) &&
- !S->notEligibleToImport() &&
+ return nonInterposable && eligibleToImport &&
(!AnalyzeRefs || !HasRefsPreventingImport(GVS));
}