25 #ifndef TVM_TIR_EXPR_FUNCTOR_H_
26 #define TVM_TIR_EXPR_FUNCTOR_H_
74 template <
typename FType>
78 #define EXPR_FUNCTOR_DEFAULT \
79 { return VisitExprDefault_(op, std::forward<Args>(args)...); }
81 #define IR_EXPR_FUNCTOR_DISPATCH(OP) \
82 vtable.template set_dispatch<OP>([](const ObjectRef& n, TSelf* self, Args... args) { \
83 return self->VisitExpr_(static_cast<const OP*>(n.get()), std::forward<Args>(args)...); \
86 template <
typename R,
typename... Args>
104 return VisitExpr(n, std::forward<Args>(args)...);
113 static FType vtable = InitVTable();
114 return vtable(n,
this, std::forward<Args>(args)...);
119 return VisitExpr_(
static_cast<const VarNode*
>(op), std::forward<Args>(args)...);
154 LOG(FATAL) <<
"Do not have a default for " << op->
GetTypeKey();
159 static FType InitVTable() {
200 #undef IR_EXPR_FUNCTOR_DISPATCH
201 #undef EXPR_FUNCTOR_DEFAULT
208 using ExprFunctor::operator();
211 using ExprFunctor::VisitExpr;
254 using ExprFunctor::operator();
257 using ExprFunctor::VisitExpr;
Constant floating point literals in the program.
Definition: expr.h:548
Constant integer literals in the program.
Definition: expr.h:501
A dynamically dispatched functor on the type of the first argument.
Definition: functor.h:64
Reference to PrimExprNode.
Definition: expr.h:115
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
std::string GetTypeKey() const
Definition: object.h:184
a + b
Definition: expr.h:157
a && b
Definition: expr.h:450
Any shape.
Definition: expr.h:1104
Create a vector where all the elements are value.
Definition: expr.h:792
Load value from the high dimension buffer.
Definition: expr.h:627
Call node.
Definition: expr.h:881
Cast value from one data type to another.
Definition: expr.h:89
a / b in the C semnatics.
Definition: expr.h:211
a == b
Definition: expr.h:348
Definition: expr_functor.h:87
virtual R VisitExpr_(const CastNode *op, Args... args)
Definition: expr_functor.h:143
virtual R VisitExpr_(const BroadcastNode *op, Args... args)
Definition: expr_functor.h:147
virtual R VisitExpr_(const OrNode *op, Args... args)
Definition: expr_functor.h:141
virtual R VisitExpr_(const SelectNode *op, Args... args)
Definition: expr_functor.h:145
virtual R VisitExpr_(const VarNode *op, Args... args)
Definition: expr_functor.h:117
virtual R VisitExpr_(const GENode *op, Args... args)
Definition: expr_functor.h:139
virtual R VisitExpr_(const ProducerLoadNode *op, Args... args)
Definition: expr_functor.h:122
virtual R VisitExpr_(const MinNode *op, Args... args)
Definition: expr_functor.h:132
virtual R VisitExpr_(const AndNode *op, Args... args)
Definition: expr_functor.h:140
virtual R VisitExpr_(const LTNode *op, Args... args)
Definition: expr_functor.h:136
virtual R VisitExpr_(const LetNode *op, Args... args)
Definition: expr_functor.h:123
virtual R VisitExpr_(const RampNode *op, Args... args)
Definition: expr_functor.h:146
virtual ~ExprFunctor()
virtual destructor
Definition: expr_functor.h:96
virtual R VisitExpr_(const AnyNode *op, Args... args)
Definition: expr_functor.h:152
virtual R VisitExpr_(const EQNode *op, Args... args)
Definition: expr_functor.h:134
virtual R VisitExpr_(const MulNode *op, Args... args)
Definition: expr_functor.h:127
virtual R VisitExpr_(const ReduceNode *op, Args... args)
Definition: expr_functor.h:142
virtual R VisitExpr_(const DivNode *op, Args... args)
Definition: expr_functor.h:128
virtual R VisitExpr_(const BufferLoadNode *op, Args... args)
Definition: expr_functor.h:121
virtual R VisitExpr_(const IntImmNode *op, Args... args)
Definition: expr_functor.h:149
virtual R VisitExpr_(const CallNode *op, Args... args)
Definition: expr_functor.h:124
R operator()(const PrimExpr &n, Args... args)
Same as call.
Definition: expr_functor.h:103
virtual R VisitExpr_(const AddNode *op, Args... args)
Definition: expr_functor.h:125
virtual R VisitExpr_(const SubNode *op, Args... args)
Definition: expr_functor.h:126
virtual R VisitExpr_(const FloorDivNode *op, Args... args)
Definition: expr_functor.h:130
virtual R VisitExpr_(const GTNode *op, Args... args)
Definition: expr_functor.h:138
virtual R VisitExpr_(const LENode *op, Args... args)
Definition: expr_functor.h:137
R result_type
the result type of this functor
Definition: expr_functor.h:94
virtual R VisitExpr_(const ShuffleNode *op, Args... args)
Definition: expr_functor.h:148
virtual R VisitExpr_(const FloorModNode *op, Args... args)
Definition: expr_functor.h:131
virtual R VisitExprDefault_(const Object *op, Args...)
Definition: expr_functor.h:153
virtual R VisitExpr_(const NENode *op, Args... args)
Definition: expr_functor.h:135
virtual R VisitExpr_(const FloatImmNode *op, Args... args)
Definition: expr_functor.h:150
virtual R VisitExpr_(const ModNode *op, Args... args)
Definition: expr_functor.h:129
virtual R VisitExpr_(const NotNode *op, Args... args)
Definition: expr_functor.h:144
virtual R VisitExpr_(const SizeVarNode *op, Args... args)
Definition: expr_functor.h:118
virtual R VisitExpr_(const MaxNode *op, Args... args)
Definition: expr_functor.h:133
virtual R VisitExpr_(const StringImmNode *op, Args... args)
Definition: expr_functor.h:151
virtual R VisitExpr(const PrimExpr &n, Args... args)
The functor call.
Definition: expr_functor.h:112
A dynamical functor that dispatches on in the first Expr argument. You can use this as a more powerfu...
Definition: expr_functor.h:75
ExprMutator that mutates expressions.
Definition: expr_functor.h:252
PrimExpr VisitExpr_(const GTNode *op) override
PrimExpr VisitExpr_(const FloorDivNode *op) override
PrimExpr VisitExpr_(const LENode *op) override
PrimExpr VisitExpr_(const CastNode *op) override
PrimExpr VisitExpr_(const BroadcastNode *op) override
PrimExpr VisitExpr_(const SelectNode *op) override
PrimExpr VisitExpr_(const MinNode *op) override
PrimExpr VisitExpr_(const IntImmNode *op) override
PrimExpr VisitExpr_(const RampNode *op) override
PrimExpr VisitExpr_(const ReduceNode *op) override
PrimExpr VisitExpr_(const OrNode *op) override
PrimExpr VisitExpr_(const FloorModNode *op) override
PrimExpr VisitExpr_(const DivNode *op) override
PrimExpr VisitExpr_(const AddNode *op) override
PrimExpr VisitExpr_(const ProducerLoadNode *op) override
PrimExpr VisitExpr_(const CallNode *op) override
PrimExpr VisitExpr_(const ShuffleNode *op) override
PrimExpr VisitExpr_(const SubNode *op) override
PrimExpr VisitExpr_(const FloatImmNode *op) override
PrimExpr VisitExpr_(const EQNode *op) override
PrimExpr VisitExpr_(const NENode *op) override
PrimExpr VisitExpr_(const GENode *op) override
PrimExpr VisitExpr_(const MulNode *op) override
PrimExpr VisitExpr_(const LTNode *op) override
PrimExpr VisitExpr_(const StringImmNode *op) override
PrimExpr VisitExpr_(const ModNode *op) override
PrimExpr VisitExpr_(const AndNode *op) override
PrimExpr VisitExpr_(const BufferLoadNode *op) override
PrimExpr VisitExpr_(const SizeVarNode *op) override
PrimExpr VisitExpr_(const LetNode *op) override
PrimExpr VisitExpr_(const MaxNode *op) override
PrimExpr VisitExpr_(const VarNode *op) override
PrimExpr VisitExpr_(const AnyNode *op) override
PrimExpr VisitExpr_(const NotNode *op) override
ExprVisitor.
Definition: expr_functor.h:206
void VisitExpr_(const FloorModNode *op) override
void VisitExpr_(const LENode *op) override
void VisitExpr_(const ProducerLoadNode *op) override
void VisitExpr_(const NENode *op) override
void VisitExpr_(const OrNode *op) override
void VisitExpr_(const LetNode *op) override
void VisitExpr_(const CastNode *op) override
void VisitExpr_(const MulNode *op) override
void VisitExpr_(const RampNode *op) override
void VisitExpr_(const IntImmNode *op) override
void VisitExpr_(const ModNode *op) override
void VisitExpr_(const DivNode *op) override
void VisitExpr_(const SelectNode *op) override
void VisitExpr_(const SubNode *op) override
void VisitExpr_(const StringImmNode *op) override
void VisitExpr_(const FloorDivNode *op) override
void VisitExpr_(const SizeVarNode *op) override
void VisitExpr_(const AnyNode *op) override
void VisitExpr_(const GTNode *op) override
void VisitExpr_(const MaxNode *op) override
void VisitExpr_(const NotNode *op) override
void VisitExpr_(const BroadcastNode *op) override
void VisitExpr_(const FloatImmNode *op) override
void VisitExpr_(const EQNode *op) override
void VisitExpr_(const AndNode *op) override
void VisitExpr_(const GENode *op) override
void VisitExpr_(const VarNode *op) override
void VisitExpr_(const AddNode *op) override
void VisitExpr_(const CallNode *op) override
void VisitExpr_(const ReduceNode *op) override
void VisitExpr_(const BufferLoadNode *op) override
void VisitExpr_(const ShuffleNode *op) override
void VisitExpr_(const LTNode *op) override
void VisitExpr_(const MinNode *op) override
Floor division, floor(a/b)
Definition: expr.h:248
The remainder of the floordiv.
Definition: expr.h:265
a >= b
Definition: expr.h:433
a > b
Definition: expr.h:416
a < b
Definition: expr.h:382
Let binding. Bind var to value then evaluate body.
Definition: expr.h:834
max(a, b)
Definition: expr.h:299
min(a, b)
Definition: expr.h:282
a % b in the C semnatics.
Definition: expr.h:231
a * b
Definition: expr.h:191
a != b
Definition: expr.h:365
a || b
Definition: expr.h:490
Load value from the result produced by the producer.
Definition: expr.h:697
Construct a vector with lanes elements where its i-th element equals base + i * stride....
Definition: expr.h:747
Reduction operator.
Definition: expr.h:1039
return true_value if condition is true, otherwise return false_value.
Definition: expr.h:572
Shuffle instruction. vec = concat(vectors) result = (vec[indices[0]], vec[indices[1]] ....
Definition: expr.h:930
A variable node represent a tensor index size, whose value must be non-negative.
Definition: var.h:144
String constants, only used in asserts.
Definition: expr.h:53
a - b
Definition: expr.h:174
A variable node in the IR.
Definition: var.h:48
Defines the Functor data structures.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
a <= b
Definition: expr.h:399
#define IR_EXPR_FUNCTOR_DISPATCH(OP)
Definition: expr_functor.h:81
#define EXPR_FUNCTOR_DEFAULT
Definition: expr_functor.h:78