tvm
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
tvm::ReflectionVTable Class Reference

Virtual function table to support IR/AST node reflection. More...

#include <reflection.h>

Collaboration diagram for tvm::ReflectionVTable:

Classes

class  Registry
 Registry of a reflection table. More...
 

Public Types

typedef void(* FVisitAttrs) (Object *self, AttrVisitor *visitor)
 Visitor function. More...
 
typedef bool(* FSEqualReduce) (const Object *self, const Object *other, SEqualReducer equal)
 Equality comparison function. More...
 
typedef void(* FSHashReduce) (const Object *self, SHashReducer hash_reduce)
 Structural hash reduction function. More...
 
typedef ObjectPtr< Object >(* FCreate) (const std::string &repr_bytes)
 creator function. More...
 
typedef std::string(* FReprBytes) (const Object *self)
 Function to get a byte representation that can be used to recover the object. More...
 

Public Member Functions

void VisitAttrs (Object *self, AttrVisitor *visitor) const
 Dispatch the VisitAttrs function. More...
 
bool GetReprBytes (const Object *self, std::string *repr_bytes) const
 Get repr bytes if any. More...
 
bool SEqualReduce (const Object *self, const Object *other, SEqualReducer equal) const
 Dispatch the SEqualReduce function. More...
 
void SHashReduce (const Object *self, SHashReducer hash_reduce) const
 Dispatch the SHashReduce function. More...
 
ObjectPtr< ObjectCreateInitObject (const std::string &type_key, const std::string &repr_bytes="") const
 Create an initial object using default constructor by type_key and global key. More...
 
ObjectRef CreateObject (const std::string &type_key, const runtime::TVMArgs &kwargs)
 Create an object by giving kwargs about its fields. More...
 
ObjectRef CreateObject (const std::string &type_key, const Map< String, ObjectRef > &kwargs)
 Create an object by giving kwargs about its fields. More...
 
runtime::TVMRetValue GetAttr (Object *self, const String &attr_name) const
 Get an field object by the attr name. More...
 
std::vector< std::string > ListAttrNames (Object *self) const
 List all the fields in the object. More...
 
template<typename T , typename TraitName >
Registry Register ()
 

Static Public Member Functions

static ReflectionVTableGlobal ()
 

Detailed Description

Virtual function table to support IR/AST node reflection.

Functions are stored in columnar manner. Each column is a vector indexed by Object's type_index.

Member Typedef Documentation

◆ FCreate

typedef ObjectPtr<Object>(* tvm::ReflectionVTable::FCreate) (const std::string &repr_bytes)

creator function.

Parameters
repr_bytesRepr bytes to create the object. If this is not empty then FReprBytes must be defined for the object.
Returns
The created function.

◆ FReprBytes

typedef std::string(* tvm::ReflectionVTable::FReprBytes) (const Object *self)

Function to get a byte representation that can be used to recover the object.

Parameters
nodeThe node pointer.
Returns
bytes The bytes that can be used to recover the object.

◆ FSEqualReduce

typedef bool(* tvm::ReflectionVTable::FSEqualReduce) (const Object *self, const Object *other, SEqualReducer equal)

Equality comparison function.

◆ FSHashReduce

typedef void(* tvm::ReflectionVTable::FSHashReduce) (const Object *self, SHashReducer hash_reduce)

Structural hash reduction function.

◆ FVisitAttrs

typedef void(* tvm::ReflectionVTable::FVisitAttrs) (Object *self, AttrVisitor *visitor)

Visitor function.

Note
We use function pointer, instead of std::function to reduce the dispatch overhead as field visit does not need as much customization.

Member Function Documentation

◆ CreateInitObject()

ObjectPtr<Object> tvm::ReflectionVTable::CreateInitObject ( const std::string &  type_key,
const std::string &  repr_bytes = "" 
) const

Create an initial object using default constructor by type_key and global key.

Parameters
type_keyThe type key of the object.
repr_bytesBytes representation of the object if any.

◆ CreateObject() [1/2]

ObjectRef tvm::ReflectionVTable::CreateObject ( const std::string &  type_key,
const Map< String, ObjectRef > &  kwargs 
)

Create an object by giving kwargs about its fields.

Parameters
type_keyThe type key.
kwargsThe field arguments.
Returns
The created object.

◆ CreateObject() [2/2]

ObjectRef tvm::ReflectionVTable::CreateObject ( const std::string &  type_key,
const runtime::TVMArgs kwargs 
)

Create an object by giving kwargs about its fields.

Parameters
type_keyThe type key.
kwargsthe arguments in format key1, value1, ..., key_n, value_n.
Returns
The created object.

◆ GetAttr()

runtime::TVMRetValue tvm::ReflectionVTable::GetAttr ( Object self,
const String attr_name 
) const

Get an field object by the attr name.

Parameters
selfThe pointer to the object.
attr_nameThe name of the field.
Returns
The corresponding attribute value.
Note
This function will throw an exception if the object does not contain the field.

◆ GetReprBytes()

bool tvm::ReflectionVTable::GetReprBytes ( const Object self,
std::string *  repr_bytes 
) const
inline

Get repr bytes if any.

Parameters
selfThe pointer to the object.
repr_bytesThe output repr bytes, can be null, in which case the function simply queries if the ReprBytes function exists for the type.
Returns
Whether repr bytes exists

◆ Global()

static ReflectionVTable* tvm::ReflectionVTable::Global ( )
static
Returns
The global singleton.

◆ ListAttrNames()

std::vector<std::string> tvm::ReflectionVTable::ListAttrNames ( Object self) const

List all the fields in the object.

Returns
All the fields.

◆ Register()

template<typename T , typename TraitName >
ReflectionVTable::Registry tvm::ReflectionVTable::Register
inline

◆ SEqualReduce()

bool tvm::ReflectionVTable::SEqualReduce ( const Object self,
const Object other,
SEqualReducer  equal 
) const

Dispatch the SEqualReduce function.

Parameters
selfThe pointer to the object.
otherThe pointer to another object to be compared.
equalThe equality comparator.
Returns
the result.

◆ SHashReduce()

void tvm::ReflectionVTable::SHashReduce ( const Object self,
SHashReducer  hash_reduce 
) const

Dispatch the SHashReduce function.

Parameters
selfThe pointer to the object.
hash_reduceThe hash reducer.

◆ VisitAttrs()

void tvm::ReflectionVTable::VisitAttrs ( Object self,
AttrVisitor visitor 
) const
inline

Dispatch the VisitAttrs function.

Parameters
selfThe pointer to the object.
visitorThe attribute visitor.

The documentation for this class was generated from the following file: