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/base.h>
27#include <tvm/s_tir/stmt.h>
29
30namespace tvm {
31namespace s_tir {
32
37template <typename FType>
39
40template <typename R, typename... Args>
41class StmtFunctor<R(const Stmt&, Args...)> : public tirx::StmtFunctor<R(const Stmt&, Args...)> {
42 using Parent = tirx::StmtFunctor<R(const Stmt&, Args...)>;
43
44 public:
46 using Parent::Dispatch_;
47
48 virtual R Dispatch_(const SBlockObj* op, Args... args) {
49 return this->DispatchDefault_(op, std::forward<Args>(args)...);
50 }
51 virtual R Dispatch_(const SBlockRealizeObj* op, Args... args) {
52 return this->DispatchDefault_(op, std::forward<Args>(args)...);
53 }
54
55 protected:
56 using VTable = typename Parent::VTable;
57 explicit StmtFunctor(const VTable* vtable) : Parent(vtable) {}
58 static void InitVTable(VTable* vtable) {
59 Parent::InitVTable(vtable);
60 Parent::template SetDispatch<StmtFunctor, SBlockObj>(vtable);
61 Parent::template SetDispatch<StmtFunctor, SBlockRealizeObj>(vtable);
62 }
63};
64
77class TVM_DLL StmtExprVisitor : public tirx::StmtExprVisitor {
78 public:
80 using tirx::StmtExprVisitor::Visit;
81 using tirx::StmtExprVisitor::Visit_;
82
83 virtual ffi::Optional<VisitInterrupt> Visit_(const SBlockObj* op);
84 virtual ffi::Optional<VisitInterrupt> Visit_(const SBlockRealizeObj* op);
85
86 // Shared native traversal for specialized TIRX helpers extended by S-TIR.
87 static ffi::Optional<VisitInterrupt> VisitBlock(ffi::StructuralVisitorObj* visitor,
88 const SBlockObj* op);
89 static ffi::Optional<VisitInterrupt> VisitBlockRealize(ffi::StructuralVisitorObj* visitor,
90 const SBlockRealizeObj* op);
91
92 protected:
93 explicit StmtExprVisitor(const VTable* vtable) : tirx::StmtExprVisitor(vtable) {}
94 static void InitVTable(VTable* vtable);
95};
96
108 public:
110 using tirx::StmtExprMutator::Mutate;
111 using tirx::StmtExprMutator::Mutate_;
112
113 virtual UnchangedOr<Stmt> Mutate_(const SBlockObj* op, InplaceMode inplace_mode);
114 virtual UnchangedOr<Stmt> Mutate_(const SBlockRealizeObj* op, InplaceMode inplace_mode);
115
116 // Share block ownership and binder rules with specialized TIRX helpers.
117 static UnchangedOr<Stmt> MutateBlock(ffi::StructuralMutatorObj* mutator, const SBlockObj* op,
118 InplaceMode inplace_mode);
119 static UnchangedOr<Stmt> MutateBlockRealize(ffi::StructuralMutatorObj* mutator,
120 const SBlockRealizeObj* op, 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_
Functors for tirx stmts utility functions to call common functors.
A dynamically dispatched functor on the type of the first argument.
Definition object_functor.h:85
Container of all statements.
Definition stmt.h:61
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:107
static void InitVTable(VTable *vtable)
static UnchangedOr< Stmt > MutateBlock(ffi::StructuralMutatorObj *mutator, const SBlockObj *op, InplaceMode inplace_mode)
StmtExprMutator(const VTable *vtable)
Definition stmt_functor.h:123
static UnchangedOr< Stmt > MutateBlockRealize(ffi::StructuralMutatorObj *mutator, const SBlockRealizeObj *op, InplaceMode inplace_mode)
virtual UnchangedOr< Stmt > Mutate_(const SBlockRealizeObj *op, InplaceMode inplace_mode)
virtual UnchangedOr< Stmt > Mutate_(const SBlockObj *op, InplaceMode inplace_mode)
Extend native TIRX traversal with schedulable block semantics.
Definition stmt_functor.h:77
virtual ffi::Optional< VisitInterrupt > Visit_(const SBlockObj *op)
static ffi::Optional< VisitInterrupt > VisitBlockRealize(ffi::StructuralVisitorObj *visitor, const SBlockRealizeObj *op)
StmtExprVisitor(const VTable *vtable)
Definition stmt_functor.h:93
virtual ffi::Optional< VisitInterrupt > Visit_(const SBlockRealizeObj *op)
static ffi::Optional< VisitInterrupt > VisitBlock(ffi::StructuralVisitorObj *visitor, const SBlockObj *op)
static void InitVTable(VTable *vtable)
typename Parent::VTable VTable
Definition stmt_functor.h:56
virtual R Dispatch_(const SBlockObj *op, Args... args)
Definition stmt_functor.h:48
virtual R Dispatch_(const SBlockRealizeObj *op, Args... args)
Definition stmt_functor.h:51
StmtFunctor(const VTable *vtable)
Definition stmt_functor.h:57
static void InitVTable(VTable *vtable)
Definition stmt_functor.h:58
Extend TIRX statement dispatch with schedulable blocks.
Definition stmt_functor.h:38
Mutator that recursively mutates stmts and exprs on them.
Definition stmt_functor.h:226
Native visitor for TIRx statements and their expression operands.
Definition stmt_functor.h:181
Type-dispatched statement functor with a caller-selected signature.
Definition stmt_functor.h:51
Parent compiler symbol visibility.
S-TIR (Schedulable TIR) statements and attributes.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
#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