[llvm] 49eb7d0 - [IR] Simplify isRequired and passIsRequiredImpl (NFC) (#137503)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 08:52:44 PDT 2025


Author: Kazu Hirata
Date: 2025-04-27T08:52:42-07:00
New Revision: 49eb7d0485bc2d9887f8cdf386aa6adaa39e8a57

URL: https://github.com/llvm/llvm-project/commit/49eb7d0485bc2d9887f8cdf386aa6adaa39e8a57
DIFF: https://github.com/llvm/llvm-project/commit/49eb7d0485bc2d9887f8cdf386aa6adaa39e8a57.diff

LOG: [IR] Simplify isRequired and passIsRequiredImpl (NFC) (#137503)

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

Added: 
    

Modified: 
    llvm/include/llvm/IR/PassInstrumentation.h
    llvm/include/llvm/IR/PassManagerInternal.h

Removed: 
    


################################################################################
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