tvm.tir.stmt_functor

Statement functor utilities for IR transformations

tvm.tir.stmt_functor.ir_transform(stmt, preorder, postorder, only_enable=None)

Recursively visit and transform ir nodes in post DFS order.

Parameters
  • stmt (tvm.tir.Stmt) – The input to be transformed.

  • preorder (function) – The function called in before recursive mutation If preorder returns None, then the transform will proceed to recursive call. If preorder returns a not None tvm.tir.Stmt/Expr, the transformer will simply return it and won’t do further recursion.

  • postorder (function) – The function called after recursive mutation.

  • only_enable (Optional[List[str]]) – List of types that we only enable.

Returns

result – The result.

Return type

tvm.tir.Stmt

tvm.tir.stmt_functor.post_order_visit(stmt, fvisit)
Recursively visit the ir in post DFS order node, apply fvisit

Each node is guaranteed to be visited only once.

Parameters

fvisit (function) – The visitor function.

tvm.tir.stmt_functor.pre_order_visit(stmt, fvisit)
Recursive pre-order visit on stmt AST, applying fvisit on each node.

If fvisit returns False, it won’t visit the children of the node.

Parameters

fvisit (function of the signature Object -> bool) – The visitor function.

tvm.tir.stmt_functor.substitute(node, vmap)

Substitute the var specified by vmap.

Parameters
  • node (ObjectRef) – The input.

  • vmap (Dict[tir.Var, PrimExpr]) – The variable mapping.

Returns

result – The result.

Return type

tvm.tir.Stmt

tvm.tir.stmt_functor.renew_defs(func: tvm.tir.function.PrimFunc)

Re-generate the definition nodes for a TIR, including VarDef, BufferDef. This pass works as a simple DeepCopy to duplicate a function with different Vars and Buffers but the same behavior

Parameters

func (PrimFunc) – The input function

Returns

result – The new generated func.

Return type

PrimFunc