Class StmtExprMutator#

Inheritance Relationships#

Base Type#

Class Documentation#

class StmtExprMutator : public tvm::ExprMutator#

Mutator that recursively mutates stmts and exprs on them.

Base hooks preserve stored types and derived fields. They rewrite structural children without re-inferring types or repeating constructor validation, including on in-place writes. Passes that change dtypes or index lanes must provide the corresponding TensorLoad, TensorStore, or TensorRegion inference.

Public Functions

inline StmtExprMutator()#
inline UnchangedOr<Stmt> Mutate(const Stmt &stmt, InplaceMode inplace_mode = InplaceMode::kDisallow)#

Mutate a borrowed statement through the virtual generic entry.

Note

Entry overrides must preserve the statement category. Result storage is transferred without a runtime category check, as for Expr/PrimExpr.

Parameters:
  • stmt – The borrowed statement.

  • inplace_mode – Inherited permission along the complete ownership chain.

Returns:

Unchanged or an owning statement replacement.

inline UnchangedOr<SeqStmt> Mutate(const SeqStmt &stmt, InplaceMode inplace_mode = InplaceMode::kDisallow)#

Mutate a scope body without collapsing its sequence container.

inline UnchangedOr<ffi::Optional<SeqStmt>> Mutate(const ffi::Optional<SeqStmt> &stmt, InplaceMode inplace_mode = InplaceMode::kDisallow)#
inline UnchangedOr<ffi::Optional<Stmt>> Mutate(const ffi::Optional<Stmt> &stmt, InplaceMode inplace_mode = InplaceMode::kDisallow)#

Mutate an optional statement, preserving absence.

virtual UnchangedOr<Stmt> Mutate_(const BindObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const RegionStmtObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const IfObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const ForObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const WhileObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const ReturnObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const BreakObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const ContinueObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const TensorStoreObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const AssertStmtObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const SeqStmtObj *op, InplaceMode inplace_mode)#
virtual UnchangedOr<Stmt> Mutate_(const EvaluateObj *op, InplaceMode inplace_mode)#
inline UnchangedOr<PrimExpr> Mutate(const PrimExpr &expr, InplaceMode inplace_mode = InplaceMode::kDisallow)#

Mutate a primitive expression, preserving its expression category.

Note

Calls the virtual AnyView entry. Overrides must preserve PrimExpr; the result storage is transferred without a runtime type check.

Parameters:
  • expr – The borrowed primitive expression.

  • inplace_mode – Inherited mutation permission.

Returns:

Unchanged or an owning primitive expression replacement.

inline UnchangedOr<Expr> Mutate(const Expr &expr, InplaceMode inplace_mode = InplaceMode::kDisallow)#

Mutate an expression, preserving its expression category.

Note

Calls the virtual AnyView entry. Overrides must preserve Expr; the result storage is transferred without a runtime type check.

Parameters:
  • expr – The borrowed expression.

  • inplace_mode – Inherited mutation permission.

Returns:

Unchanged or an owning expression replacement.

inline virtual UnchangedOr<ffi::Any> Mutate(ffi::AnyView value, InplaceMode inplace_mode = InplaceMode::kDisallow)#

Mutate a borrowed value, throwing on failure.

In-place mutation requires every node and owning container on the root-to-current path to be unique. Inherited inplace_mode records ancestor permission; Mutate checks the current target. Never promote inherited denial to permission. Within a Mutate_ hook, forward mode to a parent hook or an immediate child:

Parent_::Mutate_(node, mode);  // The current node was already checked.
Mutate(node->elem, mode);     // Mutate checks elem's uniqueness.
Direct descent that skips an owning ancestor must check that ancestor too:
auto child_mode = node->elem.unique() ? mode : InplaceMode::kDisallow;
Mutate(node->elem->a, child_mode);
When in doubt, omit inplace_mode. The default kDisallow is always safe; pass permission explicitly only when the full ancestor path is accounted for.

Note

Establishes uniqueness before invoking typed hooks. Entry overrides must preserve inherited denial and check uniqueness before writing or forwarding permission. Qualified Parent::Mutate bypasses the current override while descendants remain virtual. Completed in-place changes are not rolled back on error.

Parameters:
  • value – The borrowed object or inline value to mutate.

  • inplace_mode – Inherited permission along the path to this value.

Returns:

An owning replacement or Unchanged. Non-object inputs return their inline value.

virtual UnchangedOr<Expr> Mutate_(const OpaqueExprObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const TupleObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const TupleGetItemObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const TensorLoadObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const TensorRegionObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const VarObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const GlobalVarObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const CallObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const GenericConstObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const DataTypeImmObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const IntImmObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const FloatImmObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const OpObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<Expr> Mutate_(const StringImmObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::CastObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::AddObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::LShiftObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::RShiftObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::BitwiseAndObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::BitwiseOrObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::BitwiseXorObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::BitwiseNotObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::SubObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::MulObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::DivObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::ModObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::FloorDivObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::FloorModObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::MinObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::MaxObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::EQObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::NEObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::LTObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::LEObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::GTObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::GEObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::AndObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::OrObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::NotObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::SelectObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::LetObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::RampObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::BroadcastObj *node, InplaceMode inplace_mode)#
virtual UnchangedOr<PrimExpr> Mutate_(const prim::ShuffleObj *node, InplaceMode inplace_mode)#

Protected Functions

inline explicit StmtExprMutator(const VTable *vtable)#

Protected Static Functions

static void InitVTable(VTable *vtable)#