25#ifndef TVM_S_TIR_SBLOCK_SCOPE_H_
26#define TVM_S_TIR_SBLOCK_SCOPE_H_
35#include <unordered_map>
73 namespace refl = tvm::ffi::reflection;
83 this->parent =
nullptr;
95 template <
typename StmtType>
97 if (
stmt !=
nullptr &&
stmt->IsInstance<StmtType>()) {
98 return static_cast<const StmtType*
>(
stmt);
153 ffi::Optional<VisitInterrupt>
Visit(ffi::AnyView value)
override {
154 if (value.as<
ExprObj>())
return std::nullopt;
164 bool include_loops =
true) {
165 auto creator = ffi::make_object<SRefTreeCreator>(include_loops);
166 for (
const auto& kv : mod->functions) {
167 const BaseFunc& base_func = kv.second;
168 if (
auto opt = base_func.as<
Function>()) {
169 auto func = opt.value();
170 creator->Visit(func->body);
173 return std::move(creator->stmt2ref_);
183 void PushSRef(
const StmtObj* stmt);
186 void PopAndRecordSRef();
188 ffi::Optional<VisitInterrupt> Visit_(
const ForObj* loop)
final;
192 ffi::Optional<VisitInterrupt> Visit_(
const SeqStmtObj* seq_stmt)
final;
196 std::unordered_map<const StmtObj*, StmtSRef> stmt2ref_;
198 std::vector<StmtSRef> srefs_;
234 namespace refl = tvm::ffi::reflection;
235 refl::ObjectDef<DependencyObj>()
274 std::unordered_map<StmtSRef, ffi::Array<Dependency>, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>
277 std::unordered_map<StmtSRef, ffi::Array<Dependency>, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>
280 std::unordered_map<TensorVar, ffi::Array<StmtSRef>, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>
284 namespace refl = tvm::ffi::reflection;
285 refl::ObjectDef<SBlockScopeObj>();
315 explicit SBlockScope(ffi::ObjectPtr<SBlockScopeObj> data) : ffi::ObjectRef(data) {
316 TVM_FFI_ICHECK(data !=
nullptr);
326 TVM_DLL
explicit SBlockScope(
const ffi::Array<StmtSRef>& child_block_srefs);
TIRx statements and shared statement entry header.
Managed reference to BaseFuncObj.
Definition function.h:202
Base type of all the expressions.
Definition expr.h:66
A for loop, with possible type annotations.
Definition stmt.h:471
Managed reference class to IRModuleObj.
Definition module.h:292
virtual ffi::Optional< VisitInterrupt > Visit(ffi::AnyView value)
Visit a borrowed object or inline value, throwing on failure.
Definition object_functor.h:242
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:74
Base node of all statements.
Definition stmt.h:37
A block realization node represents execution of the block at the binding values.
Definition stmt.h:188
Extend native TIRX traversal with schedulable block semantics.
Definition stmt_functor.h:77
virtual ffi::Optional< VisitInterrupt > Visit_(const SBlockObj *op)
A tuple (src, dst, kind) representing certain types of dependency. For example, (A,...
Definition sblock_scope.h:220
StmtSRef dst
The destination of the dependency relation.
Definition sblock_scope.h:229
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.Dependency", DependencyObj, ffi::Object)
StmtSRef src
The source of the dependency relation.
Definition sblock_scope.h:227
DependencyObj(StmtSRef src, StmtSRef dst, DepKind kind)
Definition sblock_scope.h:224
static void RegisterReflection()
Definition sblock_scope.h:233
DepKind kind
The dependency kind.
Definition sblock_scope.h:231
DependencyObj(ffi::UnsafeInit tag)
Definition sblock_scope.h:222
Managed reference to DependencyObj.
Definition sblock_scope.h:247
Dependency(StmtSRef src, StmtSRef dst, DepKind kind)
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Dependency, ffi::ObjectRef, DependencyObj)
Managed reference to FunctionObj.
Definition function.h:107
An object with 1-to-1 correspondence with each block reference in the sref tree. This data structure ...
Definition sblock_scope.h:267
std::unordered_map< TensorVar, ffi::Array< StmtSRef >, ffi::ObjectPtrHash, ffi::ObjectPtrEqual > tensor_writers
The mapping from the tensor to the blocks who write it.
Definition sblock_scope.h:281
ffi::Array< Dependency > GetDepsBySrc(const StmtSRef &src) const
Get all dependencies whose src equals src
std::unordered_map< StmtSRef, ffi::Array< Dependency >, ffi::ObjectPtrHash, ffi::ObjectPtrEqual > dst2deps
Lookup table for the dst of dependencies.
Definition sblock_scope.h:278
std::unordered_map< StmtSRef, ffi::Array< Dependency >, ffi::ObjectPtrHash, ffi::ObjectPtrEqual > src2deps
Lookup table for the src of dependencies.
Definition sblock_scope.h:275
ffi::Array< Dependency > GetDepsByDst(const StmtSRef &dst) const
Get all dependencies whose dst equals dst
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.SBlockScope", SBlockScopeObj, ffi::Object)
static void RegisterReflection()
Definition sblock_scope.h:283
Managed reference to SBlockScopeObj.
Definition sblock_scope.h:309
SBlockScope(ffi::ObjectPtr< SBlockScopeObj > data)
Constructor from ffi::ObjectPtr<SBlockScopeObj>.
Definition sblock_scope.h:315
SBlockScope()
The constructor creating an empty block scope with on dependency information.
SBlockScope(const ffi::Array< StmtSRef > &child_block_srefs)
Create the object with the specific leaf blocks, and compute the dependency information between the l...
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SBlockScope, ffi::ObjectRef, SBlockScopeObj)
Definition sblock_scope.h:149
static std::unordered_map< const StmtObj *, StmtSRef > Create(IRModule mod, bool include_loops=true)
StmtSRef Tree Creator.
Definition sblock_scope.h:163
SRefTreeCreator(bool include_loops)
Definition sblock_scope.h:176
ffi::Optional< VisitInterrupt > Visit(ffi::AnyView value) override
Construct a visitor with the core expression hooks.
Definition sblock_scope.h:153
An object that refers to schedulable elements (block/for-loop) in TensorIR, aka "sref".
Definition sblock_scope.h:56
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.StmtSRef", StmtSRefObj, ffi::Object)
static void RegisterReflection()
Definition sblock_scope.h:72
StmtSRefObj * parent
The parent sref.
Definition sblock_scope.h:65
const StmtObj * stmt
The block or for stmt the object refers to.
Definition sblock_scope.h:63
void Reset()
Reset the object inplace to the invalid state.
Definition sblock_scope.h:81
const StmtType * StmtAs() const
Get the referenced statement with proper type checking. It serves the same purpose as ffi::ObjectRef:...
Definition sblock_scope.h:96
int64_t seq_index
If the statement the sref points to is an element of a SeqStmt in the AST, then seq_index is set to i...
Definition sblock_scope.h:70
static constexpr const bool _type_mutable
Definition sblock_scope.h:77
Managed reference to StmtSRefObj.
Definition sblock_scope.h:109
StmtSRef(const StmtObj *stmt, StmtSRefObj *parent, int64_t seq_index)
The constructor.
static StmtSRef RootMark()
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(StmtSRef, ffi::ObjectRef, StmtSRefObj)
static StmtSRef InlineMark()
Parent compiler symbol visibility.
S-TIR (Schedulable TIR) statements and attributes.
Native traversal and statement dispatch for schedulable TIR.
IRModule that holds the functions and type definitions.
DepKind
Type of dependency. Right now we have 4 types of dependencies 1) Read-after-write (kRAW) 2) Write-aft...
Definition sblock_scope.h:208
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41