25#ifndef TVM_IR_PRIM_EXPR_H_
26#define TVM_IR_PRIM_EXPR_H_
28#include <tvm/ffi/container/array.h>
29#include <tvm/ffi/container/map.h>
30#include <tvm/ffi/dtype.h>
31#include <tvm/ffi/string.h>
43#include <unordered_map>
58 namespace refl = tvm::ffi::reflection;
85 namespace refl = tvm::ffi::reflection;
115 namespace refl = tvm::ffi::reflection;
116 refl::ObjectDef<T>().def_ro(
"a", &T::a).def_ro(
"b", &T::b);
223 static constexpr const char*
_type_key =
"ir.prim.FloorDiv";
241 static constexpr const char*
_type_key =
"ir.prim.FloorMod";
304 namespace refl = tvm::ffi::reflection;
305 refl::ObjectDef<T>().def_ro(
"a", &T::a).def_ro(
"b", &T::b);
428 namespace refl = tvm::ffi::reflection;
454 namespace refl = tvm::ffi::reflection;
478 namespace refl = tvm::ffi::reflection;
479 refl::ObjectDef<NotNode>().def_ro(
"a", &
NotNode::a);
512 namespace refl = tvm::ffi::reflection;
513 refl::ObjectDef<SelectNode>()
546 namespace refl = tvm::ffi::reflection;
547 refl::ObjectDef<LetNode>()
549 .def_ro(
"var", &
LetNode::var, refl::AttachFieldFlag::SEqHashDefRecursive())
576template <
typename K,
typename V>
578 std::unordered_map<K, V> ret;
580 ret[
kv.first] =
kv.second;
589inline constexpr bool object_ref_contains_v<PrimExpr, prim::StringImmNode> =
true;
591inline constexpr bool object_ref_contains_v<PrimExpr, prim::CastNode> =
true;
593inline constexpr bool object_ref_contains_v<PrimExpr, prim::AddNode> =
true;
595inline constexpr bool object_ref_contains_v<PrimExpr, prim::SubNode> =
true;
597inline constexpr bool object_ref_contains_v<PrimExpr, prim::MulNode> =
true;
599inline constexpr bool object_ref_contains_v<PrimExpr, prim::DivNode> =
true;
601inline constexpr bool object_ref_contains_v<PrimExpr, prim::ModNode> =
true;
603inline constexpr bool object_ref_contains_v<PrimExpr, prim::FloorDivNode> =
true;
605inline constexpr bool object_ref_contains_v<PrimExpr, prim::FloorModNode> =
true;
607inline constexpr bool object_ref_contains_v<PrimExpr, prim::MinNode> =
true;
609inline constexpr bool object_ref_contains_v<PrimExpr, prim::MaxNode> =
true;
611inline constexpr bool object_ref_contains_v<PrimExpr, prim::EQNode> =
true;
613inline constexpr bool object_ref_contains_v<PrimExpr, prim::NENode> =
true;
615inline constexpr bool object_ref_contains_v<PrimExpr, prim::LTNode> =
true;
617inline constexpr bool object_ref_contains_v<PrimExpr, prim::LENode> =
true;
619inline constexpr bool object_ref_contains_v<PrimExpr, prim::GTNode> =
true;
621inline constexpr bool object_ref_contains_v<PrimExpr, prim::GENode> =
true;
623inline constexpr bool object_ref_contains_v<PrimExpr, prim::AndNode> =
true;
625inline constexpr bool object_ref_contains_v<PrimExpr, prim::OrNode> =
true;
627inline constexpr bool object_ref_contains_v<PrimExpr, prim::NotNode> =
true;
629inline constexpr bool object_ref_contains_v<PrimExpr, prim::SelectNode> =
true;
631inline constexpr bool object_ref_contains_v<PrimExpr, prim::RampNode> =
true;
633inline constexpr bool object_ref_contains_v<PrimExpr, prim::BroadcastNode> =
true;
635inline constexpr bool object_ref_contains_v<PrimExpr, prim::LetNode> =
true;
637inline constexpr bool object_ref_contains_v<PrimExpr, prim::ShuffleNode> =
true;
639inline constexpr bool use_default_type_traits_v<tvm::prim::StringImm> =
false;
643 :
public ObjectRefWithFallbackTraitsBase<tvm::prim::StringImm, ffi::String> {
Helpers for attribute objects.
Base type of all the expressions.
Definition base_expr.h:300
Constant floating point literals in the program.
Definition expr.h:550
Constant integer literals in the program.
Definition expr.h:487
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
Definition base_expr.h:137
Definition source_map.h:111
Managed reference to VarNode.
Definition expr.h:372
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
a + b
Definition expr.h:124
static constexpr const char * _type_key
Definition expr.h:126
Managed reference to AddNode.
Definition expr.h:133
Add(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Add, PrimExpr, AddNode)
static constexpr bool _type_container_is_exact
Definition expr.h:137
TVM_DEFINE_OBJECT_REF_COW_METHOD(AddNode)
a && b
Definition expr.h:421
PrimExpr b
The right operand.
Definition expr.h:426
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.And", AndNode, ExprNode)
static void RegisterReflection()
Definition expr.h:427
PrimExpr a
The left operand.
Definition expr.h:424
Managed reference to AndNode.
Definition expr.h:438
And(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(AndNode)
static constexpr bool _type_container_is_exact
Definition expr.h:442
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(And, PrimExpr, AndNode)
Base template to implement binary ops.
Definition expr.h:108
static const constexpr int _type_child_slots
Definition expr.h:118
TVM_FFI_DECLARE_OBJECT_INFO_PREDEFINED_TYPE_KEY(T, ExprNode)
static void RegisterReflection()
Definition expr.h:114
PrimExpr a
The left operand.
Definition expr.h:111
PrimExpr b
The right operand.
Definition expr.h:113
static const constexpr bool _type_final
Definition expr.h:119
Cast value from one data type to another.
Definition expr.h:80
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.Cast", CastNode, ExprNode)
PrimExpr value
Original data type.
Definition expr.h:83
static void RegisterReflection()
Definition expr.h:84
Managed reference to CastNode.
Definition expr.h:95
static constexpr bool _type_container_is_exact
Definition expr.h:99
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Cast, PrimExpr, CastNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(CastNode)
Cast(PrimType value_ty, PrimExpr value, Span span=Span())
Base template to implement comparison ops.
Definition expr.h:297
static const constexpr bool _type_final
Definition expr.h:308
PrimExpr b
The right operand.
Definition expr.h:302
PrimExpr a
The left operand.
Definition expr.h:300
TVM_FFI_DECLARE_OBJECT_INFO_PREDEFINED_TYPE_KEY(T, ExprNode)
static void RegisterReflection()
Definition expr.h:303
static const constexpr int _type_child_slots
Definition expr.h:307
a / b in the C semnatics.
Definition expr.h:182
static constexpr const char * _type_key
Definition expr.h:184
Managed reference to DivNode.
Definition expr.h:191
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Div, PrimExpr, DivNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(DivNode)
Div(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition expr.h:195
a == b
Definition expr.h:313
static constexpr const char * _type_key
Definition expr.h:315
Managed reference to EQNode.
Definition expr.h:322
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(EQ, PrimExpr, EQNode)
EQ(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition expr.h:326
TVM_DEFINE_OBJECT_REF_COW_METHOD(EQNode)
Floor division, floor(a/b)
Definition expr.h:221
static constexpr const char * _type_key
Definition expr.h:223
Managed reference to FloorDivNode.
Definition expr.h:230
static constexpr bool _type_container_is_exact
Definition expr.h:234
FloorDiv(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FloorDiv, PrimExpr, FloorDivNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloorDivNode)
The remainder of the floordiv.
Definition expr.h:239
static constexpr const char * _type_key
Definition expr.h:241
Managed reference to FloorModNode.
Definition expr.h:248
FloorMod(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(FloorMod, PrimExpr, FloorModNode)
static constexpr bool _type_container_is_exact
Definition expr.h:252
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloorModNode)
a >= b
Definition expr.h:403
static constexpr const char * _type_key
Definition expr.h:405
Managed reference to GENode.
Definition expr.h:412
GE(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GE, PrimExpr, GENode)
static constexpr bool _type_container_is_exact
Definition expr.h:416
TVM_DEFINE_OBJECT_REF_COW_METHOD(GENode)
a > b
Definition expr.h:385
static constexpr const char * _type_key
Definition expr.h:387
Managed reference to GTNode.
Definition expr.h:394
TVM_DEFINE_OBJECT_REF_COW_METHOD(GTNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(GT, PrimExpr, GTNode)
static constexpr bool _type_container_is_exact
Definition expr.h:398
GT(PrimExpr a, PrimExpr b, Span span=Span())
Managed reference to LENode.
Definition expr.h:376
TVM_DEFINE_OBJECT_REF_COW_METHOD(LENode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(LE, PrimExpr, LENode)
static constexpr bool _type_container_is_exact
Definition expr.h:380
LE(PrimExpr a, PrimExpr b, Span span=Span())
a < b
Definition expr.h:349
static constexpr const char * _type_key
Definition expr.h:351
Managed reference to LTNode.
Definition expr.h:358
TVM_DEFINE_OBJECT_REF_COW_METHOD(LTNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(LT, PrimExpr, LTNode)
static constexpr bool _type_container_is_exact
Definition expr.h:362
LT(PrimExpr a, PrimExpr b, Span span=Span())
Let binding. Bind var to value then evaluate body.
Definition expr.h:537
PrimExpr value
The value to be binded.
Definition expr.h:542
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.Let", LetNode, ExprNode)
Var var
The variable.
Definition expr.h:540
static void RegisterReflection()
Definition expr.h:545
PrimExpr body
The result expression.
Definition expr.h:544
Managed reference to LetNode.
Definition expr.h:560
TVM_DEFINE_OBJECT_REF_COW_METHOD(LetNode)
static constexpr bool _type_container_is_exact
Definition expr.h:564
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Let, PrimExpr, LetNode)
Let(Var var, PrimExpr value, PrimExpr body, Span span=Span())
max(a, b)
Definition expr.h:275
static constexpr const char * _type_key
Definition expr.h:277
Managed reference to MaxNode.
Definition expr.h:284
TVM_DEFINE_OBJECT_REF_COW_METHOD(MaxNode)
Max(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Max, PrimExpr, MaxNode)
static constexpr bool _type_container_is_exact
Definition expr.h:288
min(a, b)
Definition expr.h:257
static constexpr const char * _type_key
Definition expr.h:259
Managed reference to MinNode.
Definition expr.h:266
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Min, PrimExpr, MinNode)
Min(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition expr.h:270
TVM_DEFINE_OBJECT_REF_COW_METHOD(MinNode)
a % b in the C semnatics.
Definition expr.h:203
static constexpr const char * _type_key
Definition expr.h:205
Managed reference to ModNode.
Definition expr.h:212
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Mod, PrimExpr, ModNode)
static constexpr bool _type_container_is_exact
Definition expr.h:216
Mod(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ModNode)
a * b
Definition expr.h:161
static constexpr const char * _type_key
Definition expr.h:163
Managed reference to MulNode.
Definition expr.h:170
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Mul, PrimExpr, MulNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MulNode)
static constexpr bool _type_container_is_exact
Definition expr.h:174
Mul(PrimExpr a, PrimExpr b, Span span=Span())
a != b
Definition expr.h:331
static constexpr const char * _type_key
Definition expr.h:333
Managed reference to NENode.
Definition expr.h:340
TVM_DEFINE_OBJECT_REF_COW_METHOD(NENode)
NE(PrimExpr a, PrimExpr b, Span span=Span())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(NE, PrimExpr, NENode)
static constexpr bool _type_container_is_exact
Definition expr.h:344
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.Not", NotNode, ExprNode)
static void RegisterReflection()
Definition expr.h:477
PrimExpr a
The input operand.
Definition expr.h:476
Managed reference to NotNode.
Definition expr.h:488
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Not, PrimExpr, NotNode)
static constexpr bool _type_container_is_exact
Definition expr.h:492
TVM_DEFINE_OBJECT_REF_COW_METHOD(NotNode)
Not(PrimExpr a, Span span=Span())
a || b
Definition expr.h:447
PrimExpr b
The right operand.
Definition expr.h:452
static void RegisterReflection()
Definition expr.h:453
PrimExpr a
The left operand.
Definition expr.h:450
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.Or", OrNode, ExprNode)
Managed reference to OrNode.
Definition expr.h:464
TVM_DEFINE_OBJECT_REF_COW_METHOD(OrNode)
Or(PrimExpr a, PrimExpr b, Span span=Span())
static constexpr bool _type_container_is_exact
Definition expr.h:468
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Or, PrimExpr, OrNode)
return true_value if condition is true, otherwise return false_value.
Definition expr.h:503
PrimExpr false_value
value to be returned when condition is false.
Definition expr.h:510
PrimExpr true_value
value to be returned when condition is true.
Definition expr.h:508
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.Select", SelectNode, ExprNode)
PrimExpr condition
The condition.
Definition expr.h:506
static void RegisterReflection()
Definition expr.h:511
Managed reference to SelectNode.
Definition expr.h:525
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Select, PrimExpr, SelectNode)
static constexpr bool _type_container_is_exact
Definition expr.h:530
TVM_DEFINE_OBJECT_REF_COW_METHOD(SelectNode)
Select(PrimExpr condition, PrimExpr true_value, PrimExpr false_value, Span span=Span())
ffi::String constants, only used in asserts.
Definition expr.h:53
ffi::String value
The constant value content.
Definition expr.h:56
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.prim.StringImm", StringImmNode, ExprNode)
static void RegisterReflection()
Definition expr.h:57
Managed reference to StringImmNode.
Definition expr.h:68
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(StringImm, PrimExpr, StringImmNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(StringImmNode)
static constexpr bool _type_container_is_exact
Definition expr.h:72
StringImm(ffi::String value, Span span=Span())
a - b
Definition expr.h:142
static constexpr const char * _type_key
Definition expr.h:144
Managed reference to SubNode.
Definition expr.h:151
TVM_DEFINE_OBJECT_REF_COW_METHOD(SubNode)
static constexpr bool _type_container_is_exact
Definition expr.h:156
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Sub, PrimExpr, SubNode)
Sub(PrimExpr a, PrimExpr b, Span span=Span())
Copy-on-write helper macro for IR ffi::ObjectRef types.
std::unordered_map< K, V > as_unordered_map(const ffi::Map< K, V > &dmap)
Definition expr.h:577
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Defines the Functor data structures.
static TVM_FFI_INLINE tvm::prim::StringImm ConvertFallbackValue(ffi::String value)
Definition expr.h:644
a <= b
Definition expr.h:367
static constexpr const char * _type_key
Definition expr.h:369
Primitive vector expressions.