19#ifndef TVM_S_TIR_UTILS_H_
20#define TVM_S_TIR_UTILS_H_
25#include <unordered_map>
37#define TVM_SREF_AS_OR_ERR(Result, SRef, Type) \
38 SRef->StmtAs<Type>(); \
39 TVM_FFI_CHECK(Result, TypeError)
49#define TVM_SREF_TO_SBLOCK(SRef) \
51 auto result = TVM_SREF_AS_OR_ERR(result, (SRef), ::tvm::tirx::SBlockNode) \
52 << "Expects StmtSRef `" << #SRef << "` points to `Block`, but gets: " \
53 << ((SRef)->stmt ? (SRef)->stmt->GetTypeKey() : "None"); \
65#define TVM_SREF_TO_FOR(SRef) \
67 auto result = TVM_SREF_AS_OR_ERR(result, (SRef), ::tvm::tirx::ForNode) \
68 << "Expects StmtSRef `" << #SRef << "` points to `Loop`, but gets: " \
69 << ((SRef)->stmt ? (SRef)->stmt->GetTypeKey() : "None"); \
80#define TVM_TYPE_AS_OR_ERR(Result, From, Type) \
82 TVM_FFI_CHECK(Result, TypeError)
90#define TVM_TYPE_AS(From, Type) \
92 auto result = TVM_TYPE_AS_OR_ERR(result, (From), Type) \
93 << "Expects `" << #From << "` to have type `" << Type::_type_key \
94 << "`, but gets: " << ((From).GetTypeKey()); \
106inline void SetSeqIndex(std::unordered_map<const StmtNode*, StmtSRef>& stmt2ref,
111 stmt2ref.at(block)->seq_index = seq_index;
112 }
else if (
const auto* block = stmt.as<
SBlockNode>()) {
114 stmt2ref.at(block)->seq_index = seq_index;
115 }
else if (
const auto*
loop = stmt.as<
ForNode>()) {
118 stmt2ref.at(
loop)->seq_index = seq_index;
129 std::unordered_map<const StmtNode*, StmtSRef>& stmt2ref,
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
ContextType * get()
Definition with_context.h:81
A for loop, with possible type annotations.
Definition stmt.h:590
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
The container of seq statement. Represent a sequence of statements.
Definition stmt.h:315
Container of all statements.
Definition stmt.h:67
void SetSeqIndex(std::unordered_map< const StmtNode *, StmtSRef > &stmt2ref, const Stmt &stmt, int seq_index, bool include_loops=true)
Set the StmtSRefNode::seq_index field for stmt.
Definition utils.h:106
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:128
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Definition of two pillar data structure for TensorIR scheduling: StmtSRef, SBlockScope.