diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index 237d48756c749..31f54413a5ff0 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -1631,14 +1631,11 @@ using detect_has_verify_region_trait = /// Verify the given trait if it provides a verifier. template -std::enable_if_t::value, LogicalResult> -verifyTrait(Operation *op) { - return T::verifyTrait(op); -} -template -inline std::enable_if_t::value, LogicalResult> -verifyTrait(Operation *) { - return success(); +LogicalResult verifyTrait(Operation *op) { + if constexpr (detect_has_verify_trait::value) + return T::verifyTrait(op); + else + return success(); } /// Given a set of traits, return the result of verifying the given operation. @@ -1649,15 +1646,11 @@ LogicalResult verifyTraits(Operation *op) { /// Verify the given trait if it provides a region verifier. template -std::enable_if_t::value, LogicalResult> -verifyRegionTrait(Operation *op) { - return T::verifyRegionTrait(op); -} -template -inline std::enable_if_t::value, - LogicalResult> -verifyRegionTrait(Operation *) { - return success(); +LogicalResult verifyRegionTrait(Operation *op) { + if constexpr (detect_has_verify_region_trait::value) + return T::verifyRegionTrait(op); + else + return success(); } /// Given a set of traits, return the result of verifying the regions of the diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h index fc6ae8fb55fec..10cfe851765dc 100644 --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -273,17 +273,13 @@ class RewritePattern : public Pattern { template using detect_has_initialize = llvm::is_detected; - /// Initialize the derived pattern by calling its `initialize` method. + /// Initialize the derived pattern by calling its `initialize` method if + /// available. template - static std::enable_if_t::value> - initializePattern(T &pattern) { - pattern.initialize(); + static void initializePattern(T &pattern) { + if constexpr (detect_has_initialize::value) + pattern.initialize(); } - /// Empty derived pattern initializer for patterns that do not have an - /// initialize method. - template - static std::enable_if_t::value> - initializePattern(T &) {} /// An anchor for the virtual table. virtual void anchor(); diff --git a/mlir/include/mlir/Pass/PassOptions.h b/mlir/include/mlir/Pass/PassOptions.h index 68588279e2f5a..e1f16c6158ad5 100644 --- a/mlir/include/mlir/Pass/PassOptions.h +++ b/mlir/include/mlir/Pass/PassOptions.h @@ -75,16 +75,13 @@ static void printOptionValue(raw_ostream &os, const std::string &str) { os << "}"; } template -static std::enable_if_t::value> -printOptionValue(raw_ostream &os, const DataT &value) { - os << value; -} -template -static std::enable_if_t::value> -printOptionValue(raw_ostream &os, const DataT &value) { - // If the value can't be streamed, fallback to checking for a print in the - // parser. - ParserT::print(os, value); +static void printOptionValue(raw_ostream &os, const DataT &value) { + if constexpr (has_stream_operator::value) + os << value; + else + // If the value can't be streamed, fallback to checking for a print in the + // parser. + ParserT::print(os, value); } } // namespace pass_options