tvm
Loading...
Searching...
No Matches
stmt_functor.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
26#ifndef TVM_TIRX_STMT_FUNCTOR_H_
27#define TVM_TIRX_STMT_FUNCTOR_H_
28
29#include <tvm/ir/node_functor.h>
30#include <tvm/ir/prim/expr.h>
32#include <tvm/tirx/function.h>
33#include <tvm/tirx/stmt.h>
35
36#include <unordered_map>
37#include <utility>
38
39namespace tvm {
40namespace tirx {
46template <typename FType>
48
49#define STMT_FUNCTOR_DEFAULT \
50 { \
51 return VisitStmtDefault_(op, std::forward<Args>(args)...); \
52 }
53
54#define IR_STMT_FUNCTOR_DISPATCH(OP) \
55 vtable.template set_dispatch<OP>([](const ffi::ObjectRef& n, TSelf* self, Args... args) { \
56 return self->VisitStmt_(static_cast<const OP*>(n.get()), std::forward<Args>(args)...); \
57 });
58
59template <typename R, typename... Args>
60class StmtFunctor<R(const Stmt& n, Args... args)> {
61 private:
62 using TSelf = StmtFunctor<R(const Stmt& n, Args... args)>;
63 using FType = NodeFunctor<R(const ffi::ObjectRef& n, TSelf* self, Args... args)>;
64
65 public:
67 using result_type = R;
69 virtual ~StmtFunctor() {}
76 R operator()(const Stmt& n, Args... args) { return VisitStmt(n, std::forward<Args>(args)...); }
83 virtual R VisitStmt(const Stmt& n, Args... args) {
84 static FType vtable = InitVTable();
85 return vtable(n, this, std::forward<Args>(args)...);
86 }
87 // Functions that can be overriden by subclass
88 virtual R VisitStmt_(const BindNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
89 virtual R VisitStmt_(const AttrStmtNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
91 virtual R VisitStmt_(const ForNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
92 virtual R VisitStmt_(const WhileNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
93 virtual R VisitStmt_(const ReturnNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
94 virtual R VisitStmt_(const BreakNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
95 virtual R VisitStmt_(const ContinueNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
100 virtual R VisitStmt_(const SeqStmtNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
101 virtual R VisitStmt_(const EvaluateNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
102 virtual R VisitStmt_(const SBlockNode* op, Args... args) STMT_FUNCTOR_DEFAULT;
106 virtual R VisitStmtDefault_(const ffi::Object* op, Args...) {
107 TVM_FFI_THROW(InternalError) << "Do not have a default for " << op->GetTypeKey();
109 }
110
111 private:
112 // initialize the vtable.
113 static FType InitVTable() {
114 FType vtable;
133 vtable.Finalize();
134 return vtable;
135 }
136};
137
138#undef IR_STMT_FUNCTOR_DISPATCH
139#undef STMT_FUNCTOR_DEFAULT
140
144class TVM_DLL StmtVisitor : protected StmtFunctor<void(const Stmt&)> {
145 public:
146 using StmtFunctor::operator();
147
148 protected:
149 using StmtFunctor::VisitStmt;
157 virtual void VisitExpr(const Expr& e) {}
165 virtual void VisitBufferDef(const BufferVar& buffer, bool alloc_data);
171 virtual void VisitBufferUse(const BufferVar& buffer);
172 // statement visitor
173 void VisitStmt_(const BindNode* op) override;
174 void VisitStmt_(const AttrStmtNode* op) override;
175 void VisitStmt_(const IfThenElseNode* op) override;
176 void VisitStmt_(const ForNode* op) override;
177 void VisitStmt_(const WhileNode* op) override;
178 void VisitStmt_(const ReturnNode* op) override;
179 void VisitStmt_(const BreakNode* op) override;
180 void VisitStmt_(const ContinueNode* op) override;
181 void VisitStmt_(const AllocBufferNode* op) override;
182 void VisitStmt_(const DeclBufferNode* op) override;
183 void VisitStmt_(const BufferStoreNode* op) override;
184 void VisitStmt_(const AssertStmtNode* op) override;
185 void VisitStmt_(const SeqStmtNode* op) override;
186 void VisitStmt_(const EvaluateNode* op) override;
187 void VisitStmt_(const SBlockNode* op) override;
188 void VisitStmt_(const SBlockRealizeNode* op) override;
189 void VisitStmt_(const ScopeIdDefStmtNode* op) override;
190 void VisitStmt_(const tirx::TilePrimitiveCallNode* op) override;
191};
192
196class TVM_DLL StmtMutator : protected StmtFunctor<Stmt(const Stmt&)> {
197 public:
207 allow_copy_on_write_ = true;
208 return VisitStmt(stmt);
209 }
210
211 protected:
213 ffi::Map<BufferVar, BufferVar> buffer_remap_;
214 // We perform copy on write optimizations on the StmtMutator
215 // so that an unique copy of parent can be mutated inplace
216 // when some of its children changed.
217 // We only do such optimization for Stmt nests(instead of Exprs) for now
218 // as Stmt's parent state is more likely remain unchanged when one of
219 // its child block changes.
224 bool allow_copy_on_write_{false};
234 template <typename TNode>
235 ffi::ObjectPtr<TNode> CopyOnWrite(const TNode* node) {
236 static_assert(std::is_base_of<StmtNode, TNode>::value,
237 "StmtMutator:: CopyOnWrite requires us to track uniqueness of all parent "
238 "nodes during the recursion. Because the child classes do not necessarily "
239 "check the Array, Expr and other structures during the visit, it is only safe to "
240 "call this function with StmtNodes for now. "
241 "Please create a new node directly in other cases.");
242 if (allow_copy_on_write_) {
243 // return the old node.
244 return ffi::GetObjectPtr<TNode>(const_cast<TNode*>(node));
245 } else {
246 // Make a new copy of the node.
247 // need to rely on the default copy constructor
248 return ffi::make_object<TNode>(*node);
249 }
250 }
257 Stmt VisitStmt(const Stmt& stmt) override {
258 if (allow_copy_on_write_ && !stmt.unique()) {
259 allow_copy_on_write_ = false;
260 Stmt ret = StmtFunctor::VisitStmt(stmt);
261 allow_copy_on_write_ = true;
262 return ret;
263 } else {
264 return StmtFunctor::VisitStmt(stmt);
265 }
266 }
274 virtual Expr VisitExpr(const Expr& e) { return e; }
276 PrimExpr VisitPrimExpr(const PrimExpr& e) { return VisitExpr(e).as_or_throw<PrimExpr>(); }
285 virtual BufferVar VisitBufferDef(const BufferVar& buffer, bool alloc_data);
292 virtual BufferVar VisitBufferUse(const BufferVar& buffer);
293 // statement visitor
294 Stmt VisitStmt_(const BindNode* op) override;
295 Stmt VisitStmt_(const AttrStmtNode* op) override;
296 Stmt VisitStmt_(const IfThenElseNode* op) override;
297 Stmt VisitStmt_(const ForNode* op) override;
298 Stmt VisitStmt_(const WhileNode* op) override;
299 Stmt VisitStmt_(const ReturnNode* op) override;
300 Stmt VisitStmt_(const BreakNode* op) override;
301 Stmt VisitStmt_(const ContinueNode* op) override;
302 Stmt VisitStmt_(const AllocBufferNode* op) override;
303 Stmt VisitStmt_(const DeclBufferNode* op) override;
304 Stmt VisitStmt_(const BufferStoreNode* op) override;
305 Stmt VisitStmt_(const AssertStmtNode* op) override;
306 Stmt VisitStmt_(const SeqStmtNode* op) override;
307 Stmt VisitStmt_(const EvaluateNode* op) override;
308 Stmt VisitStmt_(const SBlockNode* op) override;
309 Stmt VisitStmt_(const SBlockRealizeNode* op) override;
310 Stmt VisitStmt_(const ScopeIdDefStmtNode* op) override;
325 std::function<Stmt(const Stmt&)> fmutate = nullptr);
326
327 // internal helper.
328 class Internal;
329};
330
335 public:
336 using StmtVisitor::operator();
337 using ExprVisitor::operator();
338
339 protected:
340 using ExprVisitor::VisitExpr;
341 using ExprVisitor::VisitExpr_;
342 using StmtVisitor::VisitStmt;
343
344 void VisitExpr(const Expr& e) override { return ExprVisitor::VisitExpr(e); }
345 void VisitExpr_(const TensorLoadNode* op) override;
346 void VisitExpr_(const BufferRegionNode* op) override;
347};
348
353 public:
354 using StmtMutator::operator();
355 using ExprMutator::operator();
356
357 protected:
358 using ExprMutator::VisitExpr;
359 using ExprMutator::VisitExpr_;
360 using ExprMutator::VisitPrimExpr;
361 using StmtMutator::VisitStmt;
362
363 Expr VisitExpr(const Expr& e) override { return ExprMutator::VisitExpr(e); }
364 Expr VisitExpr_(const VarNode* op) override;
365 Expr VisitExpr_(const TensorLoadNode* op) override;
366 Expr VisitExpr_(const BufferRegionNode* op) override;
367};
368
384TVM_DLL Stmt IRTransform(Stmt stmt, const ffi::Function& preorder, const ffi::Function& postorder,
385 ffi::Optional<ffi::Array<ffi::String>> only_enable = std::nullopt);
386
393TVM_DLL void PostOrderVisit(const ffi::ObjectRef& node,
394 std::function<void(const ffi::ObjectRef&)> fvisit);
395
402TVM_DLL Stmt Substitute(Stmt stmt, std::function<ffi::Optional<Expr>(const Var& var)> vmap);
403
410TVM_DLL Expr Substitute(Expr expr, std::function<ffi::Optional<Expr>(const Var& var)> vmap);
411
412inline PrimExpr Substitute(PrimExpr expr, std::function<ffi::Optional<Expr>(const Var& var)> vmap) {
413 return Substitute(Expr(expr), std::move(vmap)).as_or_throw<PrimExpr>();
414}
415
423 std::function<ffi::Optional<Expr>(const Var& var)> vmap) {
425}
426
433template <typename T>
434ffi::Array<T> Substitute(const ffi::Array<T>& arr,
435 std::function<ffi::Optional<Expr>(const Var& var)> vmap) {
436 return arr.Map([&vmap](const auto& elem) { return Substitute(elem, vmap); });
437}
438
450template <typename Obj>
451auto Substitute(Obj&& obj, const ffi::Map<Var, Expr>& vmap) {
452 auto func = [&vmap](const Var& var) -> ffi::Optional<Expr> { return vmap.Get(var); };
453 return Substitute(std::forward<Obj>(obj), func);
454}
455
465template <typename Obj, typename Replacement>
466auto Substitute(Obj&& obj, const ffi::Map<Var, Replacement>& vmap) {
467 auto func = [&vmap](const Var& var) -> ffi::Optional<Expr> {
468 if (auto replacement = vmap.Get(var)) return Expr(replacement.value());
469 return std::nullopt;
470 };
471 return Substitute(std::forward<Obj>(obj), func);
472}
473
483template <typename Obj, typename Replacement>
484auto Substitute(Obj&& obj, const std::unordered_map<const VarNode*, Replacement>& vmap) {
485 auto func = [&vmap](const Var& var) -> ffi::Optional<Expr> {
486 if (auto it = vmap.find(var.get()); it != vmap.end()) {
487 return Expr(it->second);
488 }
489 return std::nullopt;
490 };
491 return Substitute(std::forward<Obj>(obj), func);
492}
493
503template <typename Obj, typename Replacement, typename Hasher, typename EqualityChecker>
505 const std::unordered_map<Var, Replacement, Hasher, EqualityChecker>& vmap) {
506 auto func = [&vmap](const Var& var) -> ffi::Optional<Expr> {
507 if (auto it = vmap.find(var); it != vmap.end()) {
508 return Expr(it->second);
509 }
510 return std::nullopt;
511 };
512 return Substitute(std::forward<Obj>(obj), func);
513}
514
524template <typename Obj, typename Replacement>
525auto Substitute(Obj&& obj, const std::unordered_map<IterVar, Replacement>& iter_vmap) {
526 std::unordered_map<const VarNode*, Expr> vmap;
527 for (const auto& [iter_var, expr] : iter_vmap) {
528 vmap[iter_var->var.get()] = Expr(expr);
529 }
530
531 auto func = [&vmap](const Var& var) -> ffi::Optional<Expr> {
532 if (auto it = vmap.find(var.get()); it != vmap.end()) {
533 return it->second;
534 } else {
535 return std::nullopt;
536 }
537 };
538 return Substitute(std::forward<Obj>(obj), func);
539}
540
552 Stmt stmt, std::function<ffi::Optional<PrimExpr>(const Var&)> vmap);
553
565 PrimExpr expr, std::function<ffi::Optional<PrimExpr>(const Var&)> vmap);
566
574TVM_DLL void PreOrderVisit(const ffi::ObjectRef& stmt_or_expr,
575 const std::function<bool(const ffi::ObjectRef&)>& fvisit);
576
587template <typename Node, typename = std::enable_if_t<std::is_base_of_v<StmtNode, Node>>>
588bool ContainsNode(const Stmt& stmt) {
589 struct Visitor : StmtVisitor {
590 // Early bail-out, if we already found the node.
591 void VisitStmt(const Stmt& stmt) final {
592 if (contains_node) {
593 return;
594 }
595 StmtVisitor::VisitStmt(stmt);
596 }
597
598 void VisitStmt_(const Node* block) override { contains_node = true; }
599
600 bool contains_node{false};
601 };
602
604 visitor(stmt);
605 return visitor.contains_node;
606}
607
608} // namespace tirx
609} // namespace tvm
610
611#endif // TVM_TIR_STMT_FUNCTOR_H_
Managed reference to ExprNode.
Definition base_expr.h:335
A dynamically dispatched functor on the type of the first argument.
Definition node_functor.h:62
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
Range container
Definition expr.h:610
static Range FromMinExtent(PrimExpr min, PrimExpr extent, Span span=Span())
construct a new range with min and extent The corresponding constructor is removed,...
Load a value from an indexed expression source.
Definition expr.h:109
A local variable in the IR.
Definition expr.h:355
Managed reference to VarNode.
Definition expr.h:372
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Allocate a buffer and declare it in scope.
Definition stmt.h:262
Assert condition, if an error occurs, return the error message.
Definition stmt.h:162
Define certain auxiliary attribute for the body to be a symbolic value. This provide auxiliary inform...
Definition stmt.h:118
Bind a variable to a value in the enclosing scope.
Definition stmt.h:79
A Break in control flow.
Definition stmt.h:724
Representing a region of multi-dimensional buffer access.
Definition buffer_region.h:49
Store value to the high dimension buffer.
Definition stmt.h:204
Checked zero-state view over an ordinary VarNode with BufferType.
Definition buffer.h:179
A Continue in control flow.
Definition stmt.h:749
Declare a buffer that can be used in the body.
Definition stmt.h:237
Evaluates an expression. This is mostly used for putting a Call node into Stmt.
Definition stmt.h:340
ExprMutator that mutates expressions.
Definition expr_functor.h:253
ExprVisitor.
Definition expr_functor.h:207
A for loop, with possible type annotations.
Definition stmt.h:590
IfThenElse statement.
Definition stmt.h:520
A return from the current function.
Definition stmt.h:696
A block is a basic schedule unit in TIR.
Definition stmt.h:833
A block realization node represents execution of the block at the binding values.
Definition stmt.h:903
Standalone statement that declares a scope-id binding (e.g. cta_id, warp_id, lane_id)....
Definition stmt.h:946
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:315
Mutator that recursively mutates stmts and exprs on them.
Definition stmt_functor.h:352
Expr VisitExpr(const Expr &e) override
Visitor to Exprs, can be overriden to do recursive changes to Exprs.
Definition stmt_functor.h:363
Expr VisitExpr_(const BufferRegionNode *op) override
Expr VisitExpr_(const VarNode *op) override
Expr VisitExpr_(const TensorLoadNode *op) override
Visitor that recursively visit stmts and exprs on them.
Definition stmt_functor.h:334
void VisitExpr_(const BufferRegionNode *op) override
void VisitExpr_(const TensorLoadNode *op) override
void VisitExpr(const Expr &e) override
Visitor to Exprs, can be overriden to do recursive changes to Exprs.
Definition stmt_functor.h:344
virtual R VisitStmt_(const ScopeIdDefStmtNode *op, Args... args)
Definition stmt_functor.h:104
virtual R VisitStmt_(const ContinueNode *op, Args... args)
Definition stmt_functor.h:95
virtual R VisitStmt_(const BufferStoreNode *op, Args... args)
Definition stmt_functor.h:98
virtual ~StmtFunctor()
virtual destructor
Definition stmt_functor.h:69
virtual R VisitStmtDefault_(const ffi::Object *op, Args...)
Definition stmt_functor.h:106
R operator()(const Stmt &n, Args... args)
Same as call.
Definition stmt_functor.h:76
virtual R VisitStmt_(const IfThenElseNode *op, Args... args)
Definition stmt_functor.h:90
virtual R VisitStmt_(const SBlockRealizeNode *op, Args... args)
Definition stmt_functor.h:103
virtual R VisitStmt_(const ForNode *op, Args... args)
Definition stmt_functor.h:91
virtual R VisitStmt_(const SeqStmtNode *op, Args... args)
Definition stmt_functor.h:100
virtual R VisitStmt_(const SBlockNode *op, Args... args)
Definition stmt_functor.h:102
virtual R VisitStmt_(const tirx::TilePrimitiveCallNode *op, Args... args)
Definition stmt_functor.h:105
virtual R VisitStmt(const Stmt &n, Args... args)
The functor call.
Definition stmt_functor.h:83
virtual R VisitStmt_(const AttrStmtNode *op, Args... args)
Definition stmt_functor.h:89
virtual R VisitStmt_(const EvaluateNode *op, Args... args)
Definition stmt_functor.h:101
virtual R VisitStmt_(const BreakNode *op, Args... args)
Definition stmt_functor.h:94
virtual R VisitStmt_(const ReturnNode *op, Args... args)
Definition stmt_functor.h:93
virtual R VisitStmt_(const DeclBufferNode *op, Args... args)
Definition stmt_functor.h:97
virtual R VisitStmt_(const AssertStmtNode *op, Args... args)
Definition stmt_functor.h:99
virtual R VisitStmt_(const AllocBufferNode *op, Args... args)
Definition stmt_functor.h:96
virtual R VisitStmt_(const WhileNode *op, Args... args)
Definition stmt_functor.h:92
virtual R VisitStmt_(const BindNode *op, Args... args)
Definition stmt_functor.h:88
Same as ExprFunctor except it is applied on statements.
Definition stmt_functor.h:47
StmtMutator that mutates the statements.
Definition stmt_functor.h:196
ffi::ObjectPtr< TNode > CopyOnWrite(const TNode *node)
Perform copy on write on node.
Definition stmt_functor.h:235
virtual Expr VisitExpr(const Expr &e)
Visitor to Exprs, can be overriden to do recursive changes to Exprs.
Definition stmt_functor.h:274
Stmt operator()(Stmt stmt)
Mutate stmt.
Definition stmt_functor.h:206
Stmt VisitStmt_(const ReturnNode *op) override
Stmt VisitStmt_(const tirx::TilePrimitiveCallNode *op) override
Stmt VisitStmt_(const EvaluateNode *op) override
Stmt VisitStmt_(const SBlockNode *op) override
virtual BufferVar VisitBufferUse(const BufferVar &buffer)
Visit buffer at use site (BufferStore, BufferLoad, SBlock reads/writes). By default,...
Stmt VisitStmt_(const WhileNode *op) override
Stmt VisitStmt_(const SeqStmtNode *op) override
virtual BufferVar VisitBufferDef(const BufferVar &buffer, bool alloc_data)
Visit buffer at definition site. Visits shape/strides/elem_offset via VisitExpr. If any field changes...
Stmt VisitStmt_(const ContinueNode *op) override
Stmt VisitStmt_(const SBlockRealizeNode *op) override
Stmt VisitStmt_(const IfThenElseNode *op) override
Stmt VisitStmt_(const ScopeIdDefStmtNode *op) override
Stmt VisitStmt_(const AttrStmtNode *op) override
Stmt VisitStmt(const Stmt &stmt) override
Internal mutator that everyone calls.
Definition stmt_functor.h:257
Stmt VisitStmt_(const BindNode *op) override
ffi::Map< BufferVar, BufferVar > buffer_remap_
Map from old buffer to new buffer, populated by VisitBufferDef.
Definition stmt_functor.h:213
Stmt VisitStmt_(const ForNode *op) override
Stmt VisitSeqStmt_(const SeqStmtNode *op, bool flatten_before_visit, std::function< Stmt(const Stmt &)> fmutate=nullptr)
Alternative advance method for SeqStmtNode.
PrimExpr VisitPrimExpr(const PrimExpr &e)
Mutate a primitive expression and verify that it remains primitive.
Definition stmt_functor.h:276
Stmt VisitStmt_(const BreakNode *op) override
Stmt VisitStmt_(const AllocBufferNode *op) override
Stmt VisitStmt_(const AssertStmtNode *op) override
Stmt VisitStmt_(const BufferStoreNode *op) override
Stmt VisitStmt_(const DeclBufferNode *op) override
StmtVisitor.
Definition stmt_functor.h:144
virtual void VisitBufferUse(const BufferVar &buffer)
Visit buffer at use site (BufferStore, BufferLoad, SBlock reads/writes). By default,...
void VisitStmt_(const ForNode *op) override
void VisitStmt_(const BindNode *op) override
void VisitStmt_(const SBlockNode *op) override
void VisitStmt_(const AttrStmtNode *op) override
void VisitStmt_(const BufferStoreNode *op) override
void VisitStmt_(const ReturnNode *op) override
void VisitStmt_(const SBlockRealizeNode *op) override
void VisitStmt_(const SeqStmtNode *op) override
void VisitStmt_(const AssertStmtNode *op) override
void VisitStmt_(const tirx::TilePrimitiveCallNode *op) override
void VisitStmt_(const ContinueNode *op) override
void VisitStmt_(const WhileNode *op) override
void VisitStmt_(const BreakNode *op) override
void VisitStmt_(const EvaluateNode *op) override
virtual void VisitExpr(const Expr &e)
Visitor to Exprs, can be overriden to do recursive changes to Exprs.
Definition stmt_functor.h:157
void VisitStmt_(const ScopeIdDefStmtNode *op) override
void VisitStmt_(const IfThenElseNode *op) override
virtual void VisitBufferDef(const BufferVar &buffer, bool alloc_data)
Visit buffer at definition site (AllocBuffer, DeclBuffer, SBlock alloc_buffers). Visits buffer shape,...
void VisitStmt_(const AllocBufferNode *op) override
void VisitStmt_(const DeclBufferNode *op) override
Container of all statements.
Definition stmt.h:67
TIRX TilePrimitiveCall stmt.
Definition tile_primitive.h:188
A While loop.
Definition stmt.h:665
TIR expressions.
void PostOrderVisit(const ffi::ObjectRef &node, std::function< void(const ffi::ObjectRef &)> fvisit)
Recursively visit a statement or expression in post DFS order, applying fvisit. Each node is guarante...
IndexMap Substitute(const IndexMap &index_map, std::function< ffi::Optional< PrimExpr >(const Var &var)> f_subst)
Substitute variables in an index map.
bool ContainsNode(const Stmt &stmt)
Check if the statement contains the specified node type.
Definition stmt_functor.h:588
Stmt IRTransform(Stmt stmt, const ffi::Function &preorder, const ffi::Function &postorder, ffi::Optional< ffi::Array< ffi::String > > only_enable=std::nullopt)
recursively visit the ir nodes in post DFS order, and transform it
void PreOrderVisit(const ffi::ObjectRef &stmt_or_expr, const std::function< bool(const ffi::ObjectRef &)> &fvisit)
Recursively visit a statement or expression in pre DFS order, applying fvisit. If fvisit returns fals...
Stmt SubstituteWithDataTypeLegalization(Stmt stmt, std::function< ffi::Optional< PrimExpr >(const Var &)> vmap)
Substitute the var specified by vmap and legalize data types after substitution.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Defines the Functor data structures.
#define IR_STMT_FUNCTOR_DISPATCH(OP)
Definition stmt_functor.h:54
#define STMT_FUNCTOR_DEFAULT
Definition stmt_functor.h:49
TIRX tile primitive statements, operators, and reified lambda expressions.
Functors for tirx expressions.
TIR Function.
TIR statements.