[llvm] [Analysis] Provide inlined `AnalysisKey` in `AnalysisInfoMixin` (PR #116046)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 03:35:27 PST 2024


https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/116046

>From 5e3535acd3008260b033ffe01dbd114ed0808341 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Wed, 13 Nov 2024 21:25:45 +0800
Subject: [PATCH 1/2] [Analysis] Provide inlined `AnalysisKey` in
 `AnalysisInfoMixin`

---
 llvm/include/llvm/IR/PassManager.h | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index d269221fac0701..69643d6cab8fc2 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -95,21 +95,15 @@ 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;
   }
+
+private:
+  /// Opaque, unique ID for this analysis type.
+  static constexpr AnalysisKey Key = {};
 };
 
 namespace detail {

>From 551e7349813b861594b3d4f2d3dfdb30c439bc44 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Sat, 16 Nov 2024 19:10:18 +0800
Subject: [PATCH 2/2] Use key from `AnalysisInfoMixin`

---
 llvm/include/llvm/IR/PassManager.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 69643d6cab8fc2..835dea443bae7c 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -98,12 +98,12 @@ struct AnalysisInfoMixin : PassInfoMixin<DerivedT> {
   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:
   /// Opaque, unique ID for this analysis type.
-  static constexpr AnalysisKey Key = {};
+  static inline AnalysisKey Key = {};
 };
 
 namespace detail {



More information about the llvm-commits mailing list