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 */
23#ifndef TVM_S_TIR_STMT_FUNCTOR_H_
24#define TVM_S_TIR_STMT_FUNCTOR_H_
25
26#include <tvm/s_tir/stmt.h>
28
29namespace tvm {
30namespace s_tir {
31
36template <typename FType>
38
39template <typename R, typename... Args>
40class StmtFunctor<R(const Stmt&, Args...)> : public tirx::StmtFunctor<R(const Stmt&, Args...)> {
41 using Parent = tirx::StmtFunctor<R(const Stmt&, Args...)>;
42
43 public:
45 using Parent::Dispatch_;
46
47 virtual R Dispatch_(const SBlockNode* op, Args... args) {
48 return this->DispatchDefault_(op, std::forward<Args>(args)...);
49 }
50 virtual R Dispatch_(const SBlockRealizeNode* op, Args... args) {
51 return this->DispatchDefault_(op, std::forward<Args>(args)...);
52 }
53
54 protected:
55 using VTable = typename Parent::VTable;
56 explicit StmtFunctor(const VTable* vtable) : Parent(vtable) {}
57 static void InitVTable(VTable* vtable) {
58 Parent::InitVTable(vtable);
59 Parent::template SetDispatch<StmtFunctor, SBlockNode>(vtable);
60 Parent::template SetDispatch<StmtFunctor, SBlockRealizeNode>(vtable);
61 }
62};
63
76class TVM_DLL StmtExprVisitor : public tirx::StmtExprVisitor {
77 public:
79 using tirx::StmtExprVisitor::Visit;
80 using tirx::StmtExprVisitor::Visit_;
81
82 virtual ffi::Optional<VisitInterrupt> Visit_(const SBlockNode* op);
83 virtual ffi::Optional<VisitInterrupt> Visit_(const SBlockRealizeNode* op);
84
85 // Shared native traversal for specialized TIRX helpers extended by S-TIR.
86 static ffi::Optional<VisitInterrupt> VisitBlock(tirx::StmtExprVisitor* visitor,
87 const SBlockNode* op);
88 static ffi::Optional<VisitInterrupt> VisitBlockRealize(tirx::StmtExprVisitor* visitor,
89 const SBlockRealizeNode* op);
90
91 protected:
92 explicit StmtExprVisitor(const VTable* vtable) : tirx::StmtExprVisitor(vtable) {}
93 static void InitVTable(VTable* vtable);
94};
95
107 public:
109 using tirx::StmtExprMutator::Mutate;
110 using tirx::StmtExprMutator::Mutate_;
111
112 virtual UnchangedOr<Stmt> Mutate_(const SBlockNode* op, InplaceMode inplace_mode);
113 virtual UnchangedOr<Stmt> Mutate_(const SBlockRealizeNode* op, InplaceMode inplace_mode);
114
115 // Share block ownership and binder rules with specialized TIRX helpers.
116 static UnchangedOr<Stmt> MutateBlock(tirx::StmtExprMutator* mutator, const SBlockNode* op,
117 InplaceMode inplace_mode);
118 static UnchangedOr<Stmt> MutateBlockRealize(tirx::StmtExprMutator* mutator,
119 const SBlockRealizeNode* op,
120 InplaceMode inplace_mode);
121
122 protected:
123 explicit StmtExprMutator(const VTable* vtable) : tirx::StmtExprMutator(vtable) {}
124 static void InitVTable(VTable* vtable);
125};
126
127} // namespace s_tir
128} // namespace tvm
129#endif // TVM_S_TIR_STMT_FUNCTOR_H_
A dynamically dispatched functor on the type of the first argument.
Definition object_functor.h:85
Container of all statements.
Definition stmt.h:62
A block is a basic schedule unit in TIR.
Definition stmt.h:112
A block realization node represents execution of the block at the binding values.
Definition stmt.h:188
Extend native TIRX mutation while preserving block iterator binders.
Definition stmt_functor.h:106
static UnchangedOr< Stmt > MutateBlockRealize(tirx::StmtExprMutator *mutator, const SBlockRealizeNode *op, InplaceMode inplace_mode)
static UnchangedOr< Stmt > MutateBlock(tirx::StmtExprMutator *mutator, const SBlockNode *op, InplaceMode inplace_mode)
static void InitVTable(VTable *vtable)
StmtExprMutator(const VTable *vtable)
Definition stmt_functor.h:123
virtual UnchangedOr< Stmt > Mutate_(const SBlockNode *op, InplaceMode inplace_mode)
virtual UnchangedOr< Stmt > Mutate_(const SBlockRealizeNode *op, InplaceMode inplace_mode)
Extend native TIRX traversal with schedulable block semantics.
Definition stmt_functor.h:76
static ffi::Optional< VisitInterrupt > VisitBlock(tirx::StmtExprVisitor *visitor, const SBlockNode *op)
StmtExprVisitor(const VTable *vtable)
Definition stmt_functor.h:92
static ffi::Optional< VisitInterrupt > VisitBlockRealize(tirx::StmtExprVisitor *visitor, const SBlockRealizeNode *op)
virtual ffi::Optional< VisitInterrupt > Visit_(const SBlockNode *op)
virtual ffi::Optional< VisitInterrupt > Visit_(const SBlockRealizeNode *op)
static void InitVTable(VTable *vtable)
typename Parent::VTable VTable
Definition stmt_functor.h:55
virtual R Dispatch_(const SBlockRealizeNode *op, Args... args)
Definition stmt_functor.h:50
virtual R Dispatch_(const SBlockNode *op, Args... args)
Definition stmt_functor.h:47
StmtFunctor(const VTable *vtable)
Definition stmt_functor.h:56
static void InitVTable(VTable *vtable)
Definition stmt_functor.h:57
Extend TIRX statement dispatch with schedulable blocks.
Definition stmt_functor.h:37
Mutator that recursively mutates stmts and exprs on them.
Definition stmt_functor.h:221
Native visitor for TIRx statements and their expression operands.
Definition stmt_functor.h:176
Type-dispatched statement functor with a caller-selected signature.
Definition stmt_functor.h:51
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
S-TIR (Schedulable TIR) statements and attributes.
Functors for tirx stmts utility functions to call common functors.