[llvm] [NFC][LLVM] Eliminate duplicate code in INITIALIZE_PASS macros (PR #134457)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 4 16:21:44 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Rahul Joshi (jurahul)

<details>
<summary>Changes</summary>

- Refactor INITIALIZE_PASS and INITIALIZE_PASS_WITH_OPTIONS macros to eliminate some code duplication.

---
Full diff: https://github.com/llvm/llvm-project/pull/134457.diff


1 Files Affected:

- (modified) llvm/include/llvm/PassSupport.h (+7-18) 


``````````diff
diff --git a/llvm/include/llvm/PassSupport.h b/llvm/include/llvm/PassSupport.h
index d3ba32f22efe1..57210b2488b53 100644
--- a/llvm/include/llvm/PassSupport.h
+++ b/llvm/include/llvm/PassSupport.h
@@ -35,20 +35,6 @@ namespace llvm {
 
 class Pass;
 
-#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)                    \
-  static void *initialize##passName##PassOnce(PassRegistry &Registry) {        \
-    PassInfo *PI = new PassInfo(                                               \
-        name, arg, &passName::ID,                                              \
-        PassInfo::NormalCtor_t(callDefaultCtor<passName>), cfg, analysis);     \
-    Registry.registerPass(*PI, true);                                          \
-    return PI;                                                                 \
-  }                                                                            \
-  static llvm::once_flag Initialize##passName##PassFlag;                       \
-  void llvm::initialize##passName##Pass(PassRegistry &Registry) {              \
-    llvm::call_once(Initialize##passName##PassFlag,                            \
-                    initialize##passName##PassOnce, std::ref(Registry));       \
-  }
-
 #define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)              \
   static void *initialize##passName##PassOnce(PassRegistry &Registry) {
 
@@ -67,15 +53,18 @@ class Pass;
                     initialize##passName##PassOnce, std::ref(Registry));       \
   }
 
-#define INITIALIZE_PASS_WITH_OPTIONS(PassName, Arg, Name, Cfg, Analysis)       \
-  INITIALIZE_PASS_BEGIN(PassName, Arg, Name, Cfg, Analysis)                    \
-  PassName::registerOptions();                                                 \
-  INITIALIZE_PASS_END(PassName, Arg, Name, Cfg, Analysis)
+#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)                    \
+  INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)                    \
+  INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
 
 #define INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis) \
   INITIALIZE_PASS_BEGIN(PassName, Arg, Name, Cfg, Analysis)                    \
   PassName::registerOptions();
 
+#define INITIALIZE_PASS_WITH_OPTIONS(PassName, Arg, Name, Cfg, Analysis)       \
+  INITIALIZE_PASS_WITH_OPTIONS_BEGIN(PassName, Arg, Name, Cfg, Analysis)       \
+  INITIALIZE_PASS_END(PassName, Arg, Name, Cfg, Analysis)
+
 template <
     class PassName,
     std::enable_if_t<std::is_default_constructible<PassName>{}, bool> = true>

``````````

</details>


https://github.com/llvm/llvm-project/pull/134457


More information about the llvm-commits mailing list