Disallow using NOperands/NResults when N < 2. We have special traits for the case of 0/1 that we explicitly check for throughout the codebase. This also fixes weird build failures in MSVC where it doesn't properly handle template type aliases.

PiperOrigin-RevId: 253269936
This commit is contained in:
River Riddle 2019-06-14 11:56:41 -07:00 committed by Mehdi Amini
parent e7e03cee1f
commit 3682936982
3 changed files with 17 additions and 15 deletions

View File

@ -394,6 +394,8 @@ public:
///
template <unsigned N> class NOperands {
public:
static_assert(N > 1, "use ZeroOperands/OneOperand for N < 2");
template <typename ConcreteType>
class Impl
: public detail::MultiOperandTraitBase<ConcreteType, NOperands<N>::Impl> {
@ -404,18 +406,6 @@ public:
};
};
/// Specialization of NOperands with N = 0.
template <> class NOperands<0> {
public:
template <typename ConcreteType> using Impl = ZeroOperands<ConcreteType>;
};
/// Specialization of NOperands with N = 1.
template <> class NOperands<1> {
public:
template <typename ConcreteType> using Impl = OneOperand<ConcreteType>;
};
/// 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 <unsigned N> class NResults {
public:
static_assert(N > 1, "use ZeroResult/OneResult for N < 2");
template <typename ConcreteType>
class Impl
: public detail::MultiResultTraitBase<ConcreteType, NResults<N>::Impl> {

View File

@ -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);

View File

@ -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;
}
}
}