24 #ifndef TVM_IR_EXPR_H_
25 #define TVM_IR_EXPR_H_
27 #include <tvm/ffi/reflection/registry.h>
28 #include <tvm/ffi/string.h>
40 #include <type_traits>
63 refl::AttachFieldFlag::SEqHashIgnore());
181 :
public ObjectRefWithFallbackTraitsBase<PrimExpr, StrictBool, int64_t, double, ffi::String,
182 PrimExprConvertible> {
183 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(StrictBool value);
184 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(int64_t value);
185 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(
double value);
190 return value->ToPrimExpr();
425 mutable ffi::Optional<ObjectRef>
struct_info_ = ffi::Optional<ObjectRef>();
430 refl::AttachFieldFlag::SEqHashIgnore());
466 ffi::TypedFunction<
bool(AnyView, AnyView,
bool, AnyView)>
equal)
const {
470 int64_t
SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t,
bool)> hash)
const {
471 return hash(
name_hint, init_hash,
false);
570 operator bool()
const {
return (*this)->value != 0; }
579 return Bool(a.operator
bool() || b.operator
bool());
584 return Bool(a.operator
bool() && b.operator
bool());
590 return a.operator bool() == b.operator bool();
626 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
628 static_assert(std::is_same<
int,
typename std::underlying_type<Enum>::type>::value,
629 "declare enum to be enum int to use visitor");
636 data_ = ffi::details::ObjectUnsafe::ObjectPtrFromObjectRef<Object>(other);
643 TVM_FFI_ICHECK(data_ !=
nullptr) <<
" Trying to reference a null Integer";
644 return (*this)->value;
648 if (data_ ==
nullptr)
return Bool(
false);
649 return Bool((*this)->value == other);
652 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
654 return *
this ==
static_cast<int>(other);
656 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
658 return *
this !=
static_cast<int>(other);
678 refl::ObjectDef<RangeNode>()
681 .def_ro(
"span", &
RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore());
722 struct TypeTraits<
IntImm> :
public ObjectRefWithFallbackTraitsBase<IntImm, int64_t> {
728 return IntImm(dtype, value);
736 struct TypeTraits<
Integer> :
public ObjectRefWithFallbackTraitsBase<Integer, int64_t> {
746 struct TypeTraits<
FloatImm> :
public ObjectRefWithFallbackTraitsBase<FloatImm, double> {
756 struct TypeTraits<
Bool> :
public ObjectRefWithFallbackTraitsBase<Bool, int64_t> {
792 return tvm::runtime::ObjectPtrHash()(
var);
799 return tvm::runtime::ObjectPtrEqual()(var_a, var_b);
Base type of all the expressions.
Definition: expr.h:51
TVM_FFI_DECLARE_OBJECT_INFO("ir.BaseExpr", BaseExprNode, Object)
static constexpr const uint32_t _type_child_slots
Definition: expr.h:68
static void RegisterReflection()
Definition: expr.h:59
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:66
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:57
Managed reference to BaseExprNode.
Definition: expr.h:76
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(BaseExpr, ObjectRef, BaseExprNode)
Boolean constant.
Definition: expr.h:566
Bool operator!() const
Definition: expr.h:569
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Bool, IntImm, IntImmNode)
Bool(bool value, Span span=Span())
Definition: expr.h:568
Constant floating point literals in the program.
Definition: expr.h:529
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FloatImm", FloatImmNode, PrimExprNode)
double value
The constant value content.
Definition: expr.h:532
static void RegisterReflection()
Definition: expr.h:534
Managed reference class to FloatImmNode.
Definition: expr.h:546
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FloatImm, PrimExpr, FloatImmNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloatImmNode)
FloatImm(DataType dtype, double value, Span span=Span())
Constructor.
Global variable that lives in the top-level module.
Definition: expr.h:455
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.GlobalVar", GlobalVarNode, RelaxExprNode)
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition: expr.h:470
ffi::String name_hint
The name of the variable, this only acts as a hint.
Definition: expr.h:458
static void RegisterReflection()
Definition: expr.h:460
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:474
bool SEqual(const GlobalVarNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition: expr.h:465
Managed reference to GlobalVarNode.
Definition: expr.h:482
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GlobalVar, RelaxExpr, GlobalVarNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(GlobalVarNode)
GlobalVar(ffi::String name_hint, Span span={})
Constant integer literals in the program.
Definition: expr.h:494
static void RegisterReflection()
Definition: expr.h:499
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.IntImm", IntImmNode, PrimExprNode)
int64_t value
the Internal value.
Definition: expr.h:497
Managed reference class to IntImmNode.
Definition: expr.h:511
TVM_DEFINE_OBJECT_REF_COW_METHOD(IntImmNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(IntImm, PrimExpr, IntImmNode)
IntImm(DataType dtype, int64_t value, Span span=Span())
Constructor.
Container of constant int that adds more constructors.
Definition: expr.h:601
Bool operator!=(Enum other) const
Definition: expr.h:657
Integer()
Definition: expr.h:603
Bool operator!=(int other) const
Definition: expr.h:651
Integer(Enum value)
Constructor from enum.
Definition: expr.h:627
Bool operator==(int other) const
Definition: expr.h:647
Integer(ffi::UnsafeInit tag)
constructor with UnsafeInit
Definition: expr.h:611
Integer(IntImm other)
Construct integer from int imm.
Definition: expr.h:620
int64_t IntValue() const
convert to int64_t
Definition: expr.h:642
Integer(ObjectPtr< IntImmNode > node)
constructor from node.
Definition: expr.h:607
Bool operator==(Enum other) const
Definition: expr.h:653
Integer & operator=(const IntImm &other)
Assign an expression to integer.
Definition: expr.h:635
Integer(int value, Span span=Span())
Construct integer from int value.
Definition: expr.h:615
Base class for other IR constructs that can be converted to PrimExpr. This is useful for the FFI to c...
Definition: expr.h:156
TVM_FFI_DECLARE_OBJECT_INFO("ir.PrimExprConvertible", PrimExprConvertibleNode, Object)
virtual ~PrimExprConvertibleNode()
Definition: expr.h:158
virtual PrimExpr ToPrimExpr() const =0
Managed reference to PrimExprConvertibleNode.
Definition: expr.h:167
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PrimExprConvertible, ObjectRef, PrimExprConvertibleNode)
Base node of all primitive expressions.
Definition: expr.h:93
static constexpr const uint32_t _type_child_slots
Definition: expr.h:118
TVM_OBJECT_ENABLE_SCRIPT_PRINTER()
TVM_FFI_DECLARE_OBJECT_INFO("ir.PrimExpr", PrimExprNode, BaseExprNode)
DataType dtype
The runtime data type of the primitive expression.
Definition: expr.h:109
static void RegisterReflection()
Definition: expr.h:111
Reference to PrimExprNode.
Definition: expr.h:126
DataType dtype() const
Definition: expr.h:140
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PrimExpr, BaseExpr, PrimExprNode)
PrimExpr(float value)
construct from float.
PrimExpr(int32_t value)
construct from integer.
static PrimExpr ConvertFallbackValue(ffi::String value)
construct from string to form a StringImm.
range over one dimension
Definition: expr.h:663
static void RegisterReflection()
Definition: expr.h:676
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Range", RangeNode, Object)
PrimExpr min
beginning of the node
Definition: expr.h:666
RangeNode(PrimExpr min, PrimExpr extent, Span span=Span())
Definition: expr.h:673
RangeNode()
constructor
Definition: expr.h:672
PrimExpr extent
the extend of range
Definition: expr.h:668
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:684
Span span
the location of this range in the source
Definition: expr.h:670
Range container
Definition: expr.h:690
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Range, ObjectRef, RangeNode)
static Range FromMinExtent(PrimExpr min, PrimExpr extent, Span span=Span())
construct a new range with min and extent The corresponding constructor is removed,...
Range(PrimExpr begin, PrimExpr end, Span span=Span())
constructor by begin and end
Base node of all non-primitive expressions.
Definition: expr.h:418
ffi::Optional< ObjectRef > struct_info_
Stores the result of structure information of the expression that encapsulate both static shape and r...
Definition: expr.h:425
TVM_FFI_DECLARE_OBJECT_INFO("ir.RelaxExpr", RelaxExprNode, BaseExprNode)
static void RegisterReflection()
Definition: expr.h:427
static constexpr const uint32_t _type_child_slots
Definition: expr.h:433
Managed reference to RelaxExprNode.
Definition: expr.h:441
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(RelaxExpr, BaseExpr, RelaxExprNode)
Definition: source_map.h:111
Runtime primitive data type.
Definition: data_type.h:47
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:295
static DataType Bool(int lanes=1, bool is_scalable=false)
Construct a bool type.
Definition: data_type.h:387
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:278
IR/AST nodes for the unified type system in TVM.
Definition: repr_printer.h:91
constexpr bool use_default_type_traits_v< PrimExpr >
Definition: expr.h:177
constexpr bool use_default_type_traits_v< Bool >
Definition: expr.h:753
constexpr bool use_default_type_traits_v< Integer >
Definition: expr.h:733
constexpr bool use_default_type_traits_v< FloatImm >
Definition: expr.h:743
constexpr bool use_default_type_traits_v< IntImm >
Definition: expr.h:718
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
PrimExpr operator!=(PrimExpr a, PrimExpr b)
not_equal
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
PrimExpr operator/(PrimExpr a, PrimExpr b)
division operator
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
PrimExpr operator>>(PrimExpr a, PrimExpr b)
right shift operator
PrimExpr operator<(PrimExpr a, PrimExpr b)
less
PrimExpr operator|(PrimExpr a, PrimExpr b)
take bitwise or of two values
PrimExpr operator==(PrimExpr a, PrimExpr b)
equal
PrimExpr operator~(PrimExpr a)
take bitwise negation of two values
PrimExpr operator>=(PrimExpr a, PrimExpr b)
greater_equal
PrimExpr operator<=(PrimExpr a, PrimExpr b)
less_equal
PrimExpr operator*(PrimExpr a, PrimExpr b)
multiplication operator
PrimExpr operator&(PrimExpr a, PrimExpr b)
take bitwise and of two values
PrimExpr min(PrimExpr a, PrimExpr b, Span span=Span())
take minimum of two values
PrimExpr operator!(PrimExpr a)
not
PrimExpr operator^(PrimExpr a, PrimExpr b)
take bitwise xor of two values
PrimExpr operator-(PrimExpr a, PrimExpr b)
subtraction operator
PrimExpr operator||(PrimExpr a, PrimExpr b)
or
PrimExpr operator>(PrimExpr a, PrimExpr b)
greater
PrimExpr operator+(PrimExpr a, PrimExpr b)
add operator
PrimExpr operator<<(PrimExpr a, PrimExpr b)
left shift operator
PrimExpr operator&&(PrimExpr a, PrimExpr b)
and
A managed object in the TVM runtime.
Printer class to print repr string of each AST/IR nodes.
A map from source names to source code.
static TVM_FFI_INLINE Bool ConvertFallbackValue(int64_t value)
Definition: expr.h:757
static TVM_FFI_INLINE FloatImm ConvertFallbackValue(double value)
Definition: expr.h:747
static TVM_FFI_INLINE IntImm ConvertFallbackValue(int64_t value)
Definition: expr.h:723
static TVM_FFI_INLINE Integer ConvertFallbackValue(int64_t value)
Definition: expr.h:737
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(StrictBool value)
Definition: expr.h:761
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(ffi::String value)
Definition: expr.h:186
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(PrimExprConvertible value)
Definition: expr.h:189