19#ifndef TVM_S_TIR_UTILS_H_
20#define TVM_S_TIR_UTILS_H_
26#include <unordered_map>
38#define TVM_SREF_AS_OR_ERR(Result, SRef, Type) \
39 SRef->StmtAs<Type>(); \
40 TVM_FFI_CHECK(Result, TypeError)
50#define TVM_SREF_TO_SBLOCK(SRef) \
52 auto result = TVM_SREF_AS_OR_ERR(result, (SRef), ::tvm::s_tir::SBlockNode) \
53 << "Expects StmtSRef `" << #SRef << "` points to `Block`, but gets: " \
54 << ((SRef)->stmt ? (SRef)->stmt->GetTypeKey() : "None"); \
66#define TVM_SREF_TO_FOR(SRef) \
68 auto result = TVM_SREF_AS_OR_ERR(result, (SRef), ::tvm::ForNode) \
69 << "Expects StmtSRef `" << #SRef << "` points to `Loop`, but gets: " \
70 << ((SRef)->stmt ? (SRef)->stmt->GetTypeKey() : "None"); \
81#define TVM_TYPE_AS_OR_ERR(Result, From, Type) \
83 TVM_FFI_CHECK(Result, TypeError)
91#define TVM_TYPE_AS(From, Type) \
93 auto result = TVM_TYPE_AS_OR_ERR(result, (From), Type) \
94 << "Expects `" << #From << "` to have type `" << Type::_type_key \
95 << "`, but gets: " << ((From).GetTypeKey()); \
107inline void SetSeqIndex(std::unordered_map<const StmtNode*, StmtSRef>& stmt2ref,
108 const Stmt& stmt,
int seq_index,
bool include_loops =
true) {
111 TVM_FFI_ICHECK(stmt2ref.count(block));
112 stmt2ref.at(block)->seq_index = seq_index;
114 TVM_FFI_ICHECK(stmt2ref.count(block));
115 stmt2ref.at(block)->seq_index = seq_index;
116 }
else if (
const auto* loop = stmt.as<
ForNode>()) {
117 if (!include_loops)
return;
118 TVM_FFI_ICHECK(stmt2ref.count(loop));
119 stmt2ref.at(loop)->seq_index = seq_index;
130 std::unordered_map<const StmtNode*, StmtSRef>& stmt2ref,
131 const SeqStmtNode* seq_stmt,
bool include_loops =
true) {
133 for (
const Stmt& stmt : seq_stmt->
seq) {
A for loop, with possible type annotations.
Definition stmt.h:457
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:75
ffi::Array< Stmt > seq
internal sequence content.
Definition stmt.h:78
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
void SetSeqIndex(std::unordered_map< const StmtNode *, StmtSRef > &stmt2ref, const Stmt &stmt, int seq_index, bool include_loops=true)
Set the StmtSRefObj::seq_index field for stmt.
Definition utils.h:107
void SetSeqIndexInChildren(std::unordered_map< const StmtNode *, StmtSRef > &stmt2ref, const SeqStmtNode *seq_stmt, bool include_loops=true)
Update seq_index of the children of a SeqStmt.
Definition utils.h:129
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
S-TIR (Schedulable TIR) statements and attributes.
Definition of two pillar data structure for TensorIR scheduling: StmtSRef, SBlockScope.
TIRx statements and shared statement entry header.