24 #ifndef TVM_TIR_VAR_H_
25 #define TVM_TIR_VAR_H_
27 #include <tvm/ffi/dtype.h>
57 namespace refl = tvm::ffi::reflection;
59 refl::AttachFieldFlag::SEqHashIgnore());
70 explicit Var(ffi::UnsafeInit tag) :
Expr(tag) {}
71 explicit Var(ffi::ObjectPtr<VarNode> n) :
Expr(n) {}
86 TVM_DLL
explicit Var(ffi::String name_hint,
Type type_annotation,
Span span =
Span());
132 Var(std::move(name_hint), std::move(dtype), std::move(span)).as_or_throw<
PrimExpr>()) {}
136 :
PrimExpr(
Var(std::move(name_hint), std::move(type_annotation), std::move(span))
140 operator Var()
const {
return this->as_or_throw<Var>(); }
256 namespace refl = tvm::ffi::reflection;
257 refl::ObjectDef<IterVarNode>()
259 .def_ro(
"var", &
IterVarNode::var, refl::AttachFieldFlag::SEqHashDefRecursive())
288 inline IterVar::operator
PrimExpr()
const {
return (*this)->var; }
295 return "ThreadIndex";
307 return "Parallelized";
320 inline constexpr
bool use_default_type_traits_v<tirx::PrimVar> =
false;
323 struct TypeTraits<tirx::PrimVar> :
public ObjectRefTypeTraitsBase<tirx::PrimVar> {
324 using Base = ObjectRefTypeTraitsBase<tirx::PrimVar>;
325 using Base::CopyFromAnyViewAfterCheck;
326 using Base::CopyToAnyView;
327 using Base::GetMismatchTypeInfo;
328 using Base::MoveFromAnyAfterCheck;
329 using Base::MoveToAny;
330 using Base::TypeSchema;
334 if (src->type_index == TypeIndex::kTVMFFINone) {
335 return tirx::PrimVar::_type_is_nullable;
337 if (src->type_index < TypeIndex::kTVMFFIStaticObjectBegin ||
338 !details::IsObjectInstance<tirx::VarNode>(src->type_index)) {
342 details::ObjectUnsafe::ObjectPtrFromUnowned<Object>(src->v_obj).get());
343 return details::AnyUnsafe::CheckAnyStrict<PrimType>(
var->ExprNode::ty);
347 if (CheckAnyStrict(src)) {
348 if (src->type_index == TypeIndex::kTVMFFINone) {
349 return details::ObjectUnsafe::ObjectRefFromObjectPtr<tirx::PrimVar>(
nullptr);
351 return details::ObjectUnsafe::ObjectRefFromObjectPtr<tirx::PrimVar>(
352 details::ObjectUnsafe::ObjectPtrFromUnowned<tirx::VarNode>(src->v_obj));
375 struct std::hash<
tvm::tirx::Var> {
376 std::size_t operator()(
const tvm::tirx::Var&
var)
const {
return tvm::ffi::ObjectPtrHash()(
var); }
380 struct std::equal_to<
tvm::tirx::Var> {
382 return tvm::ffi::ObjectPtrEqual()(var_a, var_b);
Base type of all the expressions.
Definition: base_expr.h:276
Managed reference to ExprNode.
Definition: base_expr.h:311
Base class for other IR constructs that can be converted to PrimExpr. This is useful for the FFI to c...
Definition: base_expr.h:391
Managed reference to PrimExprConvertibleNode.
Definition: base_expr.h:402
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition: base_expr.h:354
Definition: base_expr.h:113
static PrimType Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
Range container
Definition: expr.h:484
Definition: source_map.h:111
Managed reference to TypeNode.
Definition: base_expr.h:77
An iteration variable representing an iteration over a one dimensional interval.
Definition: var.h:231
Range dom
the domain of iteration, if known, can be None For the intermediate schedule node,...
Definition: var.h:237
ffi::String thread_tag
additional tag on the iteration variable, set this if this is bound already to a known thread tag.
Definition: var.h:246
IterVarType iter_type
The type of the IterVar.
Definition: var.h:241
static void RegisterReflection()
Definition: var.h:255
PrimVar var
The looping variable.
Definition: var.h:239
PrimExpr ToPrimExpr() const final
Definition: var.h:253
Span span
Span that points to the original source code. Reserved debug information.
Definition: var.h:251
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: var.h:264
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.IterVar", IterVarNode, PrimExprConvertibleNode)
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:274
IterVar(Range dom, PrimVar var, IterVarType iter_type, ffi::String thread_tag="", Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(IterVar, PrimExprConvertible, IterVarNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(IterVarNode)
Checked scalar view over a VarNode.
Definition: var.h:127
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PrimVar, PrimExpr, VarNode)
PrimVar(ffi::String name_hint, PrimType dtype=PrimType::Int(32), Span span=Span())
Construct a scalar variable directly from a primitive type.
Definition: var.h:130
static constexpr bool _type_container_is_exact
Definition: var.h:150
PrimVar CopyWithSuffix(const ffi::String &suffix) const
Definition: var.h:142
PrimVar(ffi::String name_hint, Type type_annotation, Span span=Span())
Construct a scalar variable directly from a checked type annotation.
Definition: var.h:135
PrimVar copy_with_dtype(PrimType dtype) const
Definition: var.h:145
A variable node in the IR.
Definition: var.h:49
ffi::String name_hint
The hint to the variable name.
Definition: var.h:55
static void RegisterReflection()
Definition: var.h:56
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: var.h:62
TVM_FFI_DECLARE_OBJECT_INFO("tirx.Var", VarNode, ExprNode)
static constexpr const uint32_t _type_child_slots
Definition: var.h:63
a named variable in TIR
Definition: var.h:68
Var(ffi::String name_hint="v", PrimType dtype=PrimType::Int(32), Span span=Span())
Constructor.
static constexpr bool _type_container_is_exact
Definition: var.h:118
const VarNode * operator->() const
Get pointer to the internal value.
Definition: var.h:110
Var(ffi::String name_hint, Type type_annotation, Span span=Span())
Constructor which provides a more detailed type annotation.
Var copy_with_dtype(PrimType dtype) const
Make a new copy of the variable with specified dtype.
Var CopyWithSuffix(const ffi::String &suffix) const
Make a new copy of var with same type, append suffix.
Var(ffi::UnsafeInit tag)
Definition: var.h:70
Var(ffi::ObjectPtr< VarNode > n)
Definition: var.h:71
Var copy_with_name(const ffi::String &name) const
Make a new copy of var with same type, but a different nam.
const VarNode * get() const
Get pointer to the internal value.
Definition: var.h:115
Copy-on-write helper macro for IR ffi::ObjectRef types.
IR/AST nodes for TVM types shared across IR variants.
Definition: iter_affine_map.h:231
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
IterVarType
Type of iteration variable. Each IterVar have a specific type.
Definition: var.h:162
@ kThreadIndex
The IterVar itself is a thread-index of a fixed thread launching group. Note that this is already ass...
Definition: var.h:179
@ kUnrolled
The execution is unrolled.
Definition: var.h:210
@ kCommReduce
Communicative reduction. Cannot be directly parallelized.
Definition: var.h:186
@ kTensorized
Marks boundary of tensorization intrinsic.
Definition: var.h:222
@ kVectorized
The loop is vectorized.
Definition: var.h:214
@ kDataPar
Data parallel iteration. This normally corresponds to axis of Tensor. Allow all IterVar manipulations...
Definition: var.h:171
@ kParallelized
The loop is parallelized.
Definition: var.h:218
@ kOpaque
IterVar is opaque,.
Definition: var.h:204
@ kOrdered
Serial loops with loop carry dependency, the iteration must execute in order. Cannot be re-ordered.
Definition: var.h:194
ffi::Array< Range > Region
Definition: var.h:153
const char * IterVarType2String(IterVarType t)
Definition: var.h:290
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
ObjectRefTypeTraitsBase< tirx::PrimVar > Base
Definition: var.h:324
static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny *src)
Definition: var.h:333
static TVM_FFI_INLINE std::optional< tirx::PrimVar > TryCastFromAnyView(const TVMFFIAny *src)
Definition: var.h:346