15 #ifndef MLIR_IR_MATCHERS_H 16 #define MLIR_IR_MATCHERS_H 33 AttrClass>::type::ValueType,
43 if (
auto intAttr = attr.
dyn_cast<AttrClass>()) {
44 *bind_value = intAttr.getValue();
65 template <
typename AttrT>
83 assert(
succeeded(result) &&
"expected ConstantLike op to be foldable");
85 if (
auto attr = foldedOp.front().get<
Attribute>().dyn_cast<AttrT>()) {
110 if (type.isa<VectorType, RankedTensorType>()) {
123 bool (*predicate)(
const APFloat &);
126 APFloat
value(APFloat::Bogus());
145 if (type.isa<IntegerType, IndexType>())
147 if (type.isa<VectorType, RankedTensorType>()) {
160 bool (*predicate)(
const APInt &);
169 template <
typename OpClass>
176 template <
typename T,
typename OperationOrValue>
178 decltype(std::declval<T>().
match(std::declval<OperationOrValue>()));
181 template <
typename MatcherClass>
182 typename std::enable_if_t<
191 template <
typename MatcherClass>
192 typename std::enable_if_t<
198 return matcher.match(defOp);
224 template <
typename TupleT,
class CallbackT, std::size_t... Is>
226 std::index_sequence<Is...>) {
227 (
void)std::initializer_list<int>{
229 (callback(std::integral_constant<std::size_t, Is>{}, std::get<Is>(tuple)),
233 template <
typename... Tys,
typename CallbackT>
234 constexpr
void enumerate(std::tuple<Tys...> &tuple, CallbackT &&callback) {
236 std::make_index_sequence<
sizeof...(Tys)>{});
240 template <
typename OpType,
typename... OperandMatchers>
243 : operandMatchers(matchers...) {}
245 if (!isa<OpType>(op) || op->
getNumOperands() !=
sizeof...(OperandMatchers))
248 enumerate(operandMatchers, [&](
size_t index,
auto &matcher) {
265 template <
typename AttrT>
273 return {[](
const APFloat &
value) {
return value.isZero(); }};
278 return {[](
const APFloat &
value) {
return value.isPosZero(); }};
283 return {[](
const APFloat &
value) {
return value.isNegZero(); }};
288 return {[](
const APFloat &
value) {
289 return APFloat(
value.getSemantics(), 1) ==
value;
296 return {[](
const APFloat &
value) {
297 return !
value.isNegative() &&
value.isInfinity();
304 return {[](
const APFloat &
value) {
305 return value.isNegative() &&
value.isInfinity();
311 return {[](
const APInt &
value) {
return 0 ==
value; }};
317 return {[](
const APInt &
value) {
return 0 !=
value; }};
322 return {[](
const APInt &
value) {
return 1 ==
value; }};
326 template <
typename OpClass>
332 template <
typename Pattern>
336 return const_cast<Pattern &>(pattern).match(op);
341 template <
typename Pattern>
360 template <
typename OpType,
typename... Matchers>
361 auto m_Op(Matchers... matchers) {
373 #endif // MLIR_IR_MATCHERS_H TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
detail::constant_float_predicate_matcher m_NegInfFloat()
Matches a constant scalar / vector splat / tensor splat float negative infinity.
constexpr void enumerateImpl(TupleT &&tuple, CallbackT &&callback, std::index_sequence< Is... >)
The matcher that matches operations that have the ConstantLike trait, and binds the folded attribute ...
detail::constant_int_op_binder m_ConstantInt(IntegerAttr::ValueType *bind_value)
Matches a constant holding a scalar/vector/tensor integer (splat) and writes the integer value to bin...
Operation is a basic unit of execution within MLIR.
Binds to a specific value and matches it.
bool match(Operation *op)
bool match(Value op) const
Value getOperand(unsigned idx)
detail::constant_float_predicate_matcher m_PosZeroFloat()
Matches a constant scalar / vector splat / tensor splat float positive zero.
static bool isConstantLike(Operation *op)
Check to see if the specified operation is ConstantLike.
unsigned getNumOperands()
attr_value_binder(ValueType *bv)
Creates a matcher instance that binds the value to bv if match succeeds.
std::enable_if_t< llvm::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.
detail::constant_float_op_binder m_ConstantFloat(FloatAttr::ValueType *bind_value)
Matches a constant holding a scalar/vector/tensor float (splat) and writes the float value to bind_va...
constant_int_op_binder(IntegerAttr::ValueType *bv)
Creates a matcher instance that binds the value to bv if match succeeds.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value...
detail::constant_float_predicate_matcher m_NegZeroFloat()
Matches a constant scalar / vector splat / tensor splat float negative zero.
constant_float_op_binder(FloatAttr::ValueType *bv)
Creates a matcher instance that binds the value to bv if match succeeds.
static constexpr const bool value
PatternMatcherValue(Value val)
This class contains all of the data related to a pattern, but does not contain any methods or logic f...
The matcher that matches operations that have the ConstantLike trait.
RecursivePatternMatcher that composes.
detail::constant_float_predicate_matcher m_AnyZeroFloat()
Matches a constant scalar / vector splat / tensor splat float (both positive and negative) zero...
bool match(Operation *op)
This class represents an efficient way to signal success or failure.
std::tuple< OperandMatchers... > operandMatchers
bool match(Value op) const
bool match(Operation *op)
detail::constant_float_predicate_matcher m_PosInfFloat()
Matches a constant scalar / vector splat / tensor splat float positive infinity.
detail::constant_float_predicate_matcher m_OneFloat()
Matches a constant scalar / vector splat / tensor splat float ones.
Attributes are known-constant values of operations.
The matcher that matches a constant scalar / vector splat / tensor splat float operation and binds th...
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
bool match(Operation *op)
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
constant_op_binder()
Creates a matcher instance that doesn't bind if match succeeds.
detail::constant_int_predicate_matcher m_Zero()
Matches a constant scalar / vector splat / tensor splat integer zero.
detail::constant_op_matcher m_Constant()
Matches a constant foldable operation.
IntegerAttr::ValueType * bind_value
bool match(Operation *op)
decltype(std::declval< T >().match(std::declval< OperationOrValue >())) has_operation_or_value_matcher_t
Trait to check whether T provides a 'match' method with type OperationOrValue.
detail::constant_int_predicate_matcher m_One()
Matches a constant scalar / vector splat / tensor splat integer one.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
An attribute that represents a reference to a splat vector or tensor constant, meaning all of the ele...
detail::op_matcher< OpClass > m_Op()
Matches the given OpClass.
The matcher that matches a certain kind of op.
Terminal matcher, always returns true.
AnyCapturedValueMatcher(Value *what)
Type getType() const
Return the type of this value.
RecursivePatternMatcher(OperandMatchers... matchers)
The matcher that matches a constant scalar / vector splat / tensor splat integer operation and binds ...
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
bool match(Operation *op)
The matcher that matches a given target constant scalar / vector splat / tensor splat integer value t...
The matcher that matches a given target constant scalar / vector splat / tensor splat float value tha...
constant_op_binder(AttrT *bind_value)
Creates a matcher instance that binds the constant attribute value to bind_value if match succeeds...
bool match(Value val) const
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
LogicalResult fold(ArrayRef< Attribute > operands, SmallVectorImpl< OpFoldResult > &results)
Attempt to fold this operation with the specified constant operand values.
unsigned getNumResults()
Return the number of results held by this operation.
bool match(Operation *op)
detail::constant_int_predicate_matcher m_NonZero()
Matches a constant scalar / vector splat / tensor splat integer that is any non-zero value...
bool match(const Attribute &attr)
This class provides the API for a sub-set of ops that are known to be constant-like.
FloatAttr::ValueType * bind_value
The matcher that matches a certain kind of Attribute and binds the value inside the Attribute...
bool match(Operation *op)
Terminal matcher, always returns true.