Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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

We can use "constexpr if" to combine the two variants of functions.
@kazutakahirata kazutakahirata requested a review from kuhar April 27, 2025 07:39
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

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

@kazutakahirata kazutakahirata merged commit 49eb7d0 into llvm:main Apr 27, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_constexpr_if_llvm_IR branch April 27, 2025 15:53
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpr if" to combine the two variants of functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants