tvm
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
tvm::IRModuleNode Class Reference

IRModule that holds functions and type definitions. More...

#include <module.h>

Inheritance diagram for tvm::IRModuleNode:
Collaboration diagram for tvm::IRModuleNode:

Public Member Functions

template<typename TObjectRef >
ffi::Optional< TObjectRef > GetAttr (const std::string &attr_key, ffi::Optional< TObjectRef > default_value=ffi::Optional< TObjectRef >(std::nullopt)) const
 Get a module attribute.
 
template<typename TObjectRef >
ffi::Optional< TObjectRef > GetAttr (const std::string &attr_key, TObjectRef default_value) const
 
DictAttrs GetAttrs () const
 Get the metadata attributes.
 
bool HasNonzeroAttr (const std::string &attr_key) const
 Check whether the module has an non-zero integer attr.
 
 IRModuleNode ()
 
TVM_TIRX_DLL bool SEqual (const IRModuleNode *other, ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)> equal) const
 
TVM_TIRX_DLL int64_t SHash (int64_t init_hash, ffi::TypedFunction< int64_t(AnyView, int64_t, bool)> hash) const
 
TVM_TIRX_DLL void Add (const GlobalVar &var, const BaseFunc &func, bool update=false)
 Add a function to the global environment.
 
TVM_TIRX_DLL void AddUnchecked (const GlobalVar &var, const BaseFunc &func)
 Add a function to the global environment.
 
TVM_TIRX_DLL void Update (const GlobalVar &var, const BaseFunc &func)
 Update a function in the global environment.
 
TVM_TIRX_DLL void UpdateGlobalInfo (const ffi::String &name, const ffi::Array< GlobalInfo > &info)
 Update an array of global infos in the global environment.
 
TVM_TIRX_DLL void Remove (const GlobalVar &var)
 Remove a function from the global environment.
 
TVM_TIRX_DLL bool ContainGlobalVar (const ffi::String &name) const
 Check if the global_var_map_ contains a global variable.
 
TVM_TIRX_DLL GlobalVar GetGlobalVar (const ffi::String &str) const
 Lookup a global function by its variable.
 
TVM_TIRX_DLL ffi::Array< GlobalVar > GetGlobalVars () const
 Collect all global vars defined in this module, ordered by the global variable name.
 
TVM_TIRX_DLL BaseFunc Lookup (const GlobalVar &var) const
 Look up a global function by its variable.
 
TVM_TIRX_DLL BaseFunc Lookup (const ffi::String &name) const
 Look up a global function by its string name.
 
TVM_TIRX_DLL void Update (const IRModule &other)
 Update the functions inside this environment by functions in another environment.
 
TVM_TIRX_DLL IRModule ShallowCopy ()
 Create a shallow copy of this IRModule.
 
TVM_TIRX_DLL std::unordered_set< ffi::String > Imports () const
 The set of imported files.
 
 TVM_FFI_DECLARE_OBJECT_INFO_FINAL ("ir.IRModule", IRModuleNode, ffi::Object)
 

Static Public Member Functions

static void RegisterReflection ()
 

Public Attributes

ffi::Map< GlobalVar, BaseFunc > functions
 A map from ids to all global functions.
 
SourceMap source_map
 The source map for the module.
 
DictAttrs attrs
 
ffi::Map< ffi::String, ffi::Array< GlobalInfo > > global_infos
 Globally static object that are referred by the IR itself.
 
ffi::Map< ffi::String, GlobalVar > global_var_map_
 A map from string names to global variables that ensures global uniqueness.
 

Static Public Attributes

static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode
 

Friends

class IRModule
 The IRModule declaration statement.
 

Detailed Description

IRModule that holds functions and type definitions.

IRModule is the basic unit for all IR transformations across the stack.

Many operations require access to the global IRModule. We pass the IRModule by value in a functional style as an explicit argument, but we mutate the Module while optimizing programs.

See also
IRModule

Constructor & Destructor Documentation

◆ IRModuleNode()

tvm::IRModuleNode::IRModuleNode ( )
inline

Member Function Documentation

◆ Add()

TVM_TIRX_DLL void tvm::IRModuleNode::Add ( const GlobalVar &  var,
const BaseFunc &  func,
bool  update = false 
)

Add a function to the global environment.

Parameters
varThe var of the global function.
funcThe function.
updateControls whether you can replace a definition in the environment.

◆ AddUnchecked()

TVM_TIRX_DLL void tvm::IRModuleNode::AddUnchecked ( const GlobalVar &  var,
const BaseFunc &  func 
)

Add a function to the global environment.

Parameters
varThe name of the global function.
funcThe function.

It does not do type inference as Add does.

◆ ContainGlobalVar()

TVM_TIRX_DLL bool tvm::IRModuleNode::ContainGlobalVar ( const ffi::String &  name) const

Check if the global_var_map_ contains a global variable.

Parameters
nameThe variable name.
Returns
true if contains, otherise false.

◆ GetAttr() [1/2]

template<typename TObjectRef >
ffi::Optional< TObjectRef > tvm::IRModuleNode::GetAttr ( const std::string &  attr_key,
ffi::Optional< TObjectRef >  default_value = ffi::Optional<TObjectRef>(std::nullopt) 
) const
inline

Get a module attribute.

Parameters
attr_keyThe attribute key.
default_valueThe default value if the key does not exist, defaults to nullptr.
Returns
The result
Template Parameters
TObjectRefthe expected object type.
Exceptions
Errorif the key exists but the value does not match TObjectRef
void GetAttrExample(const IRModule& mod) {
auto value = f->GetAttr<int64_t>("AttrKey", 0);
}
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, ffi::Optional< TObjectRef > default_value=ffi::Optional< TObjectRef >(std::nullopt)) const
Get a module attribute.
Definition module.h:94
Managed reference class to IRModuleNode.
Definition module.h:255

◆ GetAttr() [2/2]

template<typename TObjectRef >
ffi::Optional< TObjectRef > tvm::IRModuleNode::GetAttr ( const std::string &  attr_key,
TObjectRef  default_value 
) const
inline

◆ GetAttrs()

DictAttrs tvm::IRModuleNode::GetAttrs ( ) const
inline

Get the metadata attributes.

Returns
The additional meta-data attributes

◆ GetGlobalVar()

TVM_TIRX_DLL GlobalVar tvm::IRModuleNode::GetGlobalVar ( const ffi::String &  str) const

Lookup a global function by its variable.

Parameters
strThe unique string specifying the global variable.
Returns
The global variable.

◆ GetGlobalVars()

TVM_TIRX_DLL ffi::Array< GlobalVar > tvm::IRModuleNode::GetGlobalVars ( ) const

Collect all global vars defined in this module, ordered by the global variable name.

Returns
An array of global vars

◆ HasNonzeroAttr()

bool tvm::IRModuleNode::HasNonzeroAttr ( const std::string &  attr_key) const
inline

Check whether the module has an non-zero integer attr.

This function can be used to check whether an optional attribute mark(e.g. inline) exists.

Parameters
attr_keyThe key to the attribute.
Returns
The check result.
void HasNonzeroAttrExample(const IRModule& mod) {
if (mod->HasNonzeroAttr(attr::kInline)) {
// inline the function.
}
}

◆ Imports()

TVM_TIRX_DLL std::unordered_set< ffi::String > tvm::IRModuleNode::Imports ( ) const

The set of imported files.

◆ Lookup() [1/2]

TVM_TIRX_DLL BaseFunc tvm::IRModuleNode::Lookup ( const ffi::String &  name) const

Look up a global function by its string name.

Parameters
nameThe name of the function.
Returns
The function named by the argument.

◆ Lookup() [2/2]

TVM_TIRX_DLL BaseFunc tvm::IRModuleNode::Lookup ( const GlobalVar &  var) const

Look up a global function by its variable.

Parameters
varThe global var to lookup.
Returns
The function named by the variable argument.

◆ RegisterReflection()

static void tvm::IRModuleNode::RegisterReflection ( )
inlinestatic

◆ Remove()

TVM_TIRX_DLL void tvm::IRModuleNode::Remove ( const GlobalVar &  var)

Remove a function from the global environment.

Parameters
varThe name of the global function to update.

◆ SEqual()

TVM_TIRX_DLL bool tvm::IRModuleNode::SEqual ( const IRModuleNode *  other,
ffi::TypedFunction< bool(AnyView, AnyView, bool, AnyView)>  equal 
) const

◆ ShallowCopy()

TVM_TIRX_DLL IRModule tvm::IRModuleNode::ShallowCopy ( )

Create a shallow copy of this IRModule.

Returns
The shallow copy of the IRModule.

◆ SHash()

TVM_TIRX_DLL int64_t tvm::IRModuleNode::SHash ( int64_t  init_hash,
ffi::TypedFunction< int64_t(AnyView, int64_t, bool)>  hash 
) const

◆ TVM_FFI_DECLARE_OBJECT_INFO_FINAL()

tvm::IRModuleNode::TVM_FFI_DECLARE_OBJECT_INFO_FINAL ( "ir.IRModule"  ,
IRModuleNode  ,
ffi::Object   
)

◆ Update() [1/2]

TVM_TIRX_DLL void tvm::IRModuleNode::Update ( const GlobalVar &  var,
const BaseFunc &  func 
)

Update a function in the global environment.

Parameters
varThe name of the global function to update.
funcThe new function.

◆ Update() [2/2]

TVM_TIRX_DLL void tvm::IRModuleNode::Update ( const IRModule &  other)

Update the functions inside this environment by functions in another environment.

Parameters
otherThe other environment.

◆ UpdateGlobalInfo()

TVM_TIRX_DLL void tvm::IRModuleNode::UpdateGlobalInfo ( const ffi::String &  name,
const ffi::Array< GlobalInfo > &  info 
)

Update an array of global infos in the global environment.

Parameters
nameThe name of the global info.
infoThe new array of global infos.

Friends And Related Symbol Documentation

◆ IRModule

The IRModule declaration statement.

Returns
The IRModuleFrame.

Member Data Documentation

◆ _type_s_eq_hash_kind

constexpr TVMFFISEqHashKind tvm::IRModuleNode::_type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode
staticconstexpr

◆ attrs

DictAttrs tvm::IRModuleNode::attrs

◆ functions

ffi::Map<GlobalVar, BaseFunc> tvm::IRModuleNode::functions

A map from ids to all global functions.

◆ global_infos

ffi::Map<ffi::String, ffi::Array<GlobalInfo> > tvm::IRModuleNode::global_infos

Globally static object that are referred by the IR itself.

◆ global_var_map_

ffi::Map<ffi::String, GlobalVar> tvm::IRModuleNode::global_var_map_

A map from string names to global variables that ensures global uniqueness.

◆ source_map

SourceMap tvm::IRModuleNode::source_map

The source map for the module.


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