15 #ifndef MLIR_MATCHERS_H 16 #define MLIR_MATCHERS_H 32 typename std::enable_if<std::is_base_of<Attribute, AttrClass>::value,
33 AttrClass>::type::ValueType,
35 typename =
typename std::enable_if<!std::is_void<ValueType>::value>::type>
43 if (
auto intAttr = attr.
dyn_cast<AttrClass>()) {
44 *bind_value = intAttr.getValue();
68 if (
auto attr = foldedOp.front().dyn_cast<
Attribute>()) {
69 if ((*bind_value = attr.dyn_cast<AttrT>()))
91 if (type.isIntOrIndex()) {
97 .
match(splatAttr.getSplatValue());
129 template <
typename T,
typename OperationOrValue>
131 decltype(std::declval<T>().
match(std::declval<OperationOrValue>()));
134 template <
typename MatcherClass>
136 MatcherClass,
Value>::value,
143 template <
typename MatcherClass>
149 return matcher.match(defOp);
165 template <
typename TupleT,
class CallbackT, std::size_t... Is>
167 std::index_sequence<Is...>) {
168 (void)std::initializer_list<int>{
170 (callback(std::integral_constant<std::size_t, Is>{}, std::get<Is>(tuple)),
174 template <
typename... Tys,
typename CallbackT>
175 constexpr
void enumerate(std::tuple<Tys...> &tuple, CallbackT &&callback) {
177 std::make_index_sequence<
sizeof...(Tys)>{});
181 template <
typename OpType,
typename... OperandMatchers>
184 : operandMatchers(matchers...) {}
186 if (!isa<OpType>(op) || op->
getNumOperands() !=
sizeof...(OperandMatchers))
189 enumerate(operandMatchers, [&](
size_t index,
auto &matcher) {
201 template <
typename AttrT>
228 template <
typename Pattern>
232 return const_cast<Pattern &>(pattern).match(op);
237 template <
typename Pattern>
249 template <
typename OpType,
typename... Matchers>
250 auto m_Op(Matchers... matchers) {
261 #endif // MLIR_MATCHERS_H Definition: InferTypeOpInterface.cpp:20
constexpr void enumerateImpl(TupleT &&tuple, CallbackT &&callback, std::index_sequence< Is... >)
Definition: Matchers.h:166
Definition: Matchers.h:53
detail::constant_int_op_binder m_ConstantInt(IntegerAttr::ValueType *bind_value)
Definition: Matchers.h:245
Definition: Operation.h:27
Binds to a specific value and matches it.
Definition: Matchers.h:159
detail::constant_int_not_value_matcher< 0 > m_NonZero()
Definition: Matchers.h:223
Value getOperand(unsigned idx)
Definition: Operation.h:207
Definition: Matchers.h:106
AttrT * bind_value
Definition: Matchers.h:54
unsigned getNumOperands()
Definition: Operation.h:205
attr_value_binder(ValueType *bv)
Creates a matcher instance that binds the value to bv if match succeeds.
Definition: Matchers.h:40
ValueType * bind_value
Definition: Matchers.h:37
Value value
Definition: Matchers.h:162
constant_int_op_binder(IntegerAttr::ValueType *bv)
Creates a matcher instance that binds the value to bv if match succeeds.
Definition: Matchers.h:83
bool succeeded(LogicalResult result)
Definition: LogicalResult.h:39
detail::constant_int_value_matcher< 1 > m_One()
Matches a constant scalar / vector splat / tensor splat integer one.
Definition: Matchers.h:207
Definition: StandardTypes.h:314
Definition: Matchers.h:115
PatternMatcherValue(Value val)
Definition: Matchers.h:160
Definition: PatternMatch.h:82
auto m_Any()
Definition: Matchers.h:255
unsigned getNumResults()
Return the number of results held by this operation.
Definition: Operation.cpp:548
RecursivePatternMatcher that composes.
Definition: Matchers.h:182
bool match(Operation *op)
Definition: Matchers.h:85
bool hasNoSideEffect()
Returns whether the operation has side-effects.
Definition: Operation.h:456
std::tuple< OperandMatchers... > operandMatchers
Definition: Matchers.h:194
bool match(Value op) const
Definition: Matchers.h:155
bool match(Operation *op)
Definition: Matchers.h:60
detail::constant_op_binder< AttrT > m_Constant(AttrT *bind_value)
Definition: Matchers.h:202
Type getType() const
Return the type of this value.
Definition: Value.cpp:34
std::enable_if_t< is_detected< detail::has_operation_or_value_matcher_t, MatcherClass, Value >::value, bool > matchOperandOrValueAtIndex(Operation *op, unsigned idx, MatcherClass &matcher)
Statically switch to a Value matcher.
Definition: Matchers.h:138
typename detail::detector< void, Op, Args... >::value_t is_detected
Definition: STLExtras.h:125
Definition: Attributes.h:53
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
Definition: Matchers.h:175
bool match(Operation *op)
Definition: Matchers.h:185
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
Definition: Operation.h:246
bool match(Operation *op)
Definition: Matchers.h:107
IntegerAttr::ValueType * bind_value
Definition: Matchers.h:80
decltype(std::declval< T >().match(std::declval< OperationOrValue >())) has_operation_or_value_matcher_t
Definition: Matchers.h:131
Definition: Attributes.h:1193
detail::op_matcher< OpClass > m_Op()
Matches the given OpClass.
Definition: Matchers.h:212
The matcher that matches a certain kind of op.
Definition: Matchers.h:123
Definition: StandardTypes.h:256
Terminal matcher, always returns true.
Definition: Matchers.h:154
RecursivePatternMatcher(OperandMatchers... matchers)
Definition: Matchers.h:183
Definition: Matchers.h:79
U dyn_cast() const
Definition: Attributes.h:1347
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
Definition: Matchers.h:229
bool match(Operation *op)
Definition: Matchers.h:124
constant_op_binder(AttrT *bind_value)
Definition: Matchers.h:58
bool match(Value val) const
Definition: Matchers.h:161
Operation * getDefiningOp() const
Definition: Value.cpp:71
auto m_Val(Value v)
Definition: Matchers.h:256
APInt ValueType
Definition: Attributes.h:348
detail::constant_int_value_matcher< 0 > m_Zero()
Matches a constant scalar / vector splat / tensor splat integer zero.
Definition: Matchers.h:217
LogicalResult fold(ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
Attempt to fold this operation using the Op's registered foldHook.
Definition: Operation.cpp:603
Definition: StandardTypes.h:63
bool match(Operation *op)
Definition: Matchers.h:116
bool match(const Attribute &attr)
Definition: Matchers.h:42
Definition: Matchers.h:36