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

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 00:40:16 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

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


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


2 Files Affected:

- (modified) llvm/include/llvm/IR/PassInstrumentation.h (+3-8) 
- (modified) llvm/include/llvm/IR/PassManagerInternal.h (+3-8) 


``````````diff
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;
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list