19#ifndef TVM_RELAX_EXPR_H_
20#define TVM_RELAX_EXPR_H_
22#include <tvm/ffi/container/array.h>
23#include <tvm/ffi/container/map.h>
24#include <tvm/ffi/reflection/registry.h>
41using ::tvm::TupleGetItem;
42using ::tvm::TupleGetItemNode;
43using ::tvm::TupleNode;
53 namespace refl = tvm::ffi::reflection;
62 explicit ShapeExpr(ffi::ObjectPtr<ShapeExprNode> node) :
Expr(std::move(node)) {}
74 namespace refl = tvm::ffi::reflection;
75 refl::ObjectDef<DataflowVarNode>();
84 TVM_DLL
explicit DataflowVar(ffi::String name, ffi::Optional<Type> ty_annotation,
87 explicit DataflowVar(ffi::ObjectPtr<DataflowVarNode> node) :
Var(std::move(node)) {}
94 ffi::Optional<Type> ty_annotation = std::nullopt,
108 namespace refl = tvm::ffi::reflection;
109 refl::ObjectDef<BindingNode>()
112 .def_ro(
"var", &
BindingNode::var, refl::AttachFieldFlag::SEqHashDefPattern());
125 explicit Binding(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
156 namespace refl = tvm::ffi::reflection;
157 refl::ObjectDef<MatchCastNode>()
188 namespace refl = tvm::ffi::reflection;
191 refl::TypeAttrDef<VarBindingNode>()
197 ffi::TypedFunction<
bool(AnyView, AnyView,
bool, AnyView)>
equal)
const;
198 int64_t
SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t,
bool)> hash)
const;
215 namespace refl = tvm::ffi::reflection;
216 refl::ObjectDef<BindingBlockNode>()
229 explicit BindingBlock(ffi::UnsafeInit tag, ffi::ObjectPtr<BindingBlockNode> n)
230 : ffi::ObjectRef(tag) {
231 data_ = std::move(n);
241 namespace refl = tvm::ffi::reflection;
242 refl::ObjectDef<DataflowBlockNode>();
251 explicit DataflowBlock(ffi::UnsafeInit tag, ffi::ObjectPtr<DataflowBlockNode> n)
253 data_ = std::move(n);
272 namespace refl = tvm::ffi::reflection;
273 refl::ObjectDef<SeqExprNode>()
276 refl::TypeAttrDef<SeqExprNode>()
282 ffi::TypedFunction<
bool(AnyView, AnyView,
bool, AnyView)>
equal)
const {
289 int64_t
SHash(int64_t init_hash, ffi::TypedFunction<int64_t(AnyView, int64_t,
bool)> hash)
const {
290 int64_t hash_value = init_hash;
291 hash_value = hash(
blocks, hash_value,
false);
292 hash_value = hash(
ty, hash_value,
false);
293 hash_value = hash(
body, hash_value,
false);
315 explicit SeqExpr(ffi::ObjectPtr<SeqExprNode> node) :
Expr(std::move(node)) {}
349 namespace refl = tvm::ffi::reflection;
350 refl::ObjectDef<IfExprNode>()
381 explicit IfExpr(ffi::ObjectPtr<IfExprNode> node) :
Expr(std::move(node)) {}
403 namespace refl = tvm::ffi::reflection;
404 refl::ObjectDef<FunctionNode>()
438 TVM_DLL
explicit Function(ffi::Array<Var> params,
Expr body, ffi::Optional<Type> ret_ty,
462 namespace refl = tvm::ffi::reflection;
Base node of all functions.
Definition function.h:92
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, ffi::Optional< TObjectRef > default_value=std::nullopt) const
Get a function attribute.
Definition function.h:117
Managed reference to BaseFuncNode.
Definition function.h:181
Managed reference to DictAttrsNode.
Definition attrs.h:108
Base type of all the expressions.
Definition base_expr.h:324
Type ty
The deduced or annotated type of the expression.
Definition base_expr.h:338
Managed reference to ExprNode.
Definition base_expr.h:359
Managed reference to a generic constant.
Definition expr.h:77
Non-nullable source-location metadata.
Definition location.h:91
Managed reference to TypeNode.
Definition base_expr.h:80
static TVM_TIRX_DLL Type Missing()
Construct a MissingType for type information not yet populated.
Reference to the shared immutable unknown location.
Definition location.h:105
A local variable in the IR.
Definition expr.h:694
Managed reference to VarNode.
Definition expr.h:714
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:222
ffi::Array< Binding > bindings
Definition expr.h:211
Location loc
Definition expr.h:212
static void RegisterReflection()
Definition expr.h:214
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.BindingBlock", BindingBlockNode, ffi::Object)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BindingBlock, ffi::ObjectRef, BindingBlockNode)
BindingBlock(ffi::UnsafeInit tag, ffi::ObjectPtr< BindingBlockNode > n)
Definition expr.h:229
BindingBlock(ffi::Array< Binding > bindings, Location loc=UnknownLoc())
BindingBlockNode * CopyOnWrite()
The base class of a variable binding in Relax.
Definition expr.h:98
Location loc
Definition expr.h:103
Var var
The return variable to bound to.
Definition expr.h:105
static void RegisterReflection()
Definition expr.h:107
BindingNode(ffi::UnsafeInit)
Definition expr.h:101
BindingNode(Var var)
Definition expr.h:100
TVM_FFI_DECLARE_OBJECT_INFO("relax.expr.Binding", BindingNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:115
Binding(const Binding &)=default
static constexpr bool _type_is_nullable
Definition expr.h:132
const BindingNode * operator->() const
Definition expr.h:130
Binding(Binding &&)=default
Binding & operator=(Binding &&)=default
const BindingNode * get() const
Definition expr.h:131
Binding(ffi::UnsafeInit tag)
Definition expr.h:125
Binding & operator=(const Binding &)=default
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowBlock", DataflowBlockNode, BindingBlockNode)
static void RegisterReflection()
Definition expr.h:240
DataflowBlock(ffi::UnsafeInit tag, ffi::ObjectPtr< DataflowBlockNode > n)
Definition expr.h:251
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataflowBlock, BindingBlock, DataflowBlockNode)
DataflowBlock(ffi::Array< Binding > bindings, Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(DataflowBlockNode)
A sub-type of the variable node used to mark dataflow variables from normal visible "function local" ...
Definition expr.h:71
static void RegisterReflection()
Definition expr.h:73
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.DataflowVar", DataflowVarNode, VarNode)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:78
DataflowVar(ffi::String name, ffi::Optional< Type > ty_annotation, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DataflowVar, Var, DataflowVarNode)
DataflowVar(ffi::ObjectPtr< DataflowVarNode > node)
Definition expr.h:87
The extern function, which can represent packed function.
Definition expr.h:456
static void RegisterReflection()
Definition expr.h:461
ffi::String global_symbol
The name of global symbol.
Definition expr.h:459
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ExternFunc", ExternFuncNode, BaseFuncNode)
ExternFunc(ffi::String global_symbol, Location loc=UnknownLoc())
ExternFunc(ffi::ObjectPtr< ExternFuncNode > node)
Definition expr.h:473
TVM_DEFINE_OBJECT_REF_COW_METHOD(ExternFuncNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ExternFunc, BaseFunc, ExternFuncNode)
ExternFunc(ffi::String global_symbol, Type ty, Location loc=UnknownLoc())
A Relax function.
Definition expr.h:388
FunctionNode(SeqExpr body)
Definition expr.h:390
static void RegisterReflection()
Definition expr.h:402
FunctionNode(ffi::UnsafeInit)
Definition expr.h:391
SeqExpr body
The body of the function.
Definition expr.h:396
ffi::Array< Var > params
The parameters to the function.
Definition expr.h:394
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.Function", FunctionNode, BaseFuncNode)
Type ret_ty
The return type of the function.
Definition expr.h:398
bool is_pure
Whether the function is annotated as pure or not.
Definition expr.h:400
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:411
Function(ffi::Array< Var > params, Expr body, ffi::Optional< Type > ret_ty, bool is_pure=true, DictAttrs attrs=DictAttrs(), Location loc=UnknownLoc())
Construct a Relax Function.
Function(ffi::ObjectPtr< FunctionNode > node)
Definition expr.h:449
static Function CreateEmpty(ffi::Array< Var > params, Type ret_ty, bool is_pure=true, DictAttrs attrs=DictAttrs(), Location loc=UnknownLoc())
Mimics the constructor but without body Expr.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Function, BaseFunc, FunctionNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(FunctionNode)
Condition expression.
Definition expr.h:332
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition expr.h:356
SeqExpr false_branch
The expression evaluated when condition is false.
Definition expr.h:346
IfExprNode(Expr cond, SeqExpr true_branch, SeqExpr false_branch)
Definition expr.h:334
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.IfExpr", IfExprNode, ExprNode)
Expr cond
The condition.
Definition expr.h:342
static void RegisterReflection()
Definition expr.h:348
IfExprNode(ffi::UnsafeInit)
Definition expr.h:338
SeqExpr true_branch
The expression evaluated when condition is true.
Definition expr.h:344
IfExpr(Expr cond, Expr true_branch, Expr false_branch, Location loc=UnknownLoc())
The constructor.
IfExpr(ffi::ObjectPtr< IfExprNode > node)
Definition expr.h:381
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfExprNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IfExpr, Expr, IfExprNode)
Runtime-match the value to the type.
Definition expr.h:143
Expr value
The input value to match cast.
Definition expr.h:151
Type ty
The type pattern to match to.
Definition expr.h:153
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.MatchCast", MatchCastNode, BindingNode)
MatchCastNode(ffi::UnsafeInit)
Definition expr.h:147
MatchCastNode(Var var, Expr value)
Definition expr.h:145
static void RegisterReflection()
Definition expr.h:155
Managed reference to MatchCastNode.
Definition expr.h:169
MatchCast(Var var, Expr value, Type ty, Location loc=UnknownLoc())
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(MatchCast, Binding, MatchCastNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MatchCastNode)
A sequence of blocks followed by an expression.
Definition expr.h:263
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.SeqExpr", SeqExprNode, ExprNode)
Expr body
Definition expr.h:269
bool SEqual(const SeqExprNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
Definition expr.h:281
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
Definition expr.h:289
SeqExprNode(ffi::UnsafeInit)
Definition expr.h:266
static void RegisterReflection()
Definition expr.h:271
ffi::Array< BindingBlock > blocks
Definition expr.h:268
SeqExprNode(Expr body)
Definition expr.h:265
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SeqExpr, Expr, SeqExprNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(SeqExprNode)
SeqExpr(ffi::Array< BindingBlock > blocks, Expr body, Location loc=UnknownLoc())
SeqExpr(ffi::ObjectPtr< SeqExprNode > node)
Definition expr.h:315
A shape expression which allows users to construct a shape containing PrimExpr.
Definition expr.h:47
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.ShapeExpr", ShapeExprNode, ExprNode)
ffi::Array< PrimExpr > values
Definition expr.h:50
static void RegisterReflection()
Definition expr.h:52
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(ShapeExpr, Expr, ShapeExprNode)
ShapeExpr(ffi::Array< PrimExpr > values, Location loc=UnknownLoc())
ShapeExpr(ffi::ObjectPtr< ShapeExprNode > node)
Definition expr.h:62
TVM_DEFINE_OBJECT_REF_COW_METHOD(ShapeExprNode)
static void RegisterReflection()
Definition expr.h:187
Expr value
The binding value.
Definition expr.h:185
VarBindingNode(Var var, Expr value)
Definition expr.h:179
int64_t SHash(int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
bool SEqual(const VarBindingNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.VarBinding", VarBindingNode, BindingNode)
VarBindingNode(ffi::UnsafeInit)
Definition expr.h:181
TVM_DEFINE_OBJECT_REF_COW_METHOD(VarBindingNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(VarBinding, Binding, VarBindingNode)
VarBinding(Var var, Expr value, Location loc=UnknownLoc())
Copy-on-write helper macro for IR ffi::ObjectRef types.
Shared primitive construction and constant helpers.
Source locations and source-text lookup.
constexpr const char * kTirVarUpperBound
Definition expr.h:533
constexpr const char * kScoped
Definition expr.h:543
constexpr const char * kCSourceFmt
Definition expr.h:531
constexpr const char * kForcePure
Override checking purity for this function and treat as pure (is_pure must be set to true)
Definition expr.h:513
constexpr const char * kCaptureSymbolicVars
Definition expr.h:541
constexpr const char * kMemoryPlanDynamicFuncOutput
Definition expr.h:539
constexpr const char * kTirVarLowerBound
Definition expr.h:535
constexpr const char * kWorkspaceSize
The required workspace for an external function.
Definition expr.h:507
constexpr const char * kOpAttrs
Definition expr.h:523
constexpr const char * kTirNonNegativeVar
Definition expr.h:537
constexpr const char * kLibraryKernel
Definition expr.h:527
constexpr const char * kOperatorName
Definition expr.h:525
constexpr const char * kCSource
Definition expr.h:529
constexpr const char * kNumInput
The number of inputs of a function. If a function has the num_input attribute, the last func->params....
Definition expr.h:520
constexpr const char * kOpPattern
Definition expr.h:521
constexpr const char * kComposite
Treat the function as a composite operator.
Definition expr.h:503
constexpr const char * kCodegen
Indicate the codegen that should be used for building this function. When this is unset or set to "de...
Definition expr.h:501
constexpr const char * kPrimitive
Mark the function as a primitive function.
Definition expr.h:496
constexpr const char * kPartitionedFromPattern
Indicate the function was created by the Pattern Partitioning Pass.
Definition expr.h:505
GenericConst MakeTensorConst(ffi::Tensor data, ffi::Optional< Type > ty_annotation=std::nullopt, Location loc=UnknownLoc())
Construct a tensor constant, inferring shape and dtype when type is omitted.
Expr GetShapeOf(const Expr &expr)
Get the shape of Expr.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
TVM_TIRX_DLL PrimExpr equal(PrimExpr a, PrimExpr b, Location loc=UnknownLoc())
equal
Relax types, including the richer dependent Relax type nodes.
Device-independent tensor allocation, copies, views and serialization.