tvm
Loading...
Searching...
No Matches
tvm::tirx::ExprFunctor< FType > Class Template Reference

A dynamical functor that dispatches on in the first Expr argument. You can use this as a more powerful Visitor, since it allows you to define function signatures of Visit Function. More...

Inheritance diagram for tvm::tirx::ExprFunctor< FType >:
Collaboration diagram for tvm::tirx::ExprFunctor< FType >:

Detailed Description

template<typename FType>
class tvm::tirx::ExprFunctor< FType >

A dynamical functor that dispatches on in the first Expr argument. You can use this as a more powerful Visitor, since it allows you to define function signatures of Visit Function.

This helps you to avoid to book-keep return value of Visitor via state, which can cause bugs easily when state is incorrectly maintained.

// A functor that set variable to b. and calculate results.
: public tirx::ExprFunctor<int(const Expr&, int)> {
public:
int VisitExpr_(const Variable* op, int b) final {
return b;
}
int VisitExpr_(const IntImm* op, int b) final {
return op->value;
}
int VisitExpr_(const Add* op, int b) final {
return Visit(op->a, b) + Visit(op->b, b);
}
};
MyExprFunctor f;
Var x("x");
TVM_FFI_ICHECK_EQ(f(x + 1, 2), 3);
Managed reference class to IntImmNode.
Definition expr.h:504
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
A dynamical functor that dispatches on in the first Expr argument. You can use this as a more powerfu...
Definition expr_functor.h:76
tvm::Var Var
Definition var.h:38
Note
Why do we need this more powerful Functor:

We often need to implement a transformer tasks. Say we want to take Expr and transform it to some analysis result, This easily be done incorrectly using plain Visitor. See IRVisitor's document for possible error cases.

Template Parameters
FTypefunction signiture This type if only defined for FType with function signiture R(const Expr&, Args...)

The documentation for this class was generated from the following file: