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:41
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Apr 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

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/137506.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Pass/AnalysisManager.h (+7-10)
diff --git a/mlir/include/mlir/Pass/AnalysisManager.h b/mlir/include/mlir/Pass/AnalysisManager.h
index 199ffee792bb5..45009d4b02a58 100644
--- a/mlir/include/mlir/Pass/AnalysisManager.h
+++ b/mlir/include/mlir/Pass/AnalysisManager.h
@@ -85,17 +85,14 @@ template <typename T, typename... Args>
 using has_is_invalidated = decltype(std::declval<T &>().isInvalidated(
     std::declval<const PreservedAnalyses &>()));
 
-/// Implementation of 'isInvalidated' if the analysis provides a definition.
 template <typename AnalysisT>
-std::enable_if_t<llvm::is_detected<has_is_invalidated, AnalysisT>::value, bool>
-isInvalidated(AnalysisT &analysis, const PreservedAnalyses &pa) {
-  return analysis.isInvalidated(pa);
-}
-/// Default implementation of 'isInvalidated'.
-template <typename AnalysisT>
-std::enable_if_t<!llvm::is_detected<has_is_invalidated, AnalysisT>::value, bool>
-isInvalidated(AnalysisT &analysis, const PreservedAnalyses &pa) {
-  return !pa.isPreserved<AnalysisT>();
+bool isInvalidated(AnalysisT &analysis, const PreservedAnalyses &pa) {
+  if constexpr (llvm::is_detected<has_is_invalidated, AnalysisT>::value)
+    /// Implementation of 'isInvalidated' if the analysis provides a definition.
+    return analysis.isInvalidated(pa);
+  else
+    /// Default implementation of 'isInvalidated'.
+    return !pa.isPreserved<AnalysisT>();
 }
 } // namespace analysis_impl
 

@kazutakahirata kazutakahirata merged commit 95b2e23 into llvm:main Apr 27, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_constexpr_if_mlir 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

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants