tvm
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tvm::relay::MixedModeMutator Class Reference

Non-recursive DFS Graph Traversal for Custom Rewriting Passes. More...

#include <expr_functor.h>

Inheritance diagram for tvm::relay::MixedModeMutator:
Collaboration diagram for tvm::relay::MixedModeMutator:

Public Member Functions

 MixedModeMutator (bool pre=false)
 
Expr VisitExpr (const Expr &expr) final
 
virtual Expr DispatchVisitExpr (const Expr &expr)
 
Expr VisitExpr_ (const TupleNode *op) final
 
Expr VisitExpr_ (const CallNode *call_node) final
 
Expr VisitExpr_ (const TupleGetItemNode *op) final
 
virtual Expr Rewrite_ (const TupleNode *pre, const Expr &post)
 Users should override Rewrite_ methods to implement their pass. Rewrite_ functions will be able to rewrite the op only with data about the original node pre and the same node with modified inputs post and should not recurse. More...
 
virtual Expr Rewrite_ (const CallNode *pre, const Expr &post)
 
virtual Expr Rewrite_ (const TupleGetItemNode *pre, const Expr &post)
 
- Public Member Functions inherited from tvm::relay::ExprMutator
Expr Mutate (const Expr &expr)
 Mutate is alias for VisitExpr. More...
 
Expr VisitExpr (const Expr &expr) override
 
Expr VisitExpr_ (const VarNode *op) override
 
Expr VisitExpr_ (const ConstantNode *op) override
 
Expr VisitExpr_ (const GlobalVarNode *op) override
 
Expr VisitExpr_ (const OpNode *op) override
 
Expr VisitExpr_ (const TupleNode *op) override
 
Expr VisitExpr_ (const FunctionNode *op) override
 
Expr VisitExpr_ (const CallNode *call_node) override
 
Expr VisitExpr_ (const LetNode *op) override
 
Expr VisitExpr_ (const IfNode *op) override
 
Expr VisitExpr_ (const TupleGetItemNode *op) override
 
Expr VisitExpr_ (const RefCreateNode *op) override
 
Expr VisitExpr_ (const RefReadNode *op) override
 
Expr VisitExpr_ (const RefWriteNode *op) override
 
Expr VisitExpr_ (const ConstructorNode *op) override
 
Expr VisitExpr_ (const MatchNode *op) override
 
virtual Type VisitType (const Type &t)
 Used to visit the types inside of expressions. More...
 
virtual Clause VisitClause (const Clause &c)
 
virtual Pattern VisitPattern (const Pattern &c)
 

Protected Member Functions

template<typename T >
Expr Rewrite (const T *op)
 Implement Rewrite API by calling ExprMutator's VisitExpr_(op) to get a post node with changed inputs. More...
 
virtual void VisitLeaf (const Expr &expr)
 
virtual bool CheckVisited (const Expr &expr)
 

Protected Attributes

bool pre_
 
- Protected Attributes inherited from tvm::relay::ExprMutator
std::unordered_map< Expr, Expr, ObjectPtrHash, ObjectPtrEqualmemo_
 Internal map used for memoization. More...
 

Detailed Description

Non-recursive DFS Graph Traversal for Custom Rewriting Passes.

MixedModeMutator treats Expr as dataflow graph, and only Rewrites each Expr once. The mutated results are memoized in a map and reused so that local transformation on the dataflow preserves the graph structure.

MixedModeMutator provides the same recursive API as ExprMutator, and uses recursion to traverse most forms of the IR, but under the hood it expands nested dataflow regions of the graph and processes them iteratatively to prevent stack overflows

Uses Rewrite_ API of ExprRewriter for a cleaner split between recrusive and non-recursive behavior.

Constructor & Destructor Documentation

◆ MixedModeMutator()

tvm::relay::MixedModeMutator::MixedModeMutator ( bool  pre = false)
inline

Member Function Documentation

◆ CheckVisited()

virtual bool tvm::relay::MixedModeMutator::CheckVisited ( const Expr expr)
protectedvirtual

◆ DispatchVisitExpr()

virtual Expr tvm::relay::MixedModeMutator::DispatchVisitExpr ( const Expr expr)
virtual

◆ Rewrite()

template<typename T >
Expr tvm::relay::MixedModeMutator::Rewrite ( const T *  op)
inlineprotected

Implement Rewrite API by calling ExprMutator's VisitExpr_(op) to get a post node with changed inputs.

◆ Rewrite_() [1/3]

virtual Expr tvm::relay::MixedModeMutator::Rewrite_ ( const CallNode pre,
const Expr post 
)
inlinevirtual

◆ Rewrite_() [2/3]

virtual Expr tvm::relay::MixedModeMutator::Rewrite_ ( const TupleGetItemNode pre,
const Expr post 
)
inlinevirtual

◆ Rewrite_() [3/3]

virtual Expr tvm::relay::MixedModeMutator::Rewrite_ ( const TupleNode pre,
const Expr post 
)
inlinevirtual

Users should override Rewrite_ methods to implement their pass. Rewrite_ functions will be able to rewrite the op only with data about the original node pre and the same node with modified inputs post and should not recurse.

Parameters
preThe expression node before rewriting.
postThe expression with rewritten inputs.

◆ VisitExpr()

Expr tvm::relay::MixedModeMutator::VisitExpr ( const Expr expr)
final

◆ VisitExpr_() [1/3]

Expr tvm::relay::MixedModeMutator::VisitExpr_ ( const CallNode call_node)
inlinefinal

◆ VisitExpr_() [2/3]

Expr tvm::relay::MixedModeMutator::VisitExpr_ ( const TupleGetItemNode op)
inlinefinal

◆ VisitExpr_() [3/3]

Expr tvm::relay::MixedModeMutator::VisitExpr_ ( const TupleNode op)
inlinefinal

◆ VisitLeaf()

virtual void tvm::relay::MixedModeMutator::VisitLeaf ( const Expr expr)
protectedvirtual

Member Data Documentation

◆ pre_

bool tvm::relay::MixedModeMutator::pre_
protected

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