tvm
Loading...
Searching...
No Matches
pattern_match.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
67#ifndef TVM_IR_PRIM_PATTERN_MATCH_H_
68#define TVM_IR_PRIM_PATTERN_MATCH_H_
69
72#include <tvm/ir/prim/expr.h>
73#include <tvm/ir/prim/op.h>
74
75#include <cmath>
76#include <tuple>
77
78namespace tvm {
79template <>
81 public:
82 bool operator()(const PrimExpr& lhs, const PrimExpr& rhs) const {
83 if (lhs.same_as(rhs)) return true;
84 return prim::ExprDeepEqual()(lhs, rhs);
85 }
86};
87
88template <>
90 public:
91 bool operator()(const IntImm& lhs, const IntImm& rhs) const { return lhs->value == rhs->value; }
92};
93
94template <>
96 public:
97 bool operator()(const FloatImm& lhs, const FloatImm& rhs) const {
98 return std::fabs(lhs->value - rhs->value) < 1e-20;
99 }
100};
101
102template <>
104 public:
105 bool operator()(const Var& lhs, const Var& rhs) const { return lhs.same_as(rhs); }
106};
107
114template <typename T, typename DType,
115 typename = std::enable_if<std::is_base_of<T, PrimExpr>::value>>
116class PVarWithDataType : public PVarWithCheck<PVarWithDataType<T, DType>, T> {
117 public:
118 explicit PVarWithDataType(const DType& dtype) : dtype_(dtype) {}
119
120 bool Match_(const T& value) const { return dtype_.Match_(value.ty()->dtype); }
121
122 protected:
123 typename DType::Nested dtype_;
124};
125
129class PVecDataType : public PVarWithCheck<PVecDataType, DLDataType> {
130 public:
132 explicit PVecDataType(DLDataType elem_dtype) : elem_dtype_(elem_dtype) {}
133
134 bool Match_(DLDataType dtype) const { return dtype.code == elem_dtype_.code; }
135
136 protected:
137 DLDataType elem_dtype_;
138};
139
147template <typename OpType, typename TA, typename TB, bool kFoldConstants = true>
148class PBinaryExpr : public Pattern<PBinaryExpr<OpType, TA, TB, kFoldConstants>> {
149 public:
150 PBinaryExpr(const TA& a, const TB& b) : a_(a), b_(b) {}
151
152 void InitMatch_() const {
153 a_.InitMatch_();
154 b_.InitMatch_();
155 }
156
157 bool Match_(const ffi::ObjectRef& node) const {
158 using NodeType = typename OpType::ContainerType;
159 if (const NodeType* ptr = node.as<NodeType>()) {
160 if (!a_.Match_(ptr->a)) return false;
161 if (!b_.Match_(ptr->b)) return false;
162 return true;
163 } else {
164 return false;
165 }
166 }
167
168 PrimExpr Eval() const {
169 PrimExpr lhs = a_.Eval();
170 PrimExpr rhs = b_.Eval();
171 if constexpr (kFoldConstants) {
172 if (auto ret = prim::TryConstFold<OpType>(lhs, rhs)) return ret.value();
173 }
174 return OpType(lhs, rhs);
175 }
176
177 private:
178 typename TA::Nested a_;
179 typename TB::Nested b_;
180};
181
182template <typename TA>
183class PConstWithTypeLike : public Pattern<PConstWithTypeLike<TA>> {
184 public:
185 PConstWithTypeLike(const TA& ref, int64_t value) : ref_(ref), value_(value) {}
186
187 void InitMatch_() const {}
188
189 bool Match_(const ffi::ObjectRef& node) const {
190 if (const IntImmObj* ptr = node.as<IntImmObj>()) {
191 return ptr->value == value_;
192 } else {
193 return false;
194 }
195 }
196
197 PrimExpr Eval() const { return prim::MakeConst(ref_.Eval().ty(), value_); }
198
199 private:
200 typename TA::Nested ref_;
201 int64_t value_;
202};
203
204#define TVM_PATTERN_BINARY_OP_EX(FuncName, NodeName, CheckStep) \
205 template <typename TA, typename TB> \
206 inline PBinaryExpr<NodeName, TA, TB> FuncName(const Pattern<TA>& a, const Pattern<TB>& b) { \
207 CheckStep; \
208 return PBinaryExpr<NodeName, TA, TB>(a.derived(), b.derived()); \
209 } \
210 template <typename TA> \
211 inline PBinaryExpr<NodeName, TA, PConstWithTypeLike<TA>> FuncName(const Pattern<TA>& a, \
212 int64_t b) { \
213 CheckStep; \
214 return FuncName(a, PConstWithTypeLike<TA>(a.derived(), b)); \
215 } \
216 template <typename TA> \
217 inline PBinaryExpr<NodeName, PConstWithTypeLike<TA>, TA> FuncName(int64_t b, \
218 const Pattern<TA>& a) { \
219 CheckStep; \
220 return FuncName(PConstWithTypeLike<TA>(a.derived(), b), a); \
221 }
222
223#define TVM_PATTERN_BINARY_OP(FuncName, NodeName) TVM_PATTERN_BINARY_OP_EX(FuncName, NodeName, )
224
225// raise ambiguity error for operator overload of / and %
228
229// arithmetic expressions
240
241// Bitwise patterns preserve nonfolding construction during evaluation.
242#define TVM_PATTERN_BITWISE_OP(FuncName, NodeName) \
243 template <typename TA, typename TB> \
244 inline PBinaryExpr<NodeName, TA, TB, false> FuncName(const Pattern<TA>& a, \
245 const Pattern<TB>& b) { \
246 return PBinaryExpr<NodeName, TA, TB, false>(a.derived(), b.derived()); \
247 }
248
249TVM_PATTERN_BITWISE_OP(operator<<, prim::LShift);
254
255#undef TVM_PATTERN_BITWISE_OP
256
257// logical expressions
266
271template <typename TA>
272class PNotExpr : public Pattern<PNotExpr<TA>> {
273 public:
274 explicit PNotExpr(const TA& value) : value_(value) {}
275
276 void InitMatch_() const { value_.InitMatch_(); }
277
278 bool Match_(const ffi::ObjectRef& node) const {
279 if (const prim::NotObj* ptr = node.as<prim::NotObj>()) {
280 if (!value_.Match_(ptr->a)) return false;
281 return true;
282 } else {
283 return false;
284 }
285 }
286
287 PrimExpr Eval() const { return prim::Not(value_.Eval()); }
288
289 private:
290 typename TA::Nested value_;
291};
292
293template <typename TA>
294inline PNotExpr<TA> operator!(const Pattern<TA>& value) {
295 return PNotExpr<TA>(value.derived());
296}
297
302template <typename TA>
303class PBitwiseNotExpr : public Pattern<PBitwiseNotExpr<TA>> {
304 public:
305 explicit PBitwiseNotExpr(const TA& value) : value_(value) {}
306
307 void InitMatch_() const { value_.InitMatch_(); }
308
309 bool Match_(const ffi::ObjectRef& node) const {
310 if (const prim::BitwiseNotObj* ptr = node.as<prim::BitwiseNotObj>()) {
311 if (!value_.Match_(ptr->a)) return false;
312 return true;
313 } else {
314 return false;
315 }
316 }
317
318 PrimExpr Eval() const { return prim::BitwiseNot(value_.Eval()); }
319
320 private:
321 typename TA::Nested value_;
322};
323
324template <typename TA>
326 return PBitwiseNotExpr<TA>(value.derived());
327}
328
329// select
336template <typename TCond, typename TA, typename TB>
337class PSelectExpr : public Pattern<PSelectExpr<TCond, TA, TB>> {
338 public:
339 PSelectExpr(const TCond& condition, const TA& true_value, const TB& false_value)
340 : condition_(condition), true_value_(true_value), false_value_(false_value) {}
341
342 void InitMatch_() const {
343 condition_.InitMatch_();
344 true_value_.InitMatch_();
345 false_value_.InitMatch_();
346 }
347
348 bool Match_(const ffi::ObjectRef& node) const {
349 if (const prim::SelectObj* ptr = node.as<prim::SelectObj>()) {
350 if (!condition_.Match_(ptr->condition)) return false;
351 if (!true_value_.Match_(ptr->true_value)) return false;
352 if (!false_value_.Match_(ptr->false_value)) return false;
353 return true;
354 } else {
355 return false;
356 }
357 }
358
359 PrimExpr Eval() const {
360 return prim::Select(condition_.Eval(), true_value_.Eval(), false_value_.Eval());
361 }
362
363 private:
364 typename TCond::Nested condition_;
365 typename TA::Nested true_value_;
366 typename TB::Nested false_value_;
367};
368
382template <typename TCond, typename TA, typename TB>
384 const Pattern<TA>& true_value,
385 const Pattern<TB>& false_value) {
386 return PSelectExpr<TCond, TA, TB>(condition.derived(), true_value.derived(),
387 false_value.derived());
388}
389
395template <typename DType, typename TA>
396class PCastExpr : public Pattern<PCastExpr<DType, TA>> {
397 public:
398 PCastExpr(const TA& value, const DType& dtype) : dtype_(dtype), value_(value) {}
399
400 void InitMatch_() const {
401 dtype_.InitMatch_();
402 value_.InitMatch_();
403 }
404
405 bool Match_(const ffi::ObjectRef& node) const {
406 if (const prim::CastObj* ptr = node.as<prim::CastObj>()) {
407 if (!dtype_.Match_(ptr->ty.as_or_throw<PrimType>()->dtype)) return false;
408 if (!value_.Match_(ptr->value)) return false;
409 return true;
410 } else {
411 return false;
412 }
413 }
414
415 PrimExpr Eval() const { return prim::Cast(PrimType(dtype_.Eval()), value_.Eval()); }
416
417 private:
418 typename DType::Nested dtype_;
419 typename TA::Nested value_;
420};
421
433template <typename DType, typename TA>
434inline PCastExpr<DType, TA> cast(const Pattern<TA>& value, const Pattern<DType>& dtype) {
435 return PCastExpr<DType, TA>(value.derived(), dtype.derived());
436}
437
444template <typename TBase, typename TStride, typename TLanes>
445class PRampExpr : public Pattern<PRampExpr<TBase, TStride, TLanes>> {
446 public:
447 PRampExpr(const TBase& base, const TStride& stride, const TLanes& lanes)
448 : base_(base), stride_(stride), lanes_(lanes) {}
449
450 void InitMatch_() const {
451 base_.InitMatch_();
452 stride_.InitMatch_();
453 lanes_.InitMatch_();
454 }
455
456 bool Match_(const ffi::ObjectRef& node) const {
457 if (const prim::RampObj* ptr = node.as<prim::RampObj>()) {
458 if (!base_.Match_(ptr->base)) return false;
459 if (!stride_.Match_(ptr->stride)) return false;
460 if (!lanes_.Match_(ptr->lanes)) return false;
461 return true;
462 } else {
463 return false;
464 }
465 }
466
467 PrimExpr Eval() const { return prim::Ramp(base_.Eval(), stride_.Eval(), lanes_.Eval()); }
468
469 private:
470 typename TBase::Nested base_;
471 typename TStride::Nested stride_;
472 typename TLanes::Nested lanes_;
473};
474
488template <typename TBase, typename TStride, typename TLanes>
490 const Pattern<TStride>& stride,
491 const Pattern<TLanes>& lanes) {
492 return PRampExpr<TBase, TStride, TLanes>(base.derived(), stride.derived(), lanes.derived());
493}
494
495template <typename TBase>
502
508template <typename TA, typename TLanes>
509class PBroadcastExpr : public Pattern<PBroadcastExpr<TA, TLanes>> {
510 public:
511 PBroadcastExpr(const TA& value, const TLanes& lanes) : value_(value), lanes_(lanes) {}
512
513 void InitMatch_() const {
514 value_.InitMatch_();
515 lanes_.InitMatch_();
516 }
517
518 bool Match_(const ffi::ObjectRef& node) const {
519 if (const prim::BroadcastObj* ptr = node.as<prim::BroadcastObj>()) {
520 if (!value_.Match_(ptr->value)) return false;
521 if (!lanes_.Match_(ptr->lanes)) return false;
522 return true;
523 } else {
524 return false;
525 }
526 }
527
528 PrimExpr Eval() const { return prim::Broadcast(value_.Eval(), lanes_.Eval()); }
529
530 private:
531 typename TA::Nested value_;
532 typename TLanes::Nested lanes_;
533};
534
546template <typename TA, typename TLanes>
548 const Pattern<TLanes>& lanes) {
549 return PBroadcastExpr<TA, TLanes>(value.derived(), lanes.derived());
550}
551
552// internal namespace
553namespace detail {
554// implementation details for CallExpr
555template <bool stop, std::size_t I, typename F>
556struct tuple_for_each_dispatcher {
557 template <typename TTuple>
558 static void run(F& f, const TTuple& tuple) { // NOLINT(*)
559 f(I, std::get<I>(tuple));
560 tuple_for_each_dispatcher<(I + 1) == std::tuple_size<TTuple>::value, (I + 1), F>::run(f, tuple);
561 }
562};
563
564template <std::size_t I, typename F>
565struct tuple_for_each_dispatcher<true, I, F> {
566 template <typename TTuple>
567 static void run(F& f, const TTuple& tuple) {} // NOLINT(*)
568};
569
570template <typename F, typename TTuple>
571inline void tuple_for_each(F& f, const TTuple& tuple) { // NOLINT(*)
572 tuple_for_each_dispatcher<std::tuple_size<TTuple>::value == 0, 0, F>::run(f, tuple);
573}
574
575struct PCallExprInitMatchFunctor {
576 template <typename T>
577 void operator()(size_t i, const T& pattern) const {
578 pattern.InitMatch_();
579 }
580};
581
582struct PCallExprMatchFunctor {
583 const CallObj* call_;
584 bool matched_{true};
585
586 explicit PCallExprMatchFunctor(const CallObj* call) : call_(call) {}
587
588 template <typename T>
589 void operator()(size_t i, const T& pattern) {
590 matched_ = matched_ && pattern.Match_(call_->args[i]);
591 }
592};
593
594struct PCallExprEvalArgsFunctor {
595 ffi::Array<PrimExpr> args_;
596
597 template <typename T>
598 void operator()(size_t i, const T& pattern) {
599 args_.push_back(pattern.Eval());
600 }
601};
602} // namespace detail
603
611template <typename Op, typename... TArgs>
612class PCallExpr : public Pattern<PCallExpr<Op, TArgs...>> {
613 public:
614 explicit PCallExpr(const TArgs&... args) : args_(args...) {}
615
616 void InitMatch_() const {
617 detail::PCallExprInitMatchFunctor finit;
618 detail::tuple_for_each(finit, args_);
619 }
620
621 bool Match_(const ffi::ObjectRef& node) const {
622 if (const CallObj* ptr = node.as<CallObj>()) {
623 if (ptr->args.size() != sizeof...(TArgs)) return false;
624 if (!ptr->op.same_as(Op::GetOp())) return false;
625 detail::PCallExprMatchFunctor fmatch(ptr);
626 detail::tuple_for_each(fmatch, args_);
627 return fmatch.matched_;
628 } else {
629 return false;
630 }
631 }
632
633 PrimExpr Eval() const {
634 detail::PCallExprEvalArgsFunctor feval_args;
635 detail::tuple_for_each(feval_args, args_);
636 return Op::Eval(feval_args.args_);
637 }
638
639 private:
640 std::tuple<typename TArgs::Nested...> args_;
641};
642
643// if_then_else
645 static PrimExpr Eval(ffi::Array<PrimExpr> args) {
646 return Call(args[1].ty(), GetOp(), args).as_or_throw<PrimExpr>();
647 }
648 static const Op& GetOp() { return prim::if_then_else_op(); }
649};
650
664template <typename TCond, typename TA, typename TB>
666 const Pattern<TA>& true_value,
667 const Pattern<TB>& false_value) {
668 return PCallExpr<PIfThenElseOp, TCond, TA, TB>(cond.derived(), true_value.derived(),
669 false_value.derived());
670}
671
672} // namespace tvm
673#endif // TVM_IR_PRIM_PATTERN_MATCH_H_
TIR expressions.
Shared primitive construction and constant helpers.
Call corresponds to callable invocation.
Definition expr.h:788
ffi::Array< Expr > args
The arguments of the call.
Definition expr.h:802
Managed reference to CallObj.
Definition expr.h:825
Managed reference class to FloatImmObj.
Definition expr.h:411
Constant integer literals in the program.
Definition expr.h:314
Managed reference class to IntImmObj.
Definition expr.h:331
Reference-counted handle to a canonical named operator.
Definition op.h:140
Pattern binary expression.
Definition pattern_match.h:148
void InitMatch_() const
Definition pattern_match.h:152
PrimExpr Eval() const
Definition pattern_match.h:168
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:157
PBinaryExpr(const TA &a, const TB &b)
Definition pattern_match.h:150
Pattern bitwise not expression.
Definition pattern_match.h:303
PrimExpr Eval() const
Definition pattern_match.h:318
PBitwiseNotExpr(const TA &value)
Definition pattern_match.h:305
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:309
void InitMatch_() const
Definition pattern_match.h:307
Pattern broadcast expression.
Definition pattern_match.h:509
PBroadcastExpr(const TA &value, const TLanes &lanes)
Definition pattern_match.h:511
void InitMatch_() const
Definition pattern_match.h:513
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:518
PrimExpr Eval() const
Definition pattern_match.h:528
Pattern CallExpr expression.
Definition pattern_match.h:612
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:621
void InitMatch_() const
Definition pattern_match.h:616
PrimExpr Eval() const
Definition pattern_match.h:633
PCallExpr(const TArgs &... args)
Definition pattern_match.h:614
Pattern cast expression.
Definition pattern_match.h:396
PCastExpr(const TA &value, const DType &dtype)
Definition pattern_match.h:398
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:405
PrimExpr Eval() const
Definition pattern_match.h:415
void InitMatch_() const
Definition pattern_match.h:400
Definition pattern_match.h:183
void InitMatch_() const
Definition pattern_match.h:187
PConstWithTypeLike(const TA &ref, int64_t value)
Definition pattern_match.h:185
PrimExpr Eval() const
Definition pattern_match.h:197
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:189
bool operator()(const FloatImm &lhs, const FloatImm &rhs) const
Definition pattern_match.h:97
bool operator()(const IntImm &lhs, const IntImm &rhs) const
Definition pattern_match.h:91
bool operator()(const PrimExpr &lhs, const PrimExpr &rhs) const
Definition pattern_match.h:82
bool operator()(const Var &lhs, const Var &rhs) const
Definition pattern_match.h:105
Default deep equality checker.
Definition pattern_match.h:122
Pattern not expression.
Definition pattern_match.h:272
void InitMatch_() const
Definition pattern_match.h:276
PNotExpr(const TA &value)
Definition pattern_match.h:274
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:278
PrimExpr Eval() const
Definition pattern_match.h:287
Pattern ramp expression.
Definition pattern_match.h:445
PrimExpr Eval() const
Definition pattern_match.h:467
PRampExpr(const TBase &base, const TStride &stride, const TLanes &lanes)
Definition pattern_match.h:447
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:456
void InitMatch_() const
Definition pattern_match.h:450
Pattern select expression.
Definition pattern_match.h:337
PrimExpr Eval() const
Definition pattern_match.h:359
void InitMatch_() const
Definition pattern_match.h:342
bool Match_(const ffi::ObjectRef &node) const
Definition pattern_match.h:348
PSelectExpr(const TCond &condition, const TA &true_value, const TB &false_value)
Definition pattern_match.h:339
Wrapper for pattern variable container with extra match logic.
Definition pattern_match.h:185
Pattern variable container with expr type check.
Definition pattern_match.h:116
DType::Nested dtype_
Definition pattern_match.h:123
bool Match_(const T &value) const
Definition pattern_match.h:120
PVarWithDataType(const DType &dtype)
Definition pattern_match.h:118
Pattern variable container for data type with lanes.
Definition pattern_match.h:129
PVecDataType(DLDataType elem_dtype)
construct vector dtype placeholder with element type check
Definition pattern_match.h:132
DLDataType elem_dtype_
Definition pattern_match.h:137
bool Match_(DLDataType dtype) const
Definition pattern_match.h:134
Base class of all the patterns.
Definition pattern_match.h:63
const Derived & derived() const
Definition pattern_match.h:114
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
Definition type.h:182
Managed reference to VarObj.
Definition expr.h:571
Managed reference to AddObj.
Definition expr.h:118
Managed reference to AndObj.
Definition expr.h:578
Managed reference to BitwiseAndObj.
Definition expr.h:181
~a
Definition expr.h:649
Managed reference to BitwiseNotObj.
Definition expr.h:667
Managed reference to BitwiseOrObj.
Definition expr.h:202
Managed reference to BitwiseXorObj.
Definition expr.h:223
Create a vector where all the elements are value.
Definition vector_expr.h:82
Managed reference to BroadcastObj.
Definition vector_expr.h:104
Cast value from one data type to another.
Definition expr.h:56
Managed reference to CastObj.
Definition expr.h:74
Managed reference to DivObj.
Definition expr.h:290
Managed reference to EQObj.
Definition expr.h:442
Managed reference to FloorDivObj.
Definition expr.h:335
Managed reference to FloorModObj.
Definition expr.h:356
Managed reference to GEObj.
Definition expr.h:547
Managed reference to GTObj.
Definition expr.h:526
Managed reference to LEObj.
Definition expr.h:505
Managed reference to LTObj.
Definition expr.h:484
Managed reference to MaxObj.
Definition expr.h:398
Managed reference to MinObj.
Definition expr.h:377
Managed reference to ModObj.
Definition expr.h:314
Managed reference to MulObj.
Definition expr.h:266
Managed reference to NEObj.
Definition expr.h:463
!a
Definition expr.h:620
Managed reference to NotObj.
Definition expr.h:638
Managed reference to OrObj.
Definition expr.h:609
Managed reference to RShiftObj.
Definition expr.h:160
Construct a vector with lanes elements where its i-th element equals base + i * stride....
Definition vector_expr.h:45
Managed reference to RampObj.
Definition vector_expr.h:71
return true_value if condition is true, otherwise return false_value.
Definition expr.h:684
Managed reference to SelectObj.
Definition expr.h:712
Managed reference to SubObj.
Definition expr.h:244
Centralized location for constant folding.
PrimExpr MakeConst(PrimType dtype, ValueType value, Location loc=UnknownLoc())
Make a const value with certain data type.
Definition op.h:814
TVM_TIRX_DLL const Op & if_then_else_op()
Same as select, used for unsafe memory access.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
PBroadcastExpr< TA, TLanes > broadcast(const Pattern< TA > &value, const Pattern< TLanes > &lanes)
Construct a broadcast pattern.
Definition pattern_match.h:547
void DivAmbiguityError(const TA &a)
Helper function to raise a compiler error about division ambiguity.
Definition op.h:926
TVM_TIRX_DLL PrimExpr operator!(PrimExpr a)
not
TVM_TIRX_DLL PrimExpr if_then_else(PrimExpr cond, PrimExpr true_value, PrimExpr false_value, Location loc=UnknownLoc())
Conditional expression.
PSelectExpr< TCond, TA, TB > select(const Pattern< TCond > &condition, const Pattern< TA > &true_value, const Pattern< TB > &false_value)
Construct a select pattern.
Definition pattern_match.h:383
TVM_TIRX_DLL PrimExpr truncdiv(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute trunc(a / b)
TVM_TIRX_DLL PrimExpr operator~(PrimExpr a)
take bitwise negation of two values
TVM_TIRX_DLL PrimExpr div(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute division in C semantics.
PCastExpr< DType, TA > cast(const Pattern< TA > &value, const Pattern< DType > &dtype)
Construct a cast pattern.
Definition pattern_match.h:434
TVM_TIRX_DLL PrimExpr floormod(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute the remainder of floordiv
TVM_TIRX_DLL PrimExpr truncmod(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute the remainder of truncdiv
TVM_TIRX_DLL PrimExpr floordiv(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
compute floor(a / b)
PRampExpr< TBase, TStride, TLanes > ramp(const Pattern< TBase > &base, const Pattern< TStride > &stride, const Pattern< TLanes > &lanes)
Construct a ramp pattern.
Definition pattern_match.h:489
PrimExpr max(PrimExpr source, ffi::Array< s_tir::IterVar > axis, ffi::Array< PrimExpr > init={}, Location loc=UnknownLoc())
max of source expression over axis
PrimExpr min(PrimExpr source, ffi::Array< s_tir::IterVar > axis, ffi::Array< PrimExpr > init={}, Location loc=UnknownLoc())
max of source expression over axis
Shared expression-template pattern and capture protocol.
#define TVM_PATTERN_BINARY_OP(FuncName, NodeName)
Definition pattern_match.h:223
#define TVM_PATTERN_BINARY_OP_EX(FuncName, NodeName, CheckStep)
Definition pattern_match.h:204
#define TVM_PATTERN_BITWISE_OP(FuncName, NodeName)
Definition pattern_match.h:242
Definition pattern_match.h:644
static PrimExpr Eval(ffi::Array< PrimExpr > args)
Definition pattern_match.h:645
static const Op & GetOp()
Definition pattern_match.h:648
Compare two expressions recursively and check if they are equal to each other without var remapping.
Definition expr.h:795