diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h index 43e246c7bd59..5f79e4f6f35a 100644 --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -394,6 +394,8 @@ public: /// template class NOperands { public: + static_assert(N > 1, "use ZeroOperands/OneOperand for N < 2"); + template class Impl : public detail::MultiOperandTraitBase::Impl> { @@ -404,18 +406,6 @@ public: }; }; -/// Specialization of NOperands with N = 0. -template <> class NOperands<0> { -public: - template using Impl = ZeroOperands; -}; - -/// Specialization of NOperands with N = 1. -template <> class NOperands<1> { -public: - template using Impl = OneOperand; -}; - /// This class provides the API for ops that are known to have a at least a /// specified number of operands. This is used as a trait like this: /// @@ -520,6 +510,8 @@ public: /// template class NResults { public: + static_assert(N > 1, "use ZeroResult/OneResult for N < 2"); + template class Impl : public detail::MultiResultTraitBase::Impl> { diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td index 7136aaf26659..359b97c6662d 100644 --- a/mlir/test/mlir-tblgen/op-decl.td +++ b/mlir/test/mlir-tblgen/op-decl.td @@ -81,14 +81,14 @@ def NS_BOp : NS_Op<"op_with_no_operand", []> { } // CHECK-LABEL: NS::BOp declarations -// CHECK: OpTrait::NOperands<0>::Impl +// CHECK: OpTrait::ZeroOperands def NS_COp : NS_Op<"op_with_one_operand", []> { let arguments = (ins I32:$operand); } // CHECK-LABEL: NS::COp declarations -// CHECK: OpTrait::NOperands<1>::Impl +// CHECK: OpTrait::OneOperand def NS_DOp : NS_Op<"op_with_two_operands", []> { let arguments = (ins I32:$input1, I32:$input2); diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 87ce6233084d..ec3eb7854377 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1190,7 +1190,17 @@ void OpEmitter::genTraits() { opClass.addTrait("AtLeastNOperands<" + Twine(numOperands - 1) + ">::Impl"); } else { - opClass.addTrait("NOperands<" + Twine(numOperands) + ">::Impl"); + switch (numOperands) { + case 0: + opClass.addTrait("ZeroOperands"); + break; + case 1: + opClass.addTrait("OneOperand"); + break; + default: + opClass.addTrait("NOperands<" + Twine(numOperands) + ">::Impl"); + break; + } } }