14 #ifndef MLIR_DIALECT_IRDL_IR_IRDLTRAITS_H_
15 #define MLIR_DIALECT_IRDL_IR_IRDLTRAITS_H_
18 #include "llvm/Support/Casting.h"
28 template <
typename... ChildOps>
31 template <
typename ConcreteType>
33 :
public TraitBase<ConcreteType, AtMostOneChildOf<ChildOps...>::Impl> {
37 ConcreteType::template hasTrait<::mlir::OpTrait::OneRegion>(),
38 "expected operation to have a single region");
39 static_assert(
sizeof...(ChildOps) > 0,
40 "expected at least one child operation type");
43 bool satisfiedOps[
sizeof...(ChildOps)] = {};
45 for (
Operation &child : cast<ConcreteType>(op).getOps()) {
47 if (((isa<ChildOps>(child) ?
false : (++childOpIndex,
true)) && ...))
51 if (satisfiedOps[childOpIndex])
53 <<
"failed to verify AtMostOneChildOf trait: the operation "
54 "contains at least two operations of type "
58 satisfiedOps[childOpIndex] =
true;
65 template <
typename OpT>
66 std::enable_if_t<std::disjunction<std::is_same<OpT, ChildOps>...>::value,
70 cast<ConcreteType>(this->
getOperation()).template getOps<OpT>();
73 return {*ops.begin()};
static LogicalResult verifyTrait(Operation *op)
std::enable_if_t< std::disjunction< std::is_same< OpT, ChildOps >... >::value, std::optional< OpT > > getOp()
Get the unique operation of a specific op that is in the operation region.
Characterize operations that have at most a single operation of certain types in their region.
Helper class for implementing traits.
Operation * getOperation()
Return the ultimate Operation being worked on.
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
Include the generated interface declarations.