tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tvm::tir::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...

Collaboration diagram for tvm::tir::ExprFunctor< FType >:

Detailed Description

template<typename FType>
class tvm::tir::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.
class MyExprFunctor
: public tir::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");
ICHECK_EQ(f(x + 1, 2), 3);
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: