24#ifndef TVM_IR_ENV_FUNC_H_
25#define TVM_IR_ENV_FUNC_H_
27#include <tvm/ffi/function.h>
28#include <tvm/ffi/reflection/registry.h>
54 namespace refl = tvm::ffi::reflection;
56 refl::ObjectDef<EnvFuncObj>()
72 explicit EnvFunc(ffi::UnsafeInit tag, ffi::ObjectPtr<ffi::Object> n) : ffi::ObjectRef(tag) {
78 explicit EnvFunc(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
86 template <
typename... Args>
89 TVM_FFI_ICHECK(n !=
nullptr);
90 return n->
func(std::forward<Args>(args)...);
106template <
typename FType>
118template <
typename R,
typename... Args>
123 static constexpr bool _type_is_nullable =
false;
135 ffi::ObjectRef::operator=(other);
147 TVM_FFI_ICHECK(n !=
nullptr);
148 if constexpr (std::is_same_v<R, void>) {
149 n->
func(std::forward<Args>(args)...);
151 ffi::Any res = n->
func(std::forward<Args>(args)...);
152 if constexpr (std::is_same_v<R, ffi::Any>) {
155 return std::move(res).cast<R>();
A serializable function backed by TVM's global environment.
Definition env_func.h:44
EnvFuncObj()
constructor
Definition env_func.h:51
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition env_func.h:61
ffi::Function func
The internal packed function.
Definition env_func.h:49
static void RegisterReflection()
Definition env_func.h:53
ffi::String name
Unique name of the global function.
Definition env_func.h:47
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.EnvFunc", EnvFuncObj, ffi::Object)
Managed reference to EnvFuncObj.
Definition env_func.h:69
EnvFunc(ffi::UnsafeInit tag)
constructor with UnsafeInit
Definition env_func.h:78
const EnvFuncObj * operator->() const
Definition env_func.h:80
EnvFunc(ffi::UnsafeInit tag, ffi::ObjectPtr< ffi::Object > n)
Definition env_func.h:72
static TVM_TIRX_DLL EnvFunc Get(const ffi::String &name)
Get a global function based on the name.
ffi::Any operator()(Args &&... args) const
Invoke the function.
Definition env_func.h:87
static constexpr bool _type_is_nullable
Definition env_func.h:71
A typed version of EnvFunc. It is backed by a GlobalFuncNode internally.
Definition env_func.h:119
TypedEnvFunc(const EnvFunc &other)
Definition env_func.h:124
const EnvFuncObj * operator->() const
Definition env_func.h:139
R operator()(Args... args) const
Invoke the function.
Definition env_func.h:145
TypedEnvFunc(ffi::UnsafeInit tag)
constructor with UnsafeInit
Definition env_func.h:128
TSelf & operator=(const EnvFunc &other)
Assign global function to a TypedEnvFunc.
Definition env_func.h:134
Please refer to TypedEnvFunc<R(Args..)>.
Definition env_func.h:107
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_TIRX_DLL
Definition base.h:83