Class ExprMutator#
Defined in File expr_functor.h
Inheritance Relationships#
Base Type#
public tvm::ObjectMutator(Class ObjectMutator)
Derived Type#
public tvm::tirx::StmtExprMutator(Class StmtExprMutator)
Class Documentation#
-
class ExprMutator : public tvm::ObjectMutator#
Structural Expr mutator with native overrides for core expressions and structural fallback for other objects.
Prefer StructuralMap for common cases; use ExprMutator for extensive per-kind customization or optimization. The default Var hook consults the inherited remap before visiting definition types.
Native hooks match exact node types; derived node types need their own registrations. Existing hooks only require overriding. For an extra MyExprObj derived from ExprObj, initialize an inherited table and register the new virtual hook:
Use tvm::ExprMutator explicitly when dialect mutators are also in scope.class MyExprMutator : public ExprMutator { public: TVM_DEFINE_OBJECT_FUNCTOR_DEFAULT_CONSTRUCTOR(MyExprMutator, ExprMutator) using ExprMutator::Mutate_; virtual UnchangedOr<Expr> Mutate_(const MyExprObj* node, InplaceMode inplace_mode); protected: static void InitVTable(VTable* vtable) { ExprMutator::InitVTable(vtable); SetDispatch<MyExprMutator, MyExprObj>(vtable); } };
Subclassed by tvm::tirx::StmtExprMutator
Public Functions
-
inline ExprMutator()#
Construct a mutator with the core expression hooks.
-
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.
-
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)#
-
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:
Direct descent that skips an owning ancestor must check that ancestor too:Parent_::Mutate_(node, mode); // The current node was already checked. Mutate(node->elem, mode); // Mutate checks elem's uniqueness.
When in doubt, omit inplace_mode. The default kDisallow is always safe; pass permission explicitly only when the full ancestor path is accounted for.auto child_mode = node->elem.unique() ? mode : InplaceMode::kDisallow; Mutate(node->elem->a, child_mode);
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.
Protected Functions
-
inline explicit ExprMutator(const VTable *vtable)#
Construct a mutator with an extended native dispatch table.
- Parameters:
vtable – The finalized table, which must outlive this mutator.
Protected Static Functions
-
static UnchangedOr<Expr> ReinferMutatedCallType(UnchangedOr<Expr> mutated, const CallObj *original, InplaceMode inplace_mode)#
Reinfer the result type of a Call after ordinary mutation.
Note
A unique replacement Call may be updated in place even when the original could not be. Inference errors propagate to the caller.
-
static void InitVTable(VTable *vtable)#
Register core expression hooks in a fresh mutable table.
- Parameters:
vtable – The table to initialize before adding derived registrations.
-
inline ExprMutator()#