[llvm] [Pass] Provide inlined `AnalysisKey` in `AnalysisInfoMixin` (PR #116527)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 16 23:16:19 PST 2024
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/116527
>From 3b5daefc05f0f95835ba03a4eea05830276c24e8 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Sun, 17 Nov 2024 13:43:02 +0800
Subject: [PATCH 1/2] [Pass] Provide inlined `AnalysisKey` in
`AnalysisInfoMixin`
---
llvm/include/llvm/IR/PassManager.h | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index d269221fac0701..abbde26d1abbc8 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -95,21 +95,14 @@ struct AnalysisInfoMixin : PassInfoMixin<DerivedT> {
/// This ID is a pointer type that is guaranteed to be 8-byte aligned and thus
/// suitable for use in sets, maps, and other data structures that use the low
/// bits of pointers.
- ///
- /// Note that this requires the derived type provide a static \c AnalysisKey
- /// member called \c Key.
- ///
- /// FIXME: The only reason the mixin type itself can't declare the Key value
- /// is that some compilers cannot correctly unique a templated static variable
- /// so it has the same addresses in each instantiation. The only currently
- /// known platform with this limitation is Windows DLL builds, specifically
- /// building each part of LLVM as a DLL. If we ever remove that build
- /// configuration, this mixin can provide the static key as well.
static AnalysisKey *ID() {
static_assert(std::is_base_of<AnalysisInfoMixin, DerivedT>::value,
"Must pass the derived type as the template argument!");
- return &DerivedT::Key;
+ return &Key;
}
+
+private:
+ static inline AnalysisKey Key = {};
};
namespace detail {
>From 0601317eea94be84e00da995df2e1ec7210a5524 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Sun, 17 Nov 2024 14:42:12 +0800
Subject: [PATCH 2/2] Drop key in DominatorTreeAnalysis
---
llvm/include/llvm/IR/Dominators.h | 3 ---
llvm/include/llvm/IR/PassManager.h | 2 +-
llvm/lib/IR/Dominators.cpp | 2 --
3 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/llvm/include/llvm/IR/Dominators.h b/llvm/include/llvm/IR/Dominators.h
index 287f419f893dbd..30794898113e95 100644
--- a/llvm/include/llvm/IR/Dominators.h
+++ b/llvm/include/llvm/IR/Dominators.h
@@ -277,9 +277,6 @@ template <> struct GraphTraits<DominatorTree*>
/// Analysis pass which computes a \c DominatorTree.
class DominatorTreeAnalysis : public AnalysisInfoMixin<DominatorTreeAnalysis> {
- friend AnalysisInfoMixin<DominatorTreeAnalysis>;
- static AnalysisKey Key;
-
public:
/// Provide the result typedef for this analysis pass.
using Result = DominatorTree;
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index abbde26d1abbc8..a28912ef0a5b6b 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -89,7 +89,7 @@ template <typename DerivedT> struct PassInfoMixin {
/// This provides some boilerplate for types that are analysis passes. It
/// automatically mixes in \c PassInfoMixin.
template <typename DerivedT>
-struct AnalysisInfoMixin : PassInfoMixin<DerivedT> {
+LLVM_ABI_EXPORT struct AnalysisInfoMixin : PassInfoMixin<DerivedT> {
/// Returns an opaque, unique ID for this analysis type.
///
/// This ID is a pointer type that is guaranteed to be 8-byte aligned and thus
diff --git a/llvm/lib/IR/Dominators.cpp b/llvm/lib/IR/Dominators.cpp
index cc51b4905a628e..5937d3ac60572b 100644
--- a/llvm/lib/IR/Dominators.cpp
+++ b/llvm/lib/IR/Dominators.cpp
@@ -375,8 +375,6 @@ DominatorTree DominatorTreeAnalysis::run(Function &F,
return DT;
}
-AnalysisKey DominatorTreeAnalysis::Key;
-
DominatorTreePrinterPass::DominatorTreePrinterPass(raw_ostream &OS) : OS(OS) {}
PreservedAnalyses DominatorTreePrinterPass::run(Function &F,
More information about the llvm-commits
mailing list