tvm
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tvm::tirx::StmtMutator Class Reference

StmtMutator that mutates the statements. More...

#include <stmt_functor.h>

Inheritance diagram for tvm::tirx::StmtMutator:
Collaboration diagram for tvm::tirx::StmtMutator:

Public Member Functions

Stmt operator() (Stmt stmt)
 Mutate stmt. More...
 

Protected Member Functions

template<typename TNode >
ObjectPtr< TNode > CopyOnWrite (const TNode *node)
 Perform copy on write on node. More...
 
Stmt VisitStmt (const Stmt &stmt) override
 Internal mutator that everyone calls. More...
 
virtual PrimExpr VisitExpr (const PrimExpr &e)
 Visitor to Exprs, can be overriden to do recursive changes to Exprs. More...
 
virtual Buffer VisitBufferDef (const Buffer &buffer, bool alloc_data)
 Visit buffer at definition site. Visits shape/strides/elem_offset via VisitExpr. If any field changes, creates a new buffer and records it in buffer_remap_. More...
 
virtual Buffer VisitBufferUse (const Buffer &buffer)
 Visit buffer at use site (BufferStore, BufferLoad, SBlock reads/writes). By default, returns the remapped buffer from buffer_remap_ if exists, otherwise returns the original buffer. Buffer fields are visited at their definition site. More...
 
Stmt VisitStmt_ (const BindNode *op) override
 
Stmt VisitStmt_ (const AttrStmtNode *op) override
 
Stmt VisitStmt_ (const IfThenElseNode *op) override
 
Stmt VisitStmt_ (const ForNode *op) override
 
Stmt VisitStmt_ (const WhileNode *op) override
 
Stmt VisitStmt_ (const AllocBufferNode *op) override
 
Stmt VisitStmt_ (const DeclBufferNode *op) override
 
Stmt VisitStmt_ (const BufferStoreNode *op) override
 
Stmt VisitStmt_ (const AssertStmtNode *op) override
 
Stmt VisitStmt_ (const SeqStmtNode *op) override
 
Stmt VisitStmt_ (const EvaluateNode *op) override
 
Stmt VisitStmt_ (const SBlockNode *op) override
 
Stmt VisitStmt_ (const SBlockRealizeNode *op) override
 
Stmt VisitSeqStmt_ (const SeqStmtNode *op, bool flatten_before_visit, std::function< Stmt(const Stmt &)> fmutate=nullptr)
 Alternative advance method for SeqStmtNode. More...
 

Protected Attributes

ffi::Map< Buffer, Bufferbuffer_remap_
 Map from old buffer to new buffer, populated by VisitBufferDef. More...
 
bool allow_copy_on_write_ {false}
 Internal state to indicate whether copy on write is enabled. COW is enabled iff all the parents of the node are unique. More...
 

Detailed Description

StmtMutator that mutates the statements.

Member Function Documentation

◆ CopyOnWrite()

template<typename TNode >
ObjectPtr<TNode> tvm::tirx::StmtMutator::CopyOnWrite ( const TNode *  node)
inlineprotected

Perform copy on write on node.

If CopyOnWrite is allowed, directly return a strong reference to the node container. Otherwise, return a copy of the node.

Returns
The result object pointer.

◆ operator()()

Stmt tvm::tirx::StmtMutator::operator() ( Stmt  stmt)
inline

Mutate stmt.

Parameters
stmtThe input statement to be mutated.
Returns
The result of the call
Note
It is important that stmt is passed by value. so copy on write can be triggered correctly. do mutator(std::move(stmt)) or when copy elison is triggered.

◆ VisitBufferDef()

virtual Buffer tvm::tirx::StmtMutator::VisitBufferDef ( const Buffer buffer,
bool  alloc_data 
)
protectedvirtual

Visit buffer at definition site. Visits shape/strides/elem_offset via VisitExpr. If any field changes, creates a new buffer and records it in buffer_remap_.

Parameters
bufferThe buffer being defined.
alloc_dataIf true, the buffer's data pointer is a new allocation (AllocBuffer); if false, data references an existing variable (DeclBuffer).
Returns
The (possibly new) buffer.

◆ VisitBufferUse()

virtual Buffer tvm::tirx::StmtMutator::VisitBufferUse ( const Buffer buffer)
protectedvirtual

Visit buffer at use site (BufferStore, BufferLoad, SBlock reads/writes). By default, returns the remapped buffer from buffer_remap_ if exists, otherwise returns the original buffer. Buffer fields are visited at their definition site.

Returns
The (possibly remapped) buffer.

◆ VisitExpr()

virtual PrimExpr tvm::tirx::StmtMutator::VisitExpr ( const PrimExpr e)
inlineprotectedvirtual

Visitor to Exprs, can be overriden to do recursive changes to Exprs.

Note
A common pattern is to call ExprMutator here, or have a class sub-class both StmtMutator and ExprMutator and redirect Mutate to ExprMutator::Mutate(Expr)

Reimplemented in tvm::tirx::StmtExprMutator.

◆ VisitSeqStmt_()

Stmt tvm::tirx::StmtMutator::VisitSeqStmt_ ( const SeqStmtNode op,
bool  flatten_before_visit,
std::function< Stmt(const Stmt &)>  fmutate = nullptr 
)
protected

Alternative advance method for SeqStmtNode.

This function can be called when a child class override VisitStmt_(const SeqStmtNode*) to introduce the special behavior to visit

Parameters
opThe sequence.
flatten_before_visitWhether to flatten the sequence before visit.
fmutateThe mutate function, can be nullptr, which defaults to Visit.
Returns
The mutated result.

◆ VisitStmt()

Stmt tvm::tirx::StmtMutator::VisitStmt ( const Stmt stmt)
inlineoverrideprotected

Internal mutator that everyone calls.

Note
To override mutate's behavior, override VisitExpr instead.
Parameters
stmtThe input stmt.
Returns
The mutated results.

◆ VisitStmt_() [1/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const AllocBufferNode op)
overrideprotected

◆ VisitStmt_() [2/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const AssertStmtNode op)
overrideprotected

◆ VisitStmt_() [3/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const AttrStmtNode op)
overrideprotected

◆ VisitStmt_() [4/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const BindNode op)
overrideprotected

◆ VisitStmt_() [5/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const BufferStoreNode op)
overrideprotected

◆ VisitStmt_() [6/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const DeclBufferNode op)
overrideprotected

◆ VisitStmt_() [7/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const EvaluateNode op)
overrideprotected

◆ VisitStmt_() [8/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const ForNode op)
overrideprotected

◆ VisitStmt_() [9/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const IfThenElseNode op)
overrideprotected

◆ VisitStmt_() [10/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const SBlockNode op)
overrideprotected

◆ VisitStmt_() [11/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const SBlockRealizeNode op)
overrideprotected

◆ VisitStmt_() [12/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const SeqStmtNode op)
overrideprotected

◆ VisitStmt_() [13/13]

Stmt tvm::tirx::StmtMutator::VisitStmt_ ( const WhileNode op)
overrideprotected

Member Data Documentation

◆ allow_copy_on_write_

bool tvm::tirx::StmtMutator::allow_copy_on_write_ {false}
protected

Internal state to indicate whether copy on write is enabled. COW is enabled iff all the parents of the node are unique.

◆ buffer_remap_

ffi::Map<Buffer, Buffer> tvm::tirx::StmtMutator::buffer_remap_
protected

Map from old buffer to new buffer, populated by VisitBufferDef.


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