Skip to content

[mlir] Simplify functions with "constexpr if" (NFC) #137551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions mlir/include/mlir/IR/OpDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -1631,14 +1631,11 @@ using detect_has_verify_region_trait =

/// Verify the given trait if it provides a verifier.
template <typename T>
std::enable_if_t<detect_has_verify_trait<T>::value, LogicalResult>
verifyTrait(Operation *op) {
return T::verifyTrait(op);
}
template <typename T>
inline std::enable_if_t<!detect_has_verify_trait<T>::value, LogicalResult>
verifyTrait(Operation *) {
return success();
LogicalResult verifyTrait(Operation *op) {
if constexpr (detect_has_verify_trait<T>::value)
return T::verifyTrait(op);
else
return success();
}

/// Given a set of traits, return the result of verifying the given operation.
Expand All @@ -1649,15 +1646,11 @@ LogicalResult verifyTraits(Operation *op) {

/// Verify the given trait if it provides a region verifier.
template <typename T>
std::enable_if_t<detect_has_verify_region_trait<T>::value, LogicalResult>
verifyRegionTrait(Operation *op) {
return T::verifyRegionTrait(op);
}
template <typename T>
inline std::enable_if_t<!detect_has_verify_region_trait<T>::value,
LogicalResult>
verifyRegionTrait(Operation *) {
return success();
LogicalResult verifyRegionTrait(Operation *op) {
if constexpr (detect_has_verify_region_trait<T>::value)
return T::verifyRegionTrait(op);
else
return success();
}

/// Given a set of traits, return the result of verifying the regions of the
Expand Down
14 changes: 5 additions & 9 deletions mlir/include/mlir/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,13 @@ class RewritePattern : public Pattern {
template <typename T>
using detect_has_initialize = llvm::is_detected<has_initialize, T>;

/// Initialize the derived pattern by calling its `initialize` method.
/// Initialize the derived pattern by calling its `initialize` method if
/// available.
template <typename T>
static std::enable_if_t<detect_has_initialize<T>::value>
initializePattern(T &pattern) {
pattern.initialize();
static void initializePattern(T &pattern) {
if constexpr (detect_has_initialize<T>::value)
pattern.initialize();
}
/// Empty derived pattern initializer for patterns that do not have an
/// initialize method.
template <typename T>
static std::enable_if_t<!detect_has_initialize<T>::value>
initializePattern(T &) {}

/// An anchor for the virtual table.
virtual void anchor();
Expand Down
17 changes: 7 additions & 10 deletions mlir/include/mlir/Pass/PassOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,13 @@ static void printOptionValue(raw_ostream &os, const std::string &str) {
os << "}";
}
template <typename ParserT, typename DataT>
static std::enable_if_t<has_stream_operator<DataT>::value>
printOptionValue(raw_ostream &os, const DataT &value) {
os << value;
}
template <typename ParserT, typename DataT>
static std::enable_if_t<!has_stream_operator<DataT>::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<DataT>::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

Expand Down
Loading