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>
63 refl::AttachFieldFlag::SEqHashIgnore());
66 static constexpr
const char*
_type_key =
"ir.BaseExpr";
164 static constexpr
const char*
_type_key =
"ir.PrimExprConvertible";
185 :
public ObjectRefWithFallbackTraitsBase<PrimExpr, StrictBool, int64_t, double, String,
186 PrimExprConvertible> {
187 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(StrictBool value);
188 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(int64_t value);
189 TVM_FFI_INLINE
static PrimExpr ConvertFallbackValue(
double value);
194 return value->ToPrimExpr();
434 refl::AttachFieldFlag::SEqHashIgnore());
437 static constexpr
const char*
_type_key =
"ir.RelaxExpr";
471 ffi::TypedFunction<
bool(AnyView, AnyView,
bool, AnyView)>
equal)
const {
476 ffi::TypedFunction<uint64_t(AnyView, uint64_t,
bool)> hash)
const {
477 return hash(
name_hint, init_hash,
false);
481 static constexpr
const char*
_type_key =
"ir.GlobalVar";
581 operator bool()
const {
return (*this)->value != 0; }
590 return Bool(a.operator
bool() || b.operator
bool());
595 return Bool(a.operator
bool() && b.operator
bool());
601 return a.operator bool() == b.operator bool();
633 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
635 static_assert(std::is_same<
int,
typename std::underlying_type<Enum>::type>::value,
636 "declare enum to be enum int to use visitor");
643 data_ = ffi::details::ObjectUnsafe::ObjectPtrFromObjectRef<Object>(other);
650 ICHECK(data_ !=
nullptr) <<
" Trying to reference a null Integer";
651 return (*this)->value;
655 if (data_ ==
nullptr)
return Bool(
false);
656 return Bool((*this)->value == other);
659 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
661 return *
this ==
static_cast<int>(other);
663 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
665 return *
this !=
static_cast<int>(other);
685 refl::ObjectDef<RangeNode>()
688 .def_ro(
"span", &
RangeNode::span, refl::AttachFieldFlag::SEqHashIgnore());
730 struct TypeTraits<
IntImm> :
public ObjectRefWithFallbackTraitsBase<IntImm, int64_t> {
736 return IntImm(dtype, value);
744 struct TypeTraits<
Integer> :
public ObjectRefWithFallbackTraitsBase<Integer, int64_t> {
754 struct TypeTraits<
FloatImm> :
public ObjectRefWithFallbackTraitsBase<FloatImm, double> {
764 struct TypeTraits<
Bool> :
public ObjectRefWithFallbackTraitsBase<Bool, int64_t> {
800 return tvm::runtime::ObjectPtrHash()(
var);
807 return tvm::runtime::ObjectPtrEqual()(var_a, var_b);
Base type of all the expressions.
Definition: expr.h:51
static constexpr const char * _type_key
Definition: expr.h:66
static constexpr const uint32_t _type_child_slots
Definition: expr.h:70
static void RegisterReflection()
Definition: expr.h:59
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:68
TVM_DECLARE_BASE_OBJECT_INFO(BaseExprNode, Object)
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:57
Managed reference to BaseExprNode.
Definition: expr.h:78
TVM_DEFINE_OBJECT_REF_METHODS(BaseExpr, ObjectRef, BaseExprNode)
Boolean constant.
Definition: expr.h:577
Bool operator!() const
Definition: expr.h:580
Bool(bool value, Span span=Span())
Definition: expr.h:579
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Bool, IntImm, IntImmNode)
Constant floating point literals in the program.
Definition: expr.h:538
TVM_DECLARE_FINAL_OBJECT_INFO(FloatImmNode, PrimExprNode)
double value
The constant value content.
Definition: expr.h:541
static constexpr const char * _type_key
Definition: expr.h:548
static void RegisterReflection()
Definition: expr.h:543
Managed reference class to FloatImmNode.
Definition: expr.h:557
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloatImmNode)
TVM_DEFINE_OBJECT_REF_METHODS(FloatImm, PrimExpr, FloatImmNode)
FloatImm(DataType dtype, double value, Span span=Span())
Constructor.
Global variable that lives in the top-level module.
Definition: expr.h:460
TVM_DECLARE_FINAL_OBJECT_INFO(GlobalVarNode, RelaxExprNode)
uint64_t SHash(uint64_t init_hash, ffi::TypedFunction< uint64_t(AnyView, uint64_t, bool)> hash) const
Definition: expr.h:475
static void RegisterReflection()
Definition: expr.h:465
static constexpr const char * _type_key
Definition: expr.h:481
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:480
String name_hint
The name of the variable, this only acts as a hint.
Definition: expr.h:463
bool SEqual(const GlobalVarNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition: expr.h:470
Managed reference to GlobalVarNode.
Definition: expr.h:489
GlobalVar(String name_hint, Span span={})
TVM_DEFINE_OBJECT_REF_COW_METHOD(GlobalVarNode)
TVM_DEFINE_OBJECT_REF_METHODS(GlobalVar, RelaxExpr, GlobalVarNode)
Constant integer literals in the program.
Definition: expr.h:501
TVM_DECLARE_FINAL_OBJECT_INFO(IntImmNode, PrimExprNode)
static void RegisterReflection()
Definition: expr.h:506
static constexpr const char * _type_key
Definition: expr.h:511
int64_t value
the Internal value.
Definition: expr.h:504
Managed reference class to IntImmNode.
Definition: expr.h:520
TVM_DEFINE_OBJECT_REF_COW_METHOD(IntImmNode)
TVM_DEFINE_OBJECT_REF_METHODS(IntImm, PrimExpr, IntImmNode)
IntImm(DataType dtype, int64_t value, Span span=Span())
Constructor.
Container of constant int that adds more constructors.
Definition: expr.h:612
Bool operator!=(Enum other) const
Definition: expr.h:664
Integer(ObjectPtr< Object > node)
constructor from node.
Definition: expr.h:618
Integer()
Definition: expr.h:614
Bool operator!=(int other) const
Definition: expr.h:658
Integer(Enum value)
Constructor from enum.
Definition: expr.h:634
Bool operator==(int other) const
Definition: expr.h:654
Integer(IntImm other)
Construct integer from int imm.
Definition: expr.h:627
int64_t IntValue() const
convert to int64_t
Definition: expr.h:649
Bool operator==(Enum other) const
Definition: expr.h:660
Integer & operator=(const IntImm &other)
Assign an expression to integer.
Definition: expr.h:642
Integer(int value, Span span=Span())
Construct integer from int value.
Definition: expr.h:622
Base class for other IR constructs that can be converted to PrimExpr. This is useful for the FFI to c...
Definition: expr.h:159
TVM_DECLARE_BASE_OBJECT_INFO(PrimExprConvertibleNode, Object)
static constexpr const char * _type_key
Definition: expr.h:164
virtual ~PrimExprConvertibleNode()
Definition: expr.h:161
virtual PrimExpr ToPrimExpr() const =0
Managed reference to PrimExprConvertibleNode.
Definition: expr.h:172
TVM_DEFINE_OBJECT_REF_METHODS(PrimExprConvertible, ObjectRef, PrimExprConvertibleNode)
Base node of all primitive expressions.
Definition: expr.h:95
static constexpr const uint32_t _type_child_slots
Definition: expr.h:121
TVM_OBJECT_ENABLE_SCRIPT_PRINTER()
DataType dtype
The runtime data type of the primitive expression.
Definition: expr.h:111
static constexpr const char * _type_key
Definition: expr.h:120
static void RegisterReflection()
Definition: expr.h:113
TVM_DECLARE_BASE_OBJECT_INFO(PrimExprNode, BaseExprNode)
Reference to PrimExprNode.
Definition: expr.h:129
DataType dtype() const
Definition: expr.h:143
TVM_DEFINE_OBJECT_REF_METHODS(PrimExpr, BaseExpr, PrimExprNode)
PrimExpr(float value)
construct from float.
PrimExpr(int32_t value)
construct from integer.
static PrimExpr ConvertFallbackValue(String value)
construct from string to form a StringImm.
range over one dimension
Definition: expr.h:670
static void RegisterReflection()
Definition: expr.h:683
PrimExpr min
beginning of the node
Definition: expr.h:673
RangeNode(PrimExpr min, PrimExpr extent, Span span=Span())
Definition: expr.h:680
static constexpr const char * _type_key
Definition: expr.h:691
TVM_DECLARE_FINAL_OBJECT_INFO(RangeNode, Object)
RangeNode()
constructor
Definition: expr.h:679
PrimExpr extent
the extend of range
Definition: expr.h:675
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: expr.h:692
Span span
the location of this range in the source
Definition: expr.h:677
Range container
Definition: expr.h:698
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
TVM_DEFINE_OBJECT_REF_METHODS(Range, ObjectRef, RangeNode)
Base node of all non-primitive expressions.
Definition: expr.h:422
static constexpr const char * _type_key
Definition: expr.h:437
Optional< ObjectRef > struct_info_
Stores the result of structure information of the expression that encapsulate both static shape and r...
Definition: expr.h:429
static void RegisterReflection()
Definition: expr.h:431
TVM_DECLARE_BASE_OBJECT_INFO(RelaxExprNode, BaseExprNode)
static constexpr const uint32_t _type_child_slots
Definition: expr.h:438
Managed reference to RelaxExprNode.
Definition: expr.h:446
TVM_DEFINE_OBJECT_REF_METHODS(RelaxExpr, BaseExpr, RelaxExprNode)
Definition: source_map.h:113
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:181
constexpr bool use_default_type_traits_v< Bool >
Definition: expr.h:761
constexpr bool use_default_type_traits_v< Integer >
Definition: expr.h:741
constexpr bool use_default_type_traits_v< FloatImm >
Definition: expr.h:751
constexpr bool use_default_type_traits_v< IntImm >
Definition: expr.h:726
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:765
static TVM_FFI_INLINE FloatImm ConvertFallbackValue(double value)
Definition: expr.h:755
static TVM_FFI_INLINE IntImm ConvertFallbackValue(int64_t value)
Definition: expr.h:731
static TVM_FFI_INLINE Integer ConvertFallbackValue(int64_t value)
Definition: expr.h:745
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(StrictBool value)
Definition: expr.h:769
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(String value)
Definition: expr.h:190
static TVM_FFI_INLINE PrimExpr ConvertFallbackValue(PrimExprConvertible value)
Definition: expr.h:193