|
tvm
|
Public tool for expression-template based pattern matching. More...
#include <tvm/ir/pattern_match.h>#include <tvm/ir/prim/const_fold.h>#include <tvm/ir/prim/expr.h>#include <tvm/ir/prim/op.h>#include <cmath>#include <tuple>Go to the source code of this file.
Classes | |
| class | tvm::PEqualChecker< PrimExpr > |
| class | tvm::PEqualChecker< IntImm > |
| class | tvm::PEqualChecker< FloatImm > |
| class | tvm::PEqualChecker< Var > |
| class | tvm::PVarWithDataType< T, DType, typename > |
| Pattern variable container with expr type check. More... | |
| class | tvm::PVecDataType |
| Pattern variable container for data type with lanes. More... | |
| class | tvm::PBinaryExpr< OpType, TA, TB, kFoldConstants > |
| Pattern binary expression. More... | |
| class | tvm::PConstWithTypeLike< TA > |
| class | tvm::PNotExpr< TA > |
| Pattern not expression. More... | |
| class | tvm::PBitwiseNotExpr< TA > |
| Pattern bitwise not expression. More... | |
| class | tvm::PSelectExpr< TCond, TA, TB > |
| Pattern select expression. More... | |
| class | tvm::PCastExpr< DType, TA > |
| Pattern cast expression. More... | |
| class | tvm::PRampExpr< TBase, TStride, TLanes > |
| Pattern ramp expression. More... | |
| class | tvm::PBroadcastExpr< TA, TLanes > |
| Pattern broadcast expression. More... | |
| class | tvm::PCallExpr< Op, TArgs > |
| Pattern CallExpr expression. More... | |
| struct | tvm::PIfThenElseOp |
Namespaces | |
| namespace | tvm |
| An object that builds and maintains block scope and StmtSref mapping for Dependence analysis. | |
| namespace | tvm::detail |
Macros | |
| #define | TVM_PATTERN_BINARY_OP_EX(FuncName, NodeName, CheckStep) |
| #define | TVM_PATTERN_BINARY_OP(FuncName, NodeName) TVM_PATTERN_BINARY_OP_EX(FuncName, NodeName, ) |
| #define | TVM_PATTERN_BITWISE_OP(FuncName, NodeName) |
Functions | |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Div, TA, TB > | tvm::operator/ (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Div, TA, PConstWithTypeLike< TA > > | tvm::operator/ (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Div, PConstWithTypeLike< TA >, TA > | tvm::operator/ (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Mod, TA, TB > | tvm::operator% (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Mod, TA, PConstWithTypeLike< TA > > | tvm::operator% (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Mod, PConstWithTypeLike< TA >, TA > | tvm::operator% (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Add, TA, TB > | tvm::operator+ (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Add, TA, PConstWithTypeLike< TA > > | tvm::operator+ (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Add, PConstWithTypeLike< TA >, TA > | tvm::operator+ (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Sub, TA, TB > | tvm::operator- (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Sub, TA, PConstWithTypeLike< TA > > | tvm::operator- (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Sub, PConstWithTypeLike< TA >, TA > | tvm::operator- (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Mul, TA, TB > | tvm::operator* (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Mul, TA, PConstWithTypeLike< TA > > | tvm::operator* (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Mul, PConstWithTypeLike< TA >, TA > | tvm::operator* (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Min, TA, TB > | tvm::min (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Min, TA, PConstWithTypeLike< TA > > | tvm::min (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Min, PConstWithTypeLike< TA >, TA > | tvm::min (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Max, TA, TB > | tvm::max (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Max, TA, PConstWithTypeLike< TA > > | tvm::max (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Max, PConstWithTypeLike< TA >, TA > | tvm::max (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Div, TA, TB > | tvm::div (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Div, TA, PConstWithTypeLike< TA > > | tvm::div (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Div, PConstWithTypeLike< TA >, TA > | tvm::div (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Div, TA, TB > | tvm::truncdiv (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Div, TA, PConstWithTypeLike< TA > > | tvm::truncdiv (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Div, PConstWithTypeLike< TA >, TA > | tvm::truncdiv (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Mod, TA, TB > | tvm::truncmod (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Mod, TA, PConstWithTypeLike< TA > > | tvm::truncmod (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Mod, PConstWithTypeLike< TA >, TA > | tvm::truncmod (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::FloorDiv, TA, TB > | tvm::floordiv (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::FloorDiv, TA, PConstWithTypeLike< TA > > | tvm::floordiv (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::FloorDiv, PConstWithTypeLike< TA >, TA > | tvm::floordiv (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::FloorMod, TA, TB > | tvm::floormod (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::FloorMod, TA, PConstWithTypeLike< TA > > | tvm::floormod (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::FloorMod, PConstWithTypeLike< TA >, TA > | tvm::floormod (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::LShift, TA, TB, false > | tvm::operator<< (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::RShift, TA, TB, false > | tvm::operator>> (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::BitwiseAnd, TA, TB, false > | tvm::operator& (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::BitwiseOr, TA, TB, false > | tvm::operator| (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::BitwiseXor, TA, TB, false > | tvm::operator^ (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::GT, TA, TB > | tvm::operator> (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::GT, TA, PConstWithTypeLike< TA > > | tvm::operator> (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::GT, PConstWithTypeLike< TA >, TA > | tvm::operator> (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::GE, TA, TB > | tvm::operator>= (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::GE, TA, PConstWithTypeLike< TA > > | tvm::operator>= (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::GE, PConstWithTypeLike< TA >, TA > | tvm::operator>= (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::LT, TA, TB > | tvm::operator< (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::LT, TA, PConstWithTypeLike< TA > > | tvm::operator< (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::LT, PConstWithTypeLike< TA >, TA > | tvm::operator< (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::LE, TA, TB > | tvm::operator<= (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::LE, TA, PConstWithTypeLike< TA > > | tvm::operator<= (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::LE, PConstWithTypeLike< TA >, TA > | tvm::operator<= (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::EQ, TA, TB > | tvm::operator== (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::EQ, TA, PConstWithTypeLike< TA > > | tvm::operator== (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::EQ, PConstWithTypeLike< TA >, TA > | tvm::operator== (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::NE, TA, TB > | tvm::operator!= (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::NE, TA, PConstWithTypeLike< TA > > | tvm::operator!= (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::NE, PConstWithTypeLike< TA >, TA > | tvm::operator!= (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::And, TA, TB > | tvm::operator&& (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::And, TA, PConstWithTypeLike< TA > > | tvm::operator&& (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::And, PConstWithTypeLike< TA >, TA > | tvm::operator&& (int64_t b, const Pattern< TA > &a) |
| template<typename TA , typename TB > | |
| PBinaryExpr< prim::Or, TA, TB > | tvm::operator|| (const Pattern< TA > &a, const Pattern< TB > &b) |
| template<typename TA > | |
| PBinaryExpr< prim::Or, TA, PConstWithTypeLike< TA > > | tvm::operator|| (const Pattern< TA > &a, int64_t b) |
| template<typename TA > | |
| PBinaryExpr< prim::Or, PConstWithTypeLike< TA >, TA > | tvm::operator|| (int64_t b, const Pattern< TA > &a) |
| template<typename TA > | |
| PNotExpr< TA > | tvm::operator! (const Pattern< TA > &value) |
| template<typename TA > | |
| PBitwiseNotExpr< TA > | tvm::operator~ (const Pattern< TA > &value) |
| template<typename TCond , typename TA , typename TB > | |
| PSelectExpr< TCond, TA, TB > | tvm::select (const Pattern< TCond > &condition, const Pattern< TA > &true_value, const Pattern< TB > &false_value) |
| Construct a select pattern. | |
| template<typename DType , typename TA > | |
| PCastExpr< DType, TA > | tvm::cast (const Pattern< TA > &value, const Pattern< DType > &dtype) |
| Construct a cast pattern. | |
| template<typename TBase , typename TStride , typename TLanes > | |
| PRampExpr< TBase, TStride, TLanes > | tvm::ramp (const Pattern< TBase > &base, const Pattern< TStride > &stride, const Pattern< TLanes > &lanes) |
| Construct a ramp pattern. | |
| template<typename TBase > | |
| PRampExpr< TBase, PConstWithTypeLike< TBase >, PConstWithTypeLike< TBase > > | tvm::ramp (const Pattern< TBase > &base, int stride, int lanes) |
| template<typename TA , typename TLanes > | |
| PBroadcastExpr< TA, TLanes > | tvm::broadcast (const Pattern< TA > &value, const Pattern< TLanes > &lanes) |
| Construct a broadcast pattern. | |
| template<typename TCond , typename TA , typename TB > | |
| PCallExpr< PIfThenElseOp, TCond, TA, TB > | tvm::if_then_else (const Pattern< TCond > &cond, const Pattern< TA > &true_value, const Pattern< TB > &false_value) |
| Construct a if_then_else pattern. | |
Public tool for expression-template based pattern matching.
It helps to simplify pattern matching and rewrites. All the patterns are generated via expression template during compile time, so the result code should be as efficient as manually written pattern match code.
The code below shows how to use the pattern matcher.
\rst .. code-block:: cpp
// max(x + z, y + z) => max(x, y) + z tvm::PVar<PrimExpr> x, y, z;
// The following code tries to match the declared pattern. // Match will fill the result of match into PVar if successful. // Note that z occurs twice in the pattern, // an equality check is performed to ensure each occurance of z // is equivalent to each other. if (max(x + z, y + z).Match(expr)) { // Eval evaluates a pattern with the current matched value. // The filled value is valid until the next call to Match. return (max(x, y) + z).Eval(); }
tvm::PrimVar tx("tx"), ty("ty"); tvm::PVar<IntImm> c; tvm::PVar<Var> v; // We can match integer and Var, both of which are // special case container of Expr TVM_FFI_ICHECK((v * c).Match(tx * 3)); TVM_FFI_ICHECK_EQ(c.Eval()->value, 3); // cannot match c to ty TVM_FFI_ICHECK(!(v * c).Match(tx * ty));
\endrst
Please be aware that the filled value in a PVar can be overriden in the next call to Match.
| #define TVM_PATTERN_BINARY_OP | ( | FuncName, | |
| NodeName | |||
| ) | TVM_PATTERN_BINARY_OP_EX(FuncName, NodeName, ) |
| #define TVM_PATTERN_BINARY_OP_EX | ( | FuncName, | |
| NodeName, | |||
| CheckStep | |||
| ) |
| #define TVM_PATTERN_BITWISE_OP | ( | FuncName, | |
| NodeName | |||
| ) |