25 #ifndef TVM_RELAY_PATTERN_FUNCTOR_H_
26 #define TVM_RELAY_PATTERN_FUNCTOR_H_
32 #include <unordered_map>
53 template <
typename FType>
57 #define PATTERN_FUNCTOR_DEFAULT \
58 { return VisitPatternDefault_(op, std::forward<Args>(args)...); }
60 #define RELAY_PATTERN_FUNCTOR_DISPATCH(OP) \
61 vtable.template set_dispatch<OP>([](const ObjectRef& n, TSelf* self, Args... args) { \
62 return self->VisitPattern_(static_cast<const OP*>(n.get()), std::forward<Args>(args)...); \
65 template <
typename R,
typename... Args>
83 return VisitPattern(n, std::forward<Args>(args)...);
93 static FType vtable = InitVTable();
94 return vtable(n,
this, std::forward<Args>(args)...);
102 LOG(FATAL) <<
"Do not have a default for " << op->
GetTypeKey();
108 static FType InitVTable() {
161 std::unordered_map<Var, Var, ObjectPtrHash, ObjectPtrEqual> var_map_;
Managed reference to ConstructorNode.
Definition: adt.h:88
A dynamically dispatched functor on the type of the first argument.
Definition: functor.h:64
Managed reference to TypeNode.
Definition: type.h:93
PatternVar container node.
Definition: adt.h:150
Definition: pattern_functor.h:66
virtual R VisitPattern_(const PatternVarNode *op, Args... args)
Definition: pattern_functor.h:98
virtual ~PatternFunctor()
virtual destructor
Definition: pattern_functor.h:75
R operator()(const Pattern &n, Args... args)
Same as call.
Definition: pattern_functor.h:82
virtual R VisitPattern_(const PatternWildcardNode *op, Args... args)
Definition: pattern_functor.h:97
virtual R VisitPattern_(const PatternTupleNode *op, Args... args)
Definition: pattern_functor.h:100
R result_type
the result type of this functor
Definition: pattern_functor.h:73
virtual R VisitPattern(const Pattern &n, Args... args)
The functor call.
Definition: pattern_functor.h:91
virtual R VisitPatternDefault_(const Object *op, Args...)
Definition: pattern_functor.h:101
virtual R VisitPattern_(const PatternConstructorNode *op, Args... args)
Definition: pattern_functor.h:99
A dynamical functor on ADT patterns that dispatches on its first argument. You can use this as a more...
Definition: pattern_functor.h:54
A wrapper around ExprFunctor which functionally updates the AST.
Definition: pattern_functor.h:141
virtual Constructor VisitConstructor(const Constructor &c)
Used to visit the vars inside of patterns.
virtual Type VisitType(const Type &t)
Used to visit the types inside of patterns.
Pattern VisitPattern_(const PatternVarNode *op) override
Pattern VisitPattern_(const PatternConstructorNode *op) override
virtual Var VisitVar(const Var &v)
Used to visit the vars inside of patterns.
Pattern VisitPattern_(const PatternWildcardNode *op) override
Pattern VisitPattern_(const PatternTupleNode *op) override
Pattern Mutate(const Pattern &pat)
PatternVar container node.
Definition: adt.h:191
PatternVar container node.
Definition: adt.h:116
A simple visitor wrapper around PatternFunctor.
Definition: pattern_functor.h:125
void VisitPattern_(const PatternTupleNode *op) override
void VisitPattern_(const PatternConstructorNode *op) override
virtual void VisitVar(const Var &v)
void VisitPattern_(const PatternWildcardNode *op) override
virtual void VisitType(const Type &t)
virtual void VisitConstructor(const Constructor &c)
void VisitPattern_(const PatternVarNode *op) override
PatternWildcard container node.
Definition: adt.h:74
Pattern is the base type for an ADT match pattern in Relay.
Definition: adt.h:63
Base class of all object reference.
Definition: object.h:519
bool defined() const
Definition: object.h:552
base class of all object containers.
Definition: object.h:171
std::string GetTypeKey() const
Definition: object.h:184
Defines the Functor data structures.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
#define RELAY_PATTERN_FUNCTOR_DISPATCH(OP)
Definition: pattern_functor.h:60
#define PATTERN_FUNCTOR_DEFAULT
Definition: pattern_functor.h:57
Runtime ADT container types.
Common operators defined for Expr.