25#ifndef TVM_TIRX_STMT_FUNCTOR_WITH_ANALYZER_H_
26#define TVM_TIRX_STMT_FUNCTOR_WITH_ANALYZER_H_
28#include <tvm/ffi/cast.h>
29#include <tvm/ffi/extra/structural_visit.h>
37#include <unordered_set>
49 using StmtExprVisitor::Visit_;
91 using StmtExprMutator::Mutate;
92 using StmtExprMutator::Mutate_;
99 UnchangedOr<Stmt>
Mutate_(
const ForNode* op, InplaceMode inplace_mode)
override;
101 UnchangedOr<Stmt>
Mutate_(
const IfNode* op, InplaceMode inplace_mode)
override;
126 bool non_trivial_only);
145 template <
typename FLambda>
147 std::unordered_set<const VarNode*> iter_var_nodes;
148 for (
const auto& [var, _] : iter_vars_) {
149 iter_var_nodes.insert(var.get());
151 auto f_use_itervar = [&iter_var_nodes](
const tvm::VarNode* v) {
152 return iter_var_nodes.count(v);
154 auto walkfn = [&](
const tvm::Var& var) -> ffi::Expected<ffi::WalkResult> {
155 return f_use_itervar(var.get()) ? ffi::WalkResult::Interrupt(ffi::VisitInterrupt(var))
156 : ffi::WalkResult::Advance();
159 if (ffi::StructuralWalk<ffi::WalkOrder::kPreOrder>(condition, walkfn).has_value()) {
160 iter_predicates_.push_back(condition);
162 iter_predicates_.pop_back();
Algebra expression simplifications.
Assert condition, if an error occurs, return the error message.
Definition stmt.h:260
Bind a variable to a value in the enclosing scope.
Definition stmt.h:135
Call corresponds to callable invocation.
Definition expr.h:935
A for loop, with possible type annotations.
Definition stmt.h:457
If statement.
Definition stmt.h:387
A dynamically dispatched functor on the type of the first argument.
Definition object_functor.h:85
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
A single-body statement whose semantics are defined by an operator. Operands are evaluated in the enc...
Definition stmt.h:189
A scope stack for maintaining hierarchical state during IR visiting.
Definition scope_stack.h:55
A local variable in the IR.
Definition expr.h:694
Managed reference to VarNode.
Definition expr.h:714
Let binding. Bind var to value then evaluate body.
Definition expr.h:727
return true_value if condition is true, otherwise return false_value.
Definition expr.h:684
Analyzer that contains bunch of sub-analyzers.
Definition analyzer.h:715
Managed reference to AnalyzerObj.
Definition analyzer.h:916
Managed reference to FunctionNode.
Definition function.h:105
IRMutator with an analyzer context.
Definition stmt_functor_with_analyzer.h:89
UnchangedOr< Stmt > Mutate_(const AssertStmtNode *op, InplaceMode inplace_mode) override
UnchangedOr< Stmt > Mutate_(const BindNode *op, InplaceMode inplace_mode) override
UnchangedOr< PrimExpr > Mutate_(const prim::LetNode *op, InplaceMode inplace_mode) override
static void InitVTable(VTable *vtable)
StmtExprMutatorWithAnalyzer(const sym::Analyzer &analyzer)
Definition stmt_functor_with_analyzer.h:93
UnchangedOr< Stmt > Mutate_(const ForNode *op, InplaceMode inplace_mode) override
UnchangedOr< Stmt > Mutate_(const RegionStmtNode *op, InplaceMode inplace_mode) override
StmtExprMutatorWithAnalyzer(sym::AnalyzerObj *analyzer)
Definition stmt_functor_with_analyzer.h:95
void WithRecordIterPredicate(PrimExpr condition, FLambda callback)
Run callback while trying to record iter predicate.
Definition stmt_functor_with_analyzer.h:146
UnchangedOr< Expr > Mutate_(const CallNode *op, InplaceMode inplace_mode) override
UnchangedOr< PrimExpr > Mutate_(const prim::SelectNode *op, InplaceMode inplace_mode) override
static const VTable * GlobalVTable()
UnchangedOr< Stmt > Mutate_(const IfNode *op, InplaceMode inplace_mode) override
void MarkTensorParamShapes(const Function &func)
Mark all tensor-parameter shape values as positive values.
ffi::Array< PrimExpr > IterMapSimplifyWithContext(const ffi::Array< PrimExpr > &indices, bool non_trivial_only)
Use internal bound information to perform inter map simplification of indices.
ffi::Array< PrimExpr > iter_predicates_
iterator predicates
Definition stmt_functor_with_analyzer.h:139
sym::AnalyzerObj * analyzer_
internal analyzer field.
Definition stmt_functor_with_analyzer.h:129
ffi::Map< PrimVar, Range > iter_vars_
Recorded loop iterators.
Definition stmt_functor_with_analyzer.h:137
StmtExprMutatorWithAnalyzer(sym::AnalyzerObj *analyzer, const VTable *vtable)
Definition stmt_functor_with_analyzer.h:110
ScopeStack< WithGroup< sym::ConstraintContext > > constraint_scope_
Scope stack for accumulated assert constraints.
Definition stmt_functor_with_analyzer.h:131
Mutator that recursively mutates stmts and exprs on them.
Definition stmt_functor.h:221
Definition stmt_functor_with_analyzer.h:43
ffi::Optional< VisitInterrupt > Visit_(const BindNode *op)
ScopeStack< WithGroup< sym::ConstraintContext > > constraint_scope_
Scope stack for accumulated assert constraints.
Definition stmt_functor_with_analyzer.h:70
PrimExpr ExtractRealCondition(PrimExpr condition) const
Extract a constraint from a conditional statement.
static void InitVTable(VTable *vtable)
ffi::Optional< VisitInterrupt > Visit_(const CallNode *op)
sym::Analyzer analyzer_
internal analyzer field.
Definition stmt_functor_with_analyzer.h:67
StmtExprVisitorWithAnalyzer(const VTable *vtable)
Definition stmt_functor_with_analyzer.h:65
ffi::Optional< VisitInterrupt > Visit_(const IfNode *op)
ffi::Optional< VisitInterrupt > Visit_(const AssertStmtNode *op)
ffi::Optional< VisitInterrupt > Visit_(const prim::LetNode *op)
ffi::Optional< VisitInterrupt > Visit_(const ForNode *op)
ffi::Optional< VisitInterrupt > Visit_(const RegionStmtNode *op)
Native visitor for TIRx statements and their expression operands.
Definition stmt_functor.h:176
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_DEFINE_OBJECT_FUNCTOR_DEFAULT_CONSTRUCTOR(Class, Parent)
Define a default constructor backed by one initialized native dispatch table.
Definition object_functor.h:529
#define TVM_TIRX_DLL
Definition base.h:83
A generic scope stack for managing hierarchical state during IR visiting.
Analysis utilities and passes for TIR.
Functors for tirx stmts utility functions to call common functors.
RAII wrapper function to enter and exit a context object similar to python's with syntax.