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>
38 #include <type_traits>
61 refl::AttachFieldFlag::SEqHashIgnore());
179 :
public ObjectRefWithFallbackTraitsBase<PrimExpr, StrictBool, int64_t, double, ffi::String,
180 PrimExprConvertible> {
181 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(StrictBool value);
182 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(int64_t value);
183 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(
double value);
188 return value->ToPrimExpr();
423 mutable ffi::Optional<ObjectRef>
struct_info_ = ffi::Optional<ObjectRef>();
428 refl::AttachFieldFlag::SEqHashIgnore());
464 ffi::TypedFunction<
bool(AnyView, AnyView,
bool, AnyView)>
equal)
const {
469 ffi::TypedFunction<uint64_t(AnyView, uint64_t,
bool)> hash)
const {
470 return hash(
name_hint, init_hash,
false);
569 operator bool()
const {
return (*this)->value != 0; }
578 return Bool(a.operator
bool() || b.operator
bool());
583 return Bool(a.operator
bool() && b.operator
bool());
589 return a.operator bool() == b.operator bool();
625 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
627 static_assert(std::is_same<
int,
typename std::underlying_type<Enum>::type>::value,
628 "declare enum to be enum int to use visitor");
635 data_ = ffi::details::ObjectUnsafe::ObjectPtrFromObjectRef<Object>(other);
642 ICHECK(data_ !=
nullptr) <<
" Trying to reference a null Integer";
643 return (*this)->value;
647 if (data_ ==
nullptr)
return Bool(
false);
648 return Bool((*this)->value == other);
651 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
653 return *
this ==
static_cast<int>(other);
655 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
657 return *
this !=
static_cast<int>(other);
677 refl::ObjectDef<RangeNode>()
680 .def_ro(
"span", &
RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore());
721 struct TypeTraits<
IntImm> :
public ObjectRefWithFallbackTraitsBase<IntImm, int64_t> {
727 return IntImm(dtype, value);
735 struct TypeTraits<
Integer> :
public ObjectRefWithFallbackTraitsBase<Integer, int64_t> {
745 struct TypeTraits<
FloatImm> :
public ObjectRefWithFallbackTraitsBase<FloatImm, double> {
755 struct TypeTraits<
Bool> :
public ObjectRefWithFallbackTraitsBase<Bool, int64_t> {
791 return tvm::runtime::ObjectPtrHash()(
var);
798 return tvm::runtime::ObjectPtrEqual()(var_a, var_b);
Base type of all the expressions.
Definition: expr.h:49
TVM_FFI_DECLARE_OBJECT_INFO("ir.BaseExpr", BaseExprNode, Object)
static constexpr const uint32_t _type_child_slots
Definition: expr.h:66
static void RegisterReflection()
Definition: expr.h:57
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:64
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:55
Managed reference to BaseExprNode.
Definition: expr.h:74
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(BaseExpr, ObjectRef, BaseExprNode)
Boolean constant.
Definition: expr.h:565
Bool operator!() const
Definition: expr.h:568
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Bool, IntImm, IntImmNode)
Bool(bool value, Span span=Span())
Definition: expr.h:567
Constant floating point literals in the program.
Definition: expr.h:528
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.FloatImm", FloatImmNode, PrimExprNode)
double value
The constant value content.
Definition: expr.h:531
static void RegisterReflection()
Definition: expr.h:533
Managed reference class to FloatImmNode.
Definition: expr.h:545
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:453
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.GlobalVar", GlobalVarNode, RelaxExprNode)
ffi::String name_hint
The name of the variable, this only acts as a hint.
Definition: expr.h:456
uint64_t SHash(uint64_t init_hash, ffi::TypedFunction< uint64_t(AnyView, uint64_t, bool)> hash) const
Definition: expr.h:468
static void RegisterReflection()
Definition: expr.h:458
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:473
bool SEqual(const GlobalVarNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition: expr.h:463
Managed reference to GlobalVarNode.
Definition: expr.h:481
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:493
static void RegisterReflection()
Definition: expr.h:498
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.IntImm", IntImmNode, PrimExprNode)
int64_t value
the Internal value.
Definition: expr.h:496
Managed reference class to IntImmNode.
Definition: expr.h:510
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:600
Bool operator!=(Enum other) const
Definition: expr.h:656
Integer()
Definition: expr.h:602
Bool operator!=(int other) const
Definition: expr.h:650
Integer(Enum value)
Constructor from enum.
Definition: expr.h:626
Bool operator==(int other) const
Definition: expr.h:646
Integer(ffi::UnsafeInit tag)
constructor with UnsafeInit
Definition: expr.h:610
Integer(IntImm other)
Construct integer from int imm.
Definition: expr.h:619
int64_t IntValue() const
convert to int64_t
Definition: expr.h:641
Integer(ObjectPtr< IntImmNode > node)
constructor from node.
Definition: expr.h:606
Bool operator==(Enum other) const
Definition: expr.h:652
Integer & operator=(const IntImm &other)
Assign an expression to integer.
Definition: expr.h:634
Integer(int value, Span span=Span())
Construct integer from int value.
Definition: expr.h:614
Base class for other IR constructs that can be converted to PrimExpr. This is useful for the FFI to c...
Definition: expr.h:154
TVM_FFI_DECLARE_OBJECT_INFO("ir.PrimExprConvertible", PrimExprConvertibleNode, Object)
virtual ~PrimExprConvertibleNode()
Definition: expr.h:156
virtual PrimExpr ToPrimExpr() const =0
Managed reference to PrimExprConvertibleNode.
Definition: expr.h:165
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PrimExprConvertible, ObjectRef, PrimExprConvertibleNode)
Base node of all primitive expressions.
Definition: expr.h:91
static constexpr const uint32_t _type_child_slots
Definition: expr.h:116
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:107
static void RegisterReflection()
Definition: expr.h:109
Reference to PrimExprNode.
Definition: expr.h:124
DataType dtype() const
Definition: expr.h:138
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:662
static void RegisterReflection()
Definition: expr.h:675
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Range", RangeNode, Object)
PrimExpr min
beginning of the node
Definition: expr.h:665
RangeNode(PrimExpr min, PrimExpr extent, Span span=Span())
Definition: expr.h:672
RangeNode()
constructor
Definition: expr.h:671
PrimExpr extent
the extend of range
Definition: expr.h:667
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:683
Span span
the location of this range in the source
Definition: expr.h:669
Range container
Definition: expr.h:689
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:416
ffi::Optional< ObjectRef > struct_info_
Stores the result of structure information of the expression that encapsulate both static shape and r...
Definition: expr.h:423
TVM_FFI_DECLARE_OBJECT_INFO("ir.RelaxExpr", RelaxExprNode, BaseExprNode)
static void RegisterReflection()
Definition: expr.h:425
static constexpr const uint32_t _type_child_slots
Definition: expr.h:431
Managed reference to RelaxExprNode.
Definition: expr.h:439
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:291
static DataType Bool(int lanes=1, bool is_scalable=false)
Construct a bool type.
Definition: data_type.h:383
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:274
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:175
constexpr bool use_default_type_traits_v< Bool >
Definition: expr.h:752
constexpr bool use_default_type_traits_v< Integer >
Definition: expr.h:732
constexpr bool use_default_type_traits_v< FloatImm >
Definition: expr.h:742
constexpr bool use_default_type_traits_v< IntImm >
Definition: expr.h:717
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Performance counters for profiling via the PAPI library.
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
Definitions and helper macros for IR/AST nodes.
A managed object in the TVM runtime.
A map from source names to source code.
static TVM_FFI_INLINE Bool ConvertFallbackValue(int64_t value)
Definition: expr.h:756
static TVM_FFI_INLINE FloatImm ConvertFallbackValue(double value)
Definition: expr.h:746
static TVM_FFI_INLINE IntImm ConvertFallbackValue(int64_t value)
Definition: expr.h:722
static TVM_FFI_INLINE Integer ConvertFallbackValue(int64_t value)
Definition: expr.h:736
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(StrictBool value)
Definition: expr.h:760
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(ffi::String value)
Definition: expr.h:184
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(PrimExprConvertible value)
Definition: expr.h:187