[Mlir-commits] [mlir] 944652f - Use if constexpr to simplify some SFINAE in mlir::OpState (NFC)
Mehdi Amini
llvmlistbot at llvm.org
Sat Dec 10 00:36:28 PST 2022
Author: Mehdi Amini
Date: 2022-12-10T08:36:13Z
New Revision: 944652f8c05e969256c7fd637ce8cab0be794d21
URL: https://github.com/llvm/llvm-project/commit/944652f8c05e969256c7fd637ce8cab0be794d21
DIFF: https://github.com/llvm/llvm-project/commit/944652f8c05e969256c7fd637ce8cab0be794d21.diff
LOG: Use if constexpr to simplify some SFINAE in mlir::OpState (NFC)
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D139769
Added:
Modified:
mlir/include/mlir/IR/OpDefinition.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index 72950670c8f9..268f2e456c99 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -1744,41 +1744,21 @@ class Op : public OpState, public Traits<ConcreteType>... {
/// hooks.
/// Implementation of `FoldHookFn` OperationName hook.
static OperationName::FoldHookFn getFoldHookFn() {
- return getFoldHookFnImpl<ConcreteType>();
- }
- /// The internal implementation of `getFoldHookFn` above that is invoked if
- /// the operation is single result and defines a `fold` method.
- template <typename ConcreteOpT>
- static std::enable_if_t<llvm::is_one_of<OpTrait::OneResult<ConcreteOpT>,
- Traits<ConcreteOpT>...>::value &&
- detect_has_single_result_fold<ConcreteOpT>::value,
- OperationName::FoldHookFn>
- getFoldHookFnImpl() {
- return [](Operation *op, ArrayRef<Attribute> operands,
- SmallVectorImpl<OpFoldResult> &results) {
- return foldSingleResultHook<ConcreteOpT>(op, operands, results);
- };
- }
- /// The internal implementation of `getFoldHookFn` above that is invoked if
- /// the operation is not single result and defines a `fold` method.
- template <typename ConcreteOpT>
- static std::enable_if_t<!llvm::is_one_of<OpTrait::OneResult<ConcreteOpT>,
- Traits<ConcreteOpT>...>::value &&
- detect_has_fold<ConcreteOpT>::value,
- OperationName::FoldHookFn>
- getFoldHookFnImpl() {
- return [](Operation *op, ArrayRef<Attribute> operands,
- SmallVectorImpl<OpFoldResult> &results) {
- return foldHook<ConcreteOpT>(op, operands, results);
- };
- }
- /// The internal implementation of `getFoldHookFn` above that is invoked if
- /// the operation does not define a `fold` method.
- template <typename ConcreteOpT>
- static std::enable_if_t<!detect_has_single_result_fold<ConcreteOpT>::value &&
- !detect_has_fold<ConcreteOpT>::value,
- OperationName::FoldHookFn>
- getFoldHookFnImpl() {
+ // If the operation is single result and defines a `fold` method.
+ if constexpr (llvm::is_one_of<OpTrait::OneResult<ConcreteType>,
+ Traits<ConcreteType>...>::value &&
+ detect_has_single_result_fold<ConcreteType>::value)
+ return [](Operation *op, ArrayRef<Attribute> operands,
+ SmallVectorImpl<OpFoldResult> &results) {
+ return foldSingleResultHook<ConcreteType>(op, operands, results);
+ };
+ // The operation is not single result and defines a `fold` method.
+ if constexpr (detect_has_fold<ConcreteType>::value)
+ return [](Operation *op, ArrayRef<Attribute> operands,
+ SmallVectorImpl<OpFoldResult> &results) {
+ return foldHook<ConcreteType>(op, operands, results);
+ };
+ // The operation does not define a `fold` method.
return [](Operation *op, ArrayRef<Attribute> operands,
SmallVectorImpl<OpFoldResult> &results) {
// In this case, we only need to fold the traits of the operation.
@@ -1837,31 +1817,16 @@ class Op : public OpState, public Traits<ConcreteType>... {
}
/// Implementation of `PrintAssemblyFn` OperationName hook.
static OperationName::PrintAssemblyFn getPrintAssemblyFn() {
- return getPrintAssemblyFnImpl<ConcreteType>();
- }
- /// The internal implementation of `getPrintAssemblyFn` that is invoked when
- /// the concrete operation does not define a `print` method.
- template <typename ConcreteOpT>
- static std::enable_if_t<!detect_has_print<ConcreteOpT>::value,
- OperationName::PrintAssemblyFn>
- getPrintAssemblyFnImpl() {
+ if constexpr (detect_has_print<ConcreteType>::value)
+ return [](Operation *op, OpAsmPrinter &p, StringRef defaultDialect) {
+ OpState::printOpName(op, p, defaultDialect);
+ return cast<ConcreteType>(op).print(p);
+ };
return [](Operation *op, OpAsmPrinter &printer, StringRef defaultDialect) {
return OpState::print(op, printer, defaultDialect);
};
}
- /// The internal implementation of `getPrintAssemblyFn` that is invoked when
- /// the concrete operation defines a `print` method.
- template <typename ConcreteOpT>
- static std::enable_if_t<detect_has_print<ConcreteOpT>::value,
- OperationName::PrintAssemblyFn>
- getPrintAssemblyFnImpl() {
- return &printAssembly;
- }
- static void printAssembly(Operation *op, OpAsmPrinter &p,
- StringRef defaultDialect) {
- OpState::printOpName(op, p, defaultDialect);
- return cast<ConcreteType>(op).print(p);
- }
+
/// Implementation of `PopulateDefaultAttrsFn` OperationName hook.
static OperationName::PopulateDefaultAttrsFn getPopulateDefaultAttrsFn() {
return ConcreteType::populateDefaultAttrs;
More information about the Mlir-commits
mailing list