[llvm] [Pass] Provide inlined `AnalysisKey` in `AnalysisInfoMixin` (PR #116527)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 16 21:50:11 PST 2024


https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/116527

None

>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] [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 {



More information about the llvm-commits mailing list