14 #ifndef MLIR_DIALECT_IRDL_IR_IRDLTRAITS_H_
15 #define MLIR_DIALECT_IRDL_IR_IRDLTRAITS_H_
19 #include "llvm/Support/Casting.h"
29 template <
typename... ChildOps>
32 template <
typename ConcreteType>
34 :
public TraitBase<ConcreteType, AtMostOneChildOf<ChildOps...>::Impl> {
38 ConcreteType::template hasTrait<::mlir::OpTrait::OneRegion>(),
39 "expected operation to have a single region");
40 static_assert(
sizeof...(ChildOps) > 0,
41 "expected at least one child operation type");
44 bool satisfiedOps[
sizeof...(ChildOps)] = {};
46 for (
Operation &child : cast<ConcreteType>(op).getOps()) {
48 if (((isa<ChildOps>(child) ?
false : (++childOpIndex,
true)) && ...))
52 if (satisfiedOps[childOpIndex])
53 return op->emitError()
54 <<
"failed to verify AtMostOneChildOf trait: the operation "
55 "contains at least two operations of type "
59 satisfiedOps[childOpIndex] =
true;
66 template <
typename OpT>
67 std::enable_if_t<std::disjunction<std::is_same<OpT, ChildOps>...>::value,
71 cast<ConcreteType>(this->
getOperation()).template getOps<OpT>();
74 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.
Include the generated interface declarations.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.