9 #ifndef MLIR_DIALECT_TRANSFORM_IR_MATCHINTERFACES_H
10 #define MLIR_DIALECT_TRANSFORM_IR_MATCHINTERFACES_H
13 #include <type_traits>
17 #include "llvm/ADT/STLExtras.h"
21 class MatchOpInterface;
26 template <
typename OpTy>
30 if constexpr (std::is_same_v<
31 typename llvm::function_traits<
32 decltype(&OpTy::matchOperation)>::
template arg_t<0>,
34 return op.matchOperation(
nullptr, results, state);
36 return op.matchOperation(std::nullopt, results, state);
41 template <
typename OpTy>
45 using has_get_operand_handle =
46 decltype(std::declval<T &>().getOperandHandle());
48 using has_match_operation_ptr = decltype(std::declval<T &>().matchOperation(
49 std::declval<Operation *>(), std::declval<TransformResults &>(),
50 std::declval<TransformState &>()));
52 using has_match_operation_optional =
53 decltype(std::declval<T &>().matchOperation(
54 std::declval<std::optional<Operation *>>(),
55 std::declval<TransformResults &>(),
56 std::declval<TransformState &>()));
60 static_assert(llvm::is_detected<has_get_operand_handle, OpTy>::value,
61 "AtMostOneOpMatcherOpTrait/SingleOpMatcherOpTrait expects "
62 "operation type to have the getOperandHandle() method");
64 llvm::is_detected<has_match_operation_ptr, OpTy>::value ||
65 llvm::is_detected<has_match_operation_optional, OpTy>::value,
66 "AtMostOneOpMatcherOpTrait/SingleOpMatcherOpTrait expected operation "
67 "type to have either the matchOperation(Operation *, TransformResults "
68 "&, TransformState &) or the matchOperation(std::optional<Operation*>, "
69 "TransformResults &, TransformState &) method");
73 isa<MatchOpInterface>(op) &&
74 "AtMostOneOpMatcherOpTrait/SingleOpMatchOpTrait is only available on "
75 "operations with MatchOpInterface");
76 Value operandHandle = cast<OpTy>(op).getOperandHandle();
77 if (!isa<TransformHandleTypeInterface>(operandHandle.
getType())) {
78 return op->emitError() <<
"AtMostOneOpMatcherOpTrait/"
79 "SingleOpMatchOpTrait requires the op handle "
80 "to be of TransformHandleTypeInterface";
90 auto payload = state.getPayloadOps(operandHandle);
91 if (!llvm::hasNItemsOrLess(payload, 1)) {
93 <<
"AtMostOneOpMatcherOpTrait requires the operand handle to "
94 "point to at most one payload op";
96 if (payload.empty()) {
101 .matchOperation(*payload.begin(), results, state);
111 template <
typename OpTy>
119 auto payload = state.getPayloadOps(operandHandle);
120 if (!llvm::hasSingleElement(payload)) {
122 <<
"SingleOpMatchOpTrait requires the operand handle to point to "
123 "a single payload op";
126 rewriter, results, state);
130 template <
typename OpTy>
137 assert(isa<MatchOpInterface>(op) &&
138 "SingleValueMatchOpTrait is only available on operations with "
141 Value operandHandle = cast<OpTy>(op).getOperandHandle();
142 if (!isa<TransformValueHandleTypeInterface>(operandHandle.
getType())) {
143 return op->emitError() <<
"SingleValueMatchOpTrait requires an operand "
144 "of TransformValueHandleTypeInterface";
154 auto payload = state.getPayloadValues(operandHandle);
155 if (!llvm::hasSingleElement(payload)) {
157 <<
"SingleValueMatchOpTrait requires the value handle to point "
158 "to a single payload value";
162 .matchValue(*payload.begin(), results, state);
185 UnitAttr &isInverted, UnitAttr &isAll);
199 bool inverted,
bool all);
221 #include "mlir/Dialect/Transform/Interfaces/MatchInterfaces.h.inc"
The result of a transform IR operation application.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
Helper class for implementing traits.
Operation * getOperation()
Return the ultimate Operation being worked on.
Operation is the basic unit of execution within MLIR.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
Base class for DenseArrayAttr that is instantiated and specialized for each supported element type be...
Include the generated interface declarations.
DiagnosedDefiniteFailure emitDefiniteFailure(Location loc, const Twine &message={})
Emits a definite failure with the given message.