[llvm] [IR] Simplify isRequired and passIsRequiredImpl (NFC) (PR #137503)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 00:39:43 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/137503

We can use "constexpr if" to combine the two variants of functions.


>From db13c3577d8dfad5148d85593affe2429435374d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 26 Apr 2025 23:29:02 -0700
Subject: [PATCH] [IR] Simplify isRequired and passIsRequiredImpl (NFC)

We can use "constexpr if" to combine the two variants of functions.
---
 llvm/include/llvm/IR/PassInstrumentation.h | 11 +++--------
 llvm/include/llvm/IR/PassManagerInternal.h | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/llvm/include/llvm/IR/PassInstrumentation.h b/llvm/include/llvm/IR/PassInstrumentation.h
index 4e65804179ae7..3172cefe7e8ca 100644
--- a/llvm/include/llvm/IR/PassInstrumentation.h
+++ b/llvm/include/llvm/IR/PassInstrumentation.h
@@ -216,14 +216,9 @@ class PassInstrumentation {
   template <typename PassT>
   using has_required_t = decltype(std::declval<PassT &>().isRequired());
 
-  template <typename PassT>
-  static std::enable_if_t<is_detected<has_required_t, PassT>::value, bool>
-  isRequired(const PassT &Pass) {
-    return Pass.isRequired();
-  }
-  template <typename PassT>
-  static std::enable_if_t<!is_detected<has_required_t, PassT>::value, bool>
-  isRequired(const PassT &Pass) {
+  template <typename PassT> static bool isRequired(const PassT &Pass) {
+    if constexpr (is_detected<has_required_t, PassT>::value)
+      return Pass.isRequired();
     return false;
   }
 
diff --git a/llvm/include/llvm/IR/PassManagerInternal.h b/llvm/include/llvm/IR/PassManagerInternal.h
index 62bede206da50..2f84ae24383e9 100644
--- a/llvm/include/llvm/IR/PassManagerInternal.h
+++ b/llvm/include/llvm/IR/PassManagerInternal.h
@@ -102,14 +102,9 @@ struct PassModel : PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
   template <typename T>
   using has_required_t = decltype(std::declval<T &>().isRequired());
 
-  template <typename T>
-  static std::enable_if_t<is_detected<has_required_t, T>::value, bool>
-  passIsRequiredImpl() {
-    return T::isRequired();
-  }
-  template <typename T>
-  static std::enable_if_t<!is_detected<has_required_t, T>::value, bool>
-  passIsRequiredImpl() {
+  template <typename T> static bool passIsRequiredImpl() {
+    if constexpr (is_detected<has_required_t, T>::value)
+      return T::isRequired();
     return false;
   }
 



More information about the llvm-commits mailing list