tvm
Loading...
Searching...
No Matches
expr.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 */
19
24#ifndef TVM_IR_EXPR_H_
25#define TVM_IR_EXPR_H_
26
27#include <tvm/ffi/big_int.h>
28#include <tvm/ffi/dtype.h>
29#include <tvm/ffi/error.h>
30#include <tvm/ffi/extra/dataclass.h>
31#include <tvm/ffi/reflection/registry.h>
32#include <tvm/ffi/string.h>
33#include <tvm/ir/attrs.h>
34#include <tvm/ir/base_expr.h>
35#include <tvm/ir/cow.h>
36#include <tvm/ir/location.h>
37
38#include <algorithm>
39#include <cstdint>
40#include <functional>
41#include <limits>
42#include <optional>
43#include <ostream>
44#include <string>
45#include <utility>
46
47namespace tvm {
48
50class ConstantNode : public ExprNode {
51 public:
52 static constexpr uint32_t _type_child_slots = 5;
53 static void RegisterReflection() { ffi::reflection::ObjectDef<ConstantNode>(); }
55};
56
58class Constant : public Expr {
59 public:
60 explicit Constant(ffi::ObjectPtr<ConstantNode> node) : Expr(std::move(node)) {}
61
63};
64
67 public:
68 ffi::Any value;
69
70 static void RegisterReflection() {
71 ffi::reflection::ObjectDef<GenericConstNode>().def_ro("value", &GenericConstNode::value);
72 }
74};
75
77class GenericConst : public Constant {
78 public:
79 TVM_TIRX_DLL GenericConst(ffi::Any value, Type ty, Location loc = UnknownLoc());
80
81 explicit GenericConst(ffi::ObjectPtr<GenericConstNode> node) : Constant(std::move(node)) {}
82
85};
86
89 public:
90 ffi::String value;
91
92 static void RegisterReflection() {
93 ffi::reflection::ObjectDef<StringImmNode>().def_ro("value", &StringImmNode::value);
94 }
96};
97
99class StringImm : public Constant {
100 public:
101 TVM_TIRX_DLL explicit StringImm(ffi::String value, Location loc = UnknownLoc());
102
103 explicit StringImm(ffi::ObjectPtr<StringImmNode> node) : Constant(std::move(node)) {}
104
107};
108
111 public:
112 DLDataType value;
113
114 static void RegisterReflection() {
115 ffi::reflection::ObjectDef<DataTypeImmNode>().def_ro("value", &DataTypeImmNode::value);
116 }
118};
119
121class DataTypeImm : public Constant {
122 public:
123 TVM_TIRX_DLL explicit DataTypeImm(DLDataType value, Location loc = UnknownLoc());
124
125 explicit DataTypeImm(ffi::ObjectPtr<DataTypeImmNode> node) : Constant(std::move(node)) {}
126
129};
130
135class IntImmNode : public ConstantNode {
136 public:
138 ffi::BigInt value;
139
140 static void RegisterReflection() {
141 namespace refl = tvm::ffi::reflection;
142 refl::ObjectDef<IntImmNode>().def_ro("value", &IntImmNode::value);
143 }
145};
146
152class IntImm : public PrimExpr {
153 public:
160 TVM_TIRX_DLL IntImm(PrimType value_ty, ffi::BigInt value, Location loc = UnknownLoc());
161
162 template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>, int> = 0>
163 IntImm(PrimType value_ty, Enum value, Location loc = UnknownLoc())
164 : IntImm(std::move(value_ty), ffi::BigInt(static_cast<std::underlying_type_t<Enum>>(value)),
165 std::move(loc)) {}
166
172 static IntImm Bool(bool value, Location loc = UnknownLoc()) {
173 return IntImm(PrimType::Bool(), value, loc);
174 }
175
181 static IntImm Int32(ffi::BigInt value, Location loc = UnknownLoc()) {
182 return IntImm(PrimType::Int(32), std::move(value), loc);
183 }
184
185 template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>, int> = 0>
186 static IntImm Int32(Enum value, Location loc = UnknownLoc()) {
187 return IntImm(PrimType::Int(32), value, std::move(loc));
188 }
189
195 static IntImm Int64(ffi::BigInt value, Location loc = UnknownLoc()) {
196 return IntImm(PrimType::Int(64), std::move(value), loc);
197 }
198
199 template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>, int> = 0>
200 static IntImm Int64(Enum value, Location loc = UnknownLoc()) {
201 return IntImm(PrimType::Int(64), value, std::move(loc));
202 }
203
204 explicit IntImm(ffi::ObjectPtr<IntImmNode> node) : PrimExpr(std::move(node)) {}
205
207 static constexpr bool _type_container_is_exact = true;
209};
210
216 public:
218 double value;
219
220 static void RegisterReflection() {
221 namespace refl = tvm::ffi::reflection;
222 refl::ObjectDef<FloatImmNode>().def_ro("value", &FloatImmNode::value);
223 }
225};
226
232class FloatImm : public PrimExpr {
233 public:
240 TVM_TIRX_DLL FloatImm(PrimType value_ty, double value, Location loc = UnknownLoc());
241
242 explicit FloatImm(ffi::ObjectPtr<FloatImmNode> node) : PrimExpr(std::move(node)) {}
243
245 static constexpr bool _type_container_is_exact = true;
247};
248
249namespace ffi {
250// Type traits to enable automatic conversion into IntImm, Integer, and Bool
251// when called through the FFI
252template <>
253inline constexpr bool use_default_type_traits_v<IntImm> = false;
254
255// specialize to enable implicit conversion from const char*
256template <>
257struct TypeTraits<IntImm> : public ObjectRefWithFallbackTraitsBase<IntImm, int64_t> {
258 TVM_FFI_INLINE static IntImm ConvertFallbackValue(int64_t value) {
259 auto value_ty =
260 (value > std::numeric_limits<int>::max() || value < std::numeric_limits<int>::min())
261 ? PrimType::Int(64)
262 : PrimType::Int(32);
263 return IntImm(value_ty, value);
264 }
265};
266
267template <>
268inline constexpr bool use_default_type_traits_v<FloatImm> = false;
269
270template <>
271struct TypeTraits<FloatImm> : public ObjectRefWithFallbackTraitsBase<FloatImm, double> {
272 TVM_FFI_INLINE static FloatImm ConvertFallbackValue(double value) {
273 return FloatImm(PrimType::Float(32), value);
274 }
275};
276template <>
277inline constexpr bool use_default_type_traits_v<tvm::StringImm> = false;
278
279template <>
280struct TypeTraits<tvm::StringImm>
281 : public ObjectRefWithFallbackTraitsBase<tvm::StringImm, ffi::String> {
282 TVM_FFI_INLINE static tvm::StringImm ConvertFallbackValue(ffi::String value) {
283 return tvm::StringImm(value);
284 }
285};
286
287// define automatic conversion from bool, int64_t, double to PrimExpr
288template <>
289inline constexpr bool use_default_type_traits_v<PrimExpr> = false;
290
291template <>
292struct TypeTraits<PrimExpr>
293 : public ObjectRefWithFallbackTraitsBase<PrimExpr, StrictBool, int64_t, double> {
294 using Base = ObjectRefWithFallbackTraitsBase<PrimExpr, StrictBool, int64_t, double>;
295 TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
296 if (src->type_index == TypeIndex::kTVMFFINone) return PrimExpr::_type_is_nullable;
297 return TypeTraits<TypedExpr<PrimType>>::CheckAnyStrict(src);
298 }
299
300 TVM_FFI_INLINE static std::optional<PrimExpr> TryCastFromAnyView(const TVMFFIAny* src) {
301 // A required expression cannot accept None.
302 if (src->type_index == TypeIndex::kTVMFFINone) return std::nullopt;
303 return Base::TryCastFromAnyView(src);
304 }
305
306 TVM_FFI_INLINE static std::string TypeStr() { return "ir.PrimExpr"; }
307
308 TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
309 return TypeTraits<TypedExpr<PrimType>>::GetMismatchTypeInfo(src);
310 }
311
312 TVM_FFI_INLINE static PrimExpr ConvertFallbackValue(StrictBool value) {
313 return IntImm::Bool(value);
314 }
315 TVM_FFI_INLINE static PrimExpr ConvertFallbackValue(int64_t value) {
316 return TypeTraits<IntImm>::ConvertFallbackValue(value);
317 }
318 TVM_FFI_INLINE static PrimExpr ConvertFallbackValue(double value) {
319 return TypeTraits<FloatImm>::ConvertFallbackValue(value);
320 }
321};
322
323template <>
324inline constexpr bool use_default_type_traits_v<IntExpr> = false;
325
326template <>
327struct TypeTraits<IntExpr> : public ObjectRefWithFallbackTraitsBase<IntExpr, int64_t> {
328 using Base = ObjectRefWithFallbackTraitsBase<IntExpr, int64_t>;
329
330 TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
331 if (!Base::CheckAnyStrict(src)) return false;
332 if (src->type_index == TypeIndex::kTVMFFINone) return true;
333 const auto* expr = details::ObjectUnsafe::RawObjectPtrFromUnowned<ExprNode>(src->v_obj);
334 const auto* ty = expr->ty.as<PrimTypeNode>();
335 return ty != nullptr && ty->dtype.lanes == 1 &&
336 (ty->dtype.code == kDLInt || ty->dtype.code == kDLUInt);
337 }
338
339 TVM_FFI_INLINE static IntExpr ConvertFallbackValue(int64_t value) {
340 return TypeTraits<PrimExpr>::ConvertFallbackValue(value).as_or_throw<IntExpr>();
341 }
342
343 TVM_FFI_INLINE static std::string TypeStr() { return "ir.IntExpr"; }
344
345 TVM_FFI_INLINE static std::string GetMismatchTypeInfo(const TVMFFIAny* src) {
346 return TypeTraits<TypedExpr<PrimType>>::GetMismatchTypeInfo(src);
347 }
348};
349
350// Generic Expr arguments accept primitive/string literals and arrays of expressions.
351template <>
352inline constexpr bool use_default_type_traits_v<Expr> = false;
353
354template <>
355struct TypeTraits<Expr> : public ObjectRefWithFallbackTraitsBase<Expr, PrimExpr, ffi::String> {
356 TVM_FFI_INLINE static Expr ConvertFallbackValue(PrimExpr value) { return value; }
357 TVM_FFI_INLINE static Expr ConvertFallbackValue(ffi::String value) { return StringImm(value); }
358 static std::optional<Expr> TryCastFromAnyView(const TVMFFIAny* src);
359};
360} // namespace ffi
361
363class TupleNode : public ExprNode {
364 public:
366 ffi::Array<Expr> fields;
367
368 static void RegisterReflection() {
369 namespace refl = tvm::ffi::reflection;
370 refl::ObjectDef<TupleNode>().def_ro("fields", &TupleNode::fields);
371 }
372
374};
375
377class Tuple : public Expr {
378 public:
384 TVM_TIRX_DLL explicit Tuple(ffi::Array<Expr> fields, Location loc = UnknownLoc());
385
386 explicit Tuple(ffi::ObjectPtr<TupleNode> node) : Expr(std::move(node)) {}
387
390};
391
392// Use ordinary inline: array elements recursively invoke this conversion.
393inline std::optional<Expr> ffi::TypeTraits<Expr>::TryCastFromAnyView(const TVMFFIAny* src) {
394 if (auto value =
395 ObjectRefWithFallbackTraitsBase<Expr, PrimExpr, ffi::String>::TryCastFromAnyView(src)) {
396 return value;
397 }
398 if (auto fields = ffi::TypeTraits<ffi::Array<Expr>>::TryCastFromAnyView(src)) {
399 return tvm::Tuple(std::move(*fields));
400 }
401 return std::nullopt;
402}
403
406 public:
407 explicit TupleGetItemNode(Expr tuple) : tuple(std::move(tuple)) {}
408 explicit TupleGetItemNode(ffi::UnsafeInit tag) : tuple(tag) {}
409
413 int index;
414
415 static void RegisterReflection() {
416 namespace refl = tvm::ffi::reflection;
417 refl::ObjectDef<TupleGetItemNode>()
418 .def_ro("tuple_value", &TupleGetItemNode::tuple)
419 .def_ro("index", &TupleGetItemNode::index);
420 }
421
423};
424
426class TupleGetItem : public Expr {
427 public:
435
436 explicit TupleGetItem(ffi::ObjectPtr<TupleGetItemNode> node) : Expr(std::move(node)) {}
437
440};
441
443class TensorLoadNode : public ExprNode {
444 public:
445 explicit TensorLoadNode(Expr source) : source(std::move(source)) {}
446 explicit TensorLoadNode(ffi::UnsafeInit tag) : source(tag) {}
447
451 ffi::Array<PrimExpr> indices;
452
453 static void RegisterReflection() {
454 namespace refl = tvm::ffi::reflection;
455 refl::ObjectDef<TensorLoadNode>()
456 .def_ro("source", &TensorLoadNode::source)
457 .def_ro("indices", &TensorLoadNode::indices);
458 }
459
461};
462
464class TensorLoad : public PrimExpr {
465 public:
466 explicit TensorLoad(ffi::ObjectPtr<TensorLoadNode> node) : PrimExpr(std::move(node)) {}
467
469 static constexpr bool _type_container_is_exact = true;
471};
472
483
494
504
515
526
537
548
559
570
581
592
603
614
624
634
643
654
665
676
686
694class VarNode : public ExprNode {
695 public:
697 ffi::String name;
698
699 static void RegisterReflection() {
700 namespace refl = tvm::ffi::reflection;
701 refl::ObjectDef<VarNode>().def_ro("name", &VarNode::name,
702 refl::AttachFieldFlag::SEqHashIgnore());
703 }
704
705 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindFreeVar;
706 static constexpr const uint32_t _type_child_slots = 1;
707 // VarNode reserves its sole child slot for the final relax::DataflowVarNode subtype, so its
708 // descendant type-index range cannot overflow.
709 static constexpr bool _type_child_slots_can_overflow = false;
711};
712
714class Var : public Expr {
715 public:
716 TVM_TIRX_DLL explicit Var(ffi::String name, ffi::Optional<Type> ty_annotation,
717 Location loc = UnknownLoc());
718
720 TVM_TIRX_DLL Var CopyWithName(const ffi::String& name) const;
721
723 TVM_TIRX_DLL Var CopyWithSuffix(const ffi::String& suffix) const;
724
727
730
731 explicit Var(ffi::ObjectPtr<VarNode> node) : Expr(std::move(node)) {}
732
734};
735
742class PrimVar : public PrimExpr {
743 public:
745 explicit PrimVar(ffi::String name, PrimType dtype = PrimType::Int(32),
746 Location loc = UnknownLoc())
747 : PrimExpr(Var(std::move(name), std::move(dtype), std::move(loc)).as_or_throw<PrimExpr>()) {}
748
750 explicit PrimVar(ffi::String name, Type type_annotation, Location loc = UnknownLoc())
751 : PrimExpr(Var(std::move(name), std::move(type_annotation), std::move(loc))
752 .as_or_throw<PrimExpr>()) {}
753
755 operator Var() const { return this->as_or_throw<Var>(); }
756
757 PrimVar CopyWithSuffix(const ffi::String& suffix) const {
758 return this->as_or_throw<Var>().CopyWithSuffix(suffix).as_or_throw<PrimVar>();
759 }
761 return this->as_or_throw<Var>().CopyWithDType(dtype).as_or_throw<PrimVar>();
762 }
763
764 explicit PrimVar(ffi::ObjectPtr<VarNode> node) : PrimExpr(std::move(node)) {}
765
767 static constexpr bool _type_container_is_exact = false;
768};
769
784 public:
786 ffi::Array<Var> vars;
789
790 explicit LambdaExprNode(ffi::UnsafeInit tag) : body(tag) {}
791 explicit LambdaExprNode(Expr body) : body(std::move(body)) {}
793 TVM_TIRX_DLL Expr Apply(const ffi::Array<Expr>& arguments) const;
794
795 static void RegisterReflection() {
796 namespace refl = tvm::ffi::reflection;
797 refl::ObjectDef<LambdaExprNode>()
798 .def_ro("vars", &LambdaExprNode::vars, refl::AttachFieldFlag::SEqHashDefSimple())
799 .def_ro("body", &LambdaExprNode::body);
800 }
801 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
803};
804
811
812class GlobalVar;
821class GlobalVarNode : public ExprNode {
822 public:
824 ffi::String name_hint;
825
826 static void RegisterReflection() {
827 namespace refl = tvm::ffi::reflection;
828 refl::ObjectDef<GlobalVarNode>().def_ro("name_hint", &GlobalVarNode::name_hint);
829 // A GlobalVar identifies a module-level symbol. Its type is derived from the
830 // corresponding function definition and is not part of the symbol identity.
831 refl::TypeAttrDef<GlobalVarNode>()
832 .def(tvm::ffi::reflection::type_attr::kSEqual, &GlobalVarNode::SEqual)
833 .def(tvm::ffi::reflection::type_attr::kSHash, &GlobalVarNode::SHash);
834 }
835
836 bool SEqual(const GlobalVarNode* other,
837 ffi::TypedFunction<bool(AnyView, AnyView, bool, AnyView)> equal) const {
838 return equal(name_hint, other->name_hint, false, "name_hint");
839 }
840
841 int64_t SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t, bool)> hash) const {
842 return hash(name_hint, init_hash, false);
843 }
844
845 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindFreeVar;
847};
848
853class GlobalVar : public Expr {
854 public:
855 TVM_TIRX_DLL explicit GlobalVar(ffi::String name_hint, Location loc = UnknownLoc());
856
857 explicit GlobalVar(ffi::ObjectPtr<GlobalVarNode> node) : Expr(std::move(node)) {}
858
861};
862
866enum class CallEffectKind : int {
868 kExprAnnotation = 0,
873 kPure = 1,
877 kReadState = 2,
881 kUpdateState = 3,
890 kSpecialCallArg = 4,
894 kEmbedInfo = 5,
898 kControlJump = 6,
899};
900
901inline std::ostream& operator<<(std::ostream& os, CallEffectKind side_effect) {
902 switch (side_effect) {
904 return os << "kExprAnnotation";
905
907 return os << "kPure";
908
910 return os << "kReadState";
911
913 return os << "kUpdateState";
914
916 return os << "kSpecialCallArg";
917
919 return os << "kEmbedInfo";
920
922 return os << "kControlJump";
923
924 default:
925 TVM_FFI_THROW(InternalError) << "Unknown CallEffectKind: " << static_cast<int>(side_effect);
926 }
927}
928
930using TCallEffectKind = int64_t;
931
935class CallNode : public ExprNode {
936 public:
937 explicit CallNode(Expr op) : op(std::move(op)) {}
938 explicit CallNode(ffi::UnsafeInit tag) : op(tag) {}
939
947
949 ffi::Array<Expr> args;
950
952 ffi::Optional<Attrs> attrs;
953
955 ffi::Array<Type> ty_args;
956
957 static void RegisterReflection() {
958 namespace refl = tvm::ffi::reflection;
959 refl::ObjectDef<CallNode>()
960 .def_ro("op", &CallNode::op)
961 .def_ro("args", &CallNode::args)
962 .def_ro("attrs", &CallNode::attrs)
963 .def_ro("ty_args", &CallNode::ty_args);
964 }
965
967};
968
972class Call : public Expr {
973 public:
977 TVM_TIRX_DLL Call(ffi::Optional<Type> ret_ty, Expr op, ffi::Array<Expr> args,
978 ffi::Optional<Attrs> attrs = std::nullopt,
979 ffi::Array<Type> ty_args = ffi::Array<Type>(), Location loc = UnknownLoc());
980
982 TVM_TIRX_DLL void Validate() const;
990
991 explicit Call(ffi::ObjectPtr<CallNode> node) : Expr(std::move(node)) {}
992
995};
996
998class RangeNode : public ffi::Object {
999 public:
1007 explicit RangeNode(ffi::UnsafeInit tag) : min(tag), extent(tag) {}
1010
1011 static void RegisterReflection() {
1012 namespace refl = tvm::ffi::reflection;
1013 refl::ObjectDef<RangeNode>()
1014 .def_ro("min", &RangeNode::min)
1015 .def_ro("extent", &RangeNode::extent)
1016 .def_ro("loc", &RangeNode::loc, refl::AttachFieldFlag::SEqHashIgnore());
1017 }
1018
1019 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
1020
1022};
1023
1025class Range : public ffi::ObjectRef {
1026 public:
1045 Location loc = UnknownLoc());
1046 // declare range.
1047 explicit Range(ffi::UnsafeInit tag, ffi::ObjectPtr<RangeNode> n) : ffi::ObjectRef(tag) {
1048 data_ = std::move(n);
1049 }
1050
1052};
1053
1056 public:
1057 explicit TensorRegionNode(Expr source) : source(std::move(source)) {}
1058 explicit TensorRegionNode(ffi::UnsafeInit tag) : source(tag) {}
1059
1063 ffi::Array<Range> region;
1064
1065 static void RegisterReflection() {
1066 namespace refl = tvm::ffi::reflection;
1067 // A region's source and symbolic source type form a definition pattern;
1068 // ranges then refer to those same identities.
1069 refl::ObjectDef<TensorRegionNode>()
1070 .def_ro("source", &TensorRegionNode::source, refl::AttachFieldFlag::SEqHashDefPattern())
1071 .def_ro("region", &TensorRegionNode::region);
1072 }
1073
1074 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
1076};
1077
1079class TensorRegion : public Expr {
1080 public:
1081 TVM_TIRX_DLL TensorRegion(Expr source, ffi::Array<Range> region, Type ty,
1082 Location loc = UnknownLoc());
1083
1084 explicit TensorRegion(ffi::ObjectPtr<TensorRegionNode> node) : Expr(std::move(node)) {}
1085
1088};
1089
1105
1106namespace ffi {
1107
1108template <>
1109inline constexpr bool use_default_type_traits_v<TensorRegion> = false;
1110
1111template <>
1112struct TypeTraits<TensorRegion> : public ObjectRefWithFallbackTraitsBase<TensorRegion, TensorLoad> {
1114};
1115
1116template <>
1117inline constexpr bool use_default_type_traits_v<PrimVar> = false;
1118
1119template <>
1120struct TypeTraits<PrimVar> : public ObjectRefTypeTraitsBase<PrimVar> {
1121 using Base = ObjectRefTypeTraitsBase<PrimVar>;
1122 using Base::CopyFromAnyViewAfterCheck;
1123 using Base::CopyToAnyView;
1124 using Base::GetMismatchTypeInfo;
1125 using Base::MoveFromAnyAfterCheck;
1126 using Base::MoveToAny;
1127 using Base::TypeSchema;
1128 using Base::TypeStr;
1129
1130 TVM_FFI_INLINE static bool CheckAnyStrict(const TVMFFIAny* src) {
1131 if (src->type_index == TypeIndex::kTVMFFINone) {
1132 return PrimVar::_type_is_nullable;
1133 }
1134 if (src->type_index != VarNode::RuntimeTypeIndex()) {
1135 return false;
1136 }
1137 const auto* var = static_cast<const VarNode*>(
1138 details::ObjectUnsafe::ObjectPtrFromUnowned<Object>(src->v_obj).get());
1139 return details::AnyUnsafe::CheckAnyStrict<PrimType>(var->ExprNode::ty);
1140 }
1141
1142 TVM_FFI_INLINE static std::optional<PrimVar> TryCastFromAnyView(const TVMFFIAny* src) {
1143 if (CheckAnyStrict(src)) {
1144 if (src->type_index == TypeIndex::kTVMFFINone) {
1145 return details::ObjectUnsafe::ObjectRefFromObjectPtr<PrimVar>(nullptr);
1146 }
1147 return details::ObjectUnsafe::ObjectRefFromObjectPtr<PrimVar>(
1148 details::ObjectUnsafe::ObjectPtrFromUnowned<VarNode>(src->v_obj));
1149 }
1150 return std::nullopt;
1151 }
1152};
1153
1154template <>
1156template <>
1158template <>
1160
1161} // namespace ffi
1162
1163namespace op_attr {
1164inline constexpr const char* kCallEffectKind = "TCallEffectKind";
1165} // namespace op_attr
1166
1167namespace type_attr {
1168inline constexpr const char* kSubscriptExprRealize = "__subscript_expr_realize__";
1169} // namespace type_attr
1170
1171} // namespace tvm
1172
1173/* \brief Allow tvm.Var and tvm.GlobalVar as keys in STL tables
1174 *
1175 * For most IR expressions, it would be ambiguous whether the
1176 * expression should follow reference equality or structural equality.
1177 * This is not the case for variables, which do not contain nested
1178 * internal structure, and are frequently used as keys in lookup
1179 * tables.
1180 *
1181 * Providing `std::hash` and `std::equal_to` specializations for
1182 * `tvm::Var` and `tvm::GlobalVar` allows them to be used as keys in STL tables. For
1183 * other IR expressions, the user must specify the type of equality
1184 * used (e.g. `std::unordered_set<T, StructuralHash, StructuralEqual>`
1185 * or `std::unordered_set<T, ffi::ObjectPtrHash, ffi::ObjectPtrEqual>`).
1186 */
1187template <>
1188struct std::hash<tvm::Var> {
1189 std::size_t operator()(const tvm::Var& var) const { return tvm::ffi::ObjectPtrHash()(var); }
1190};
1191
1192template <>
1193struct std::equal_to<tvm::Var> {
1194 bool operator()(const tvm::Var& var_a, const tvm::Var& var_b) const {
1195 return tvm::ffi::ObjectPtrEqual()(var_a, var_b);
1196 }
1197};
1198
1199template <>
1200struct std::hash<tvm::GlobalVar> {
1201 std::size_t operator()(const tvm::GlobalVar& var) const { return tvm::ffi::ObjectPtrHash()(var); }
1202};
1203
1204template <>
1205struct std::equal_to<tvm::GlobalVar> {
1206 bool operator()(const tvm::GlobalVar& var_a, const tvm::GlobalVar& var_b) const {
1207 return tvm::ffi::ObjectPtrEqual()(var_a, var_b);
1208 }
1209};
1210#endif // TVM_IR_EXPR_H_
Helpers for attribute objects.
Base expression and primitive type nodes.
Call corresponds to callable invocation.
Definition expr.h:935
ffi::Optional< Attrs > attrs
The additional attributes.
Definition expr.h:952
ffi::Array< Expr > args
The arguments of the call.
Definition expr.h:949
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Call", CallNode, ExprNode)
CallNode(ffi::UnsafeInit tag)
Definition expr.h:938
Expr op
The operator/function being invoked.
Definition expr.h:946
static void RegisterReflection()
Definition expr.h:957
CallNode(Expr op)
Definition expr.h:937
ffi::Array< Type > ty_args
The type information arguments passed to the callee.
Definition expr.h:955
Managed reference to CallNode.
Definition expr.h:972
TVM_TIRX_DLL Call(ffi::Optional< Type > ret_ty, Expr op, ffi::Array< Expr > args, ffi::Optional< Attrs > attrs=std::nullopt, ffi::Array< Type > ty_args=ffi::Array< Type >(), Location loc=UnknownLoc())
Construct a Call, inferring only when ret_ty is absent. Construction preserves provisional IR; invoke...
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Call, Expr, CallNode)
Call(ffi::ObjectPtr< CallNode > node)
Definition expr.h:991
TVM_DEFINE_OBJECT_REF_COW_METHOD(CallNode)
TVM_TIRX_DLL void Validate() const
Check this Call against its registered operator contract.
static TVM_TIRX_DLL Type ReinferType(const CallNode *call)
Recompute a result type from the Call's current explicit inputs.
Base node for literal constants.
Definition expr.h:50
static void RegisterReflection()
Definition expr.h:53
TVM_FFI_DECLARE_OBJECT_INFO("ir.Constant", ConstantNode, ExprNode)
static constexpr uint32_t _type_child_slots
Definition expr.h:52
Managed reference to a literal constant.
Definition expr.h:58
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Constant, Expr, ConstantNode)
Constant(ffi::ObjectPtr< ConstantNode > node)
Definition expr.h:60
A data type literal with AnyType as its expression type.
Definition expr.h:110
DLDataType value
Definition expr.h:112
static void RegisterReflection()
Definition expr.h:114
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.DataTypeImm", DataTypeImmNode, ConstantNode)
Managed reference to a data type literal.
Definition expr.h:121
DataTypeImm(ffi::ObjectPtr< DataTypeImmNode > node)
Definition expr.h:125
TVM_TIRX_DLL DataTypeImm(DLDataType value, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(DataTypeImmNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataTypeImm, Constant, DataTypeImmNode)
Base type of all the expressions.
Definition base_expr.h:324
Managed reference to ExprNode.
Definition base_expr.h:359
Constant floating point literals in the program.
Definition expr.h:215
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FloatImm", FloatImmNode, ConstantNode)
double value
The constant value content.
Definition expr.h:218
static void RegisterReflection()
Definition expr.h:220
Managed reference class to FloatImmNode.
Definition expr.h:232
TVM_TIRX_DLL FloatImm(PrimType value_ty, double value, Location loc=UnknownLoc())
Constructor.
static constexpr bool _type_container_is_exact
Definition expr.h:245
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloatImmNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FloatImm, PrimExpr, FloatImmNode)
FloatImm(ffi::ObjectPtr< FloatImmNode > node)
Definition expr.h:242
A constant whose payload is separate from its expression type.
Definition expr.h:66
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.GenericConst", GenericConstNode, ConstantNode)
static void RegisterReflection()
Definition expr.h:70
ffi::Any value
Definition expr.h:68
Managed reference to a generic constant.
Definition expr.h:77
TVM_DEFINE_OBJECT_REF_COW_METHOD(GenericConstNode)
GenericConst(ffi::ObjectPtr< GenericConstNode > node)
Definition expr.h:81
TVM_TIRX_DLL GenericConst(ffi::Any value, Type ty, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(GenericConst, Constant, GenericConstNode)
Global variable that lives in the top-level module.
Definition expr.h:821
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition expr.h:841
ffi::String name_hint
The name of the variable, this only acts as a hint.
Definition expr.h:824
static void RegisterReflection()
Definition expr.h:826
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.GlobalVar", GlobalVarNode, ExprNode)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:845
bool SEqual(const GlobalVarNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition expr.h:836
Managed reference to GlobalVarNode.
Definition expr.h:853
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(GlobalVar, Expr, GlobalVarNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(GlobalVarNode)
GlobalVar(ffi::ObjectPtr< GlobalVarNode > node)
Definition expr.h:857
TVM_TIRX_DLL GlobalVar(ffi::String name_hint, Location loc=UnknownLoc())
View over a scalar signed or unsigned integer expression of any bit width.
Definition base_expr.h:481
Constant integer literals in the program.
Definition expr.h:135
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.IntImm", IntImmNode, ConstantNode)
static void RegisterReflection()
Definition expr.h:140
ffi::BigInt value
the Internal value.
Definition expr.h:138
Managed reference class to IntImmNode.
Definition expr.h:152
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IntImm, PrimExpr, IntImmNode)
static constexpr bool _type_container_is_exact
Definition expr.h:207
static IntImm Int64(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int64 constant.
Definition expr.h:195
TVM_TIRX_DLL IntImm(PrimType value_ty, ffi::BigInt value, Location loc=UnknownLoc())
Constructor.
TVM_DEFINE_OBJECT_REF_COW_METHOD(IntImmNode)
static IntImm Bool(bool value, Location loc=UnknownLoc())
Construct a scalar boolean constant.
Definition expr.h:172
IntImm(PrimType value_ty, Enum value, Location loc=UnknownLoc())
Definition expr.h:163
IntImm(ffi::ObjectPtr< IntImmNode > node)
Definition expr.h:204
static IntImm Int32(Enum value, Location loc=UnknownLoc())
Definition expr.h:186
static IntImm Int64(Enum value, Location loc=UnknownLoc())
Definition expr.h:200
static IntImm Int32(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int32 constant.
Definition expr.h:181
A typed staging expression representing a lambda computation.
Definition expr.h:783
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.LambdaExpr", LambdaExprNode, StagingExprNode)
Expr body
Computation over the parameters and captured expressions.
Definition expr.h:788
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:801
TVM_TIRX_DLL Expr Apply(const ffi::Array< Expr > &arguments) const
Simultaneously substitute arguments for the bound parameters.
LambdaExprNode(ffi::UnsafeInit tag)
Definition expr.h:790
static void RegisterReflection()
Definition expr.h:795
ffi::Array< Var > vars
Lambda-local parameter definitions.
Definition expr.h:786
LambdaExprNode(Expr body)
Definition expr.h:791
Managed reference to a typed staging lambda.
Definition expr.h:806
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(LambdaExpr, StagingExpr, LambdaExprNode)
TVM_TIRX_DLL LambdaExpr(ffi::Array< Var > vars, Expr body)
Non-nullable source-location metadata.
Definition location.h:91
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Primitive data types used in the low-level IR.
Definition base_expr.h:143
DLDataType dtype
The raw DLPack dtype represented by this primitive type.
Definition base_expr.h:148
Definition base_expr.h:161
static TVM_TIRX_DLL PrimType Bool(int lanes=1)
Construct a boolean type with fixed lanes.
static TVM_TIRX_DLL PrimType Int(int bits, int lanes=1)
Construct a signed integer type with fixed lanes.
Checked scalar view over a VarNode.
Definition expr.h:742
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(PrimVar, PrimExpr, VarNode)
static constexpr bool _type_container_is_exact
Definition expr.h:767
PrimVar(ffi::ObjectPtr< VarNode > node)
Definition expr.h:764
PrimVar(ffi::String name, PrimType dtype=PrimType::Int(32), Location loc=UnknownLoc())
Construct a scalar variable directly from a primitive type.
Definition expr.h:745
PrimVar CopyWithDType(PrimType dtype) const
Definition expr.h:760
PrimVar CopyWithSuffix(const ffi::String &suffix) const
Definition expr.h:757
PrimVar(ffi::String name, Type type_annotation, Location loc=UnknownLoc())
Construct a scalar variable directly from a checked type annotation.
Definition expr.h:750
range over one dimension
Definition expr.h:998
static void RegisterReflection()
Definition expr.h:1011
PrimExpr min
beginning of the node
Definition expr.h:1001
RangeNode(PrimExpr min, PrimExpr extent, Location loc=UnknownLoc())
Definition expr.h:1008
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Range", RangeNode, ffi::Object)
RangeNode(ffi::UnsafeInit tag)
constructor
Definition expr.h:1007
PrimExpr extent
the extend of range
Definition expr.h:1003
Location loc
the location of this range in the source
Definition expr.h:1005
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:1019
Range container
Definition expr.h:1025
Range(ffi::UnsafeInit tag, ffi::ObjectPtr< RangeNode > n)
Definition expr.h:1047
static TVM_TIRX_DLL Range FromMinExtent(PrimExpr min, PrimExpr extent, Location loc=UnknownLoc())
construct a new range with min and extent The corresponding constructor is removed,...
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Range, ffi::ObjectRef, RangeNode)
TVM_TIRX_DLL Range(PrimExpr begin, PrimExpr end, Location loc=UnknownLoc())
constructor by begin and end
Base node for traversable expressions eliminated during compilation.
Definition base_expr.h:375
Managed reference to a staging expression.
Definition base_expr.h:383
A string literal with shared semantic StringType.
Definition expr.h:88
ffi::String value
Definition expr.h:90
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.StringImm", StringImmNode, ConstantNode)
static void RegisterReflection()
Definition expr.h:92
Managed reference to a string literal.
Definition expr.h:99
TVM_DEFINE_OBJECT_REF_COW_METHOD(StringImmNode)
TVM_TIRX_DLL StringImm(ffi::String value, Location loc=UnknownLoc())
StringImm(ffi::ObjectPtr< StringImmNode > node)
Definition expr.h:103
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(StringImm, Constant, StringImmNode)
Load a value from an indexed expression source.
Definition expr.h:443
TensorLoadNode(Expr source)
Definition expr.h:445
ffi::Array< PrimExpr > indices
The indices at which the source is loaded.
Definition expr.h:451
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorLoad", TensorLoadNode, ExprNode)
TensorLoadNode(ffi::UnsafeInit tag)
Definition expr.h:446
Expr source
The indexed source expression.
Definition expr.h:449
static void RegisterReflection()
Definition expr.h:453
Managed reference to TensorLoadNode.
Definition expr.h:464
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorLoad, PrimExpr, TensorLoadNode)
static constexpr bool _type_container_is_exact
Definition expr.h:469
TensorLoad(ffi::ObjectPtr< TensorLoadNode > node)
Definition expr.h:466
TVM_DEFINE_OBJECT_REF_COW_METHOD(TensorLoadNode)
A region of an indexed expression source.
Definition expr.h:1055
TensorRegionNode(ffi::UnsafeInit tag)
Definition expr.h:1058
Expr source
The indexed source expression.
Definition expr.h:1061
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TensorRegion", TensorRegionNode, ExprNode)
TensorRegionNode(Expr source)
Definition expr.h:1057
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:1074
ffi::Array< Range > region
The ranges selected from the source.
Definition expr.h:1063
static void RegisterReflection()
Definition expr.h:1065
Managed reference to TensorRegionNode.
Definition expr.h:1079
TVM_TIRX_DLL TensorRegion(Expr source, ffi::Array< Range > region, Type ty, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(TensorRegionNode)
TensorRegion(ffi::ObjectPtr< TensorRegionNode > node)
Definition expr.h:1084
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TensorRegion, Expr, TensorRegionNode)
Get the index-th field out of a tuple.
Definition expr.h:405
TupleGetItemNode(Expr tuple)
Definition expr.h:407
Expr tuple
The tuple expression.
Definition expr.h:411
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.TupleGetItem", TupleGetItemNode, ExprNode)
static void RegisterReflection()
Definition expr.h:415
TupleGetItemNode(ffi::UnsafeInit tag)
Definition expr.h:408
int index
The field index.
Definition expr.h:413
Managed reference to TupleGetItemNode.
Definition expr.h:426
TupleGetItem(ffi::ObjectPtr< TupleGetItemNode > node)
Definition expr.h:436
TVM_DEFINE_OBJECT_REF_COW_METHOD(TupleGetItemNode)
TVM_TIRX_DLL TupleGetItem(Expr tuple, int index, Location loc=UnknownLoc())
Construct a tuple field projection.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TupleGetItem, Expr, TupleGetItemNode)
Tuple container.
Definition expr.h:363
ffi::Array< Expr > fields
The fields of the tuple.
Definition expr.h:366
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Tuple", TupleNode, ExprNode)
static void RegisterReflection()
Definition expr.h:368
Managed reference to TupleNode.
Definition expr.h:377
TVM_TIRX_DLL Tuple(ffi::Array< Expr > fields, Location loc=UnknownLoc())
Construct a tuple from its fields.
TVM_DEFINE_OBJECT_REF_COW_METHOD(TupleNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Tuple, Expr, TupleNode)
Tuple(ffi::ObjectPtr< TupleNode > node)
Definition expr.h:386
Managed reference to TypeNode.
Definition base_expr.h:80
Reference to the shared immutable unknown location.
Definition location.h:105
A local variable in the IR.
Definition expr.h:694
TVM_FFI_DECLARE_OBJECT_INFO("ir.Var", VarNode, ExprNode)
static constexpr const uint32_t _type_child_slots
Definition expr.h:706
static constexpr bool _type_child_slots_can_overflow
Definition expr.h:709
ffi::String name
The variable name.
Definition expr.h:697
static void RegisterReflection()
Definition expr.h:699
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:705
Managed reference to VarNode.
Definition expr.h:714
TVM_TIRX_DLL Var CopyWithDType(PrimType dtype) const
Return a fresh ordinary Var with a new primitive type.
TVM_TIRX_DLL Var(ffi::String name, ffi::Optional< Type > ty_annotation, Location loc=UnknownLoc())
TVM_TIRX_DLL Var CopyWithType(Type type) const
Return a fresh ordinary Var with a new type, retaining its metadata.
TVM_TIRX_DLL Var CopyWithSuffix(const ffi::String &suffix) const
Return a fresh ordinary Var with a suffix appended to its name.
Var(ffi::ObjectPtr< VarNode > node)
Definition expr.h:731
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Var, Expr, VarNode)
TVM_TIRX_DLL Var CopyWithName(const ffi::String &name) const
Return a fresh ordinary Var with the same type and a new name.
Copy-on-write helper macro for IR ffi::ObjectRef types.
Source locations and source-text lookup.
constexpr bool use_default_type_traits_v< PrimVar >
Definition expr.h:1117
constexpr bool use_default_type_traits_v< Expr >
Definition expr.h:352
constexpr bool use_default_type_traits_v< PrimExpr >
Definition expr.h:289
constexpr bool use_default_type_traits_v< TensorRegion >
Definition expr.h:1109
constexpr bool object_ref_contains_v< PrimExpr, IntImmNode >
Definition expr.h:1155
constexpr bool object_ref_contains_v< PrimExpr, TensorLoadNode >
Definition expr.h:1159
constexpr bool use_default_type_traits_v< IntExpr >
Definition expr.h:324
constexpr bool object_ref_contains_v< PrimExpr, FloatImmNode >
Definition expr.h:1157
constexpr bool use_default_type_traits_v< FloatImm >
Definition expr.h:268
constexpr bool use_default_type_traits_v< IntImm >
Definition expr.h:253
constexpr const char * kCallEffectKind
Definition expr.h:1164
PrimVar var(std::string name_hint, PrimType t=PrimType::Int(32))
Construct a new Var expression.
constexpr const char * kSubscriptExprRealize
Definition expr.h:1168
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL CallEffectKind SideEffect(const Expr &expr)
Analyze the runtime effects of an expression.
int64_t TCallEffectKind
Use integer to record the kind.
Definition expr.h:930
TVM_TIRX_DLL PrimExpr operator<(PrimExpr a, PrimExpr b)
less
TVM_TIRX_DLL PrimExpr operator!(PrimExpr a)
not
TVM_TIRX_DLL PrimExpr min(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
take minimum of two values
TVM_TIRX_DLL PrimExpr operator<=(PrimExpr a, PrimExpr b)
less_equal
bool operator!=(const PrimType &lhs, const PrimType &rhs)
Definition base_expr.h:318
TVM_TIRX_DLL PrimExpr operator~(PrimExpr a)
take bitwise negation of two values
TVM_TIRX_DLL PrimExpr operator>=(PrimExpr a, PrimExpr b)
greater_equal
TVM_TIRX_DLL PrimExpr operator+(PrimExpr a, PrimExpr b)
add operator
TVM_TIRX_DLL PrimExpr operator>(PrimExpr a, PrimExpr b)
greater
TVM_TIRX_DLL PrimExpr equal(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
equal
TVM_TIRX_DLL PrimExpr operator/(PrimExpr a, PrimExpr b)
division operator
TVM_TIRX_DLL PrimExpr operator||(PrimExpr a, PrimExpr b)
or
TVM_TIRX_DLL PrimExpr operator^(PrimExpr a, PrimExpr b)
take bitwise xor of two values
TVM_TIRX_DLL PrimExpr operator&(PrimExpr a, PrimExpr b)
take bitwise and of two values
CallEffectKind
The effect type of the call.
Definition expr.h:866
@ kControlJump
Function that changes control flow.
@ kOpaque
Opaque function, cannot make any assumption.
@ kExprAnnotation
Function corresponds to an annotation(e.g. likely) and can translate to identity.
@ kPure
Pure function that do not interacts with any external state.
@ kReadState
Function's that may read from states(e.g. RAM)
@ kEmbedInfo
Embed opaque information in the Expr, cannot be codegen.
@ kSpecialCallArg
Special intrinsic to annotate call arguments info only valid as a direct argument to a call.
@ kUpdateState
Function that may read/write from states(e.g. RAM).
TVM_TIRX_DLL PrimExpr operator>>(PrimExpr a, PrimExpr b)
right shift operator
bool operator==(const PrimType &lhs, const PrimType &rhs)
Definition base_expr.h:314
TVM_TIRX_DLL PrimExpr operator|(PrimExpr a, PrimExpr b)
take bitwise or of two values
TVM_TIRX_DLL PrimExpr operator&&(PrimExpr a, PrimExpr b)
and
TVM_TIRX_DLL PrimExpr operator*(PrimExpr a, PrimExpr b)
multiplication operator
TVM_TIRX_DLL PrimExpr operator<<(PrimExpr a, PrimExpr b)
left shift operator
TVM_TIRX_DLL PrimExpr operator-(PrimExpr a, PrimExpr b)
subtraction operator
#define TVM_TIRX_DLL
Definition base.h:83
static TVM_FFI_INLINE Expr ConvertFallbackValue(PrimExpr value)
Definition expr.h:356
static TVM_FFI_INLINE Expr ConvertFallbackValue(ffi::String value)
Definition expr.h:357
static TVM_FFI_INLINE FloatImm ConvertFallbackValue(double value)
Definition expr.h:272
static TVM_FFI_INLINE IntExpr ConvertFallbackValue(int64_t value)
Definition expr.h:339
static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const TVMFFIAny *src)
Definition expr.h:345
static TVM_FFI_INLINE std::string TypeStr()
Definition expr.h:343
ObjectRefWithFallbackTraitsBase< IntExpr, int64_t > Base
Definition expr.h:328
static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny *src)
Definition expr.h:330
static TVM_FFI_INLINE IntImm ConvertFallbackValue(int64_t value)
Definition expr.h:258
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(int64_t value)
Definition expr.h:315
static TVM_FFI_INLINE std::string GetMismatchTypeInfo(const TVMFFIAny *src)
Definition expr.h:308
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(double value)
Definition expr.h:318
static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny *src)
Definition expr.h:295
ObjectRefWithFallbackTraitsBase< PrimExpr, StrictBool, int64_t, double > Base
Definition expr.h:294
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(StrictBool value)
Definition expr.h:312
static TVM_FFI_INLINE std::string TypeStr()
Definition expr.h:306
static TVM_FFI_INLINE std::optional< PrimExpr > TryCastFromAnyView(const TVMFFIAny *src)
Definition expr.h:300
static TVM_FFI_INLINE std::optional< PrimVar > TryCastFromAnyView(const TVMFFIAny *src)
Definition expr.h:1142
static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny *src)
Definition expr.h:1130
ObjectRefTypeTraitsBase< PrimVar > Base
Definition expr.h:1121
static TVM_TIRX_DLL TensorRegion ConvertFallbackValue(TensorLoad value)
static TVM_FFI_INLINE tvm::StringImm ConvertFallbackValue(ffi::String value)
Definition expr.h:282