24#ifndef TVM_IR_UNIQUE_NAME_SUPPLY_H_
25#define TVM_IR_UNIQUE_NAME_SUPPLY_H_
27#include <tvm/ffi/reflection/registry.h>
52 :
prefix_(prefix), name_map(std::move(name_map)) {}
62 ffi::String
FreshName(
const ffi::String& name,
bool add_prefix =
true,
63 bool add_underscore =
true);
72 ffi::String
ReserveName(
const ffi::String& name,
bool add_prefix =
true);
81 bool ContainsName(
const ffi::String& name,
bool add_prefix =
true);
89 namespace refl = tvm::ffi::reflection;
90 refl::ObjectDef<UniqueNameSupplyObj>();
97 ffi::String AddPrefixToName(
const ffi::String& name);
105 std::string GetUniqueName(std::string name,
bool add_underscore =
true);
108 ffi::Map<ffi::String, int64_t> name_map;
123 ffi::Map<ffi::String, int64_t> name_map = {});
130 template <
typename Iter,
typename Lambda>
132 for (
auto it = begin; it != end; ++it) {
133 this->operator->()->ReserveName(f(*it),
false);
UniqueNameSupply can be used to generate unique names.
Definition unique_name_supply.h:39
static constexpr const bool _type_mutable
Definition unique_name_supply.h:86
UniqueNameSupplyObj(const ffi::String &prefix, ffi::Map< ffi::String, int64_t > name_map)
Constructor.
Definition unique_name_supply.h:51
std::string prefix_
Definition unique_name_supply.h:84
ffi::String FreshName(const ffi::String &name, bool add_prefix=true, bool add_underscore=true)
Generates a unique name from this UniqueNameSupply.
UniqueNameSupplyObj()=default
Empty constructor. Needed by the TVM_REGISTER_NODE_TYPE macro.
ffi::String ReserveName(const ffi::String &name, bool add_prefix=true)
Reserves an existing name with this UniqueNameSupply.
static void RegisterReflection()
Definition unique_name_supply.h:88
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.UniqueNameSupply", UniqueNameSupplyObj, ffi::Object)
bool ContainsName(const ffi::String &name, bool add_prefix=true)
Checks if this UniqueNameSupply already generated a name.
Managed reference class to UniqueNameSupplyObj.
Definition unique_name_supply.h:115
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(UniqueNameSupply, ffi::ObjectRef, UniqueNameSupplyObj)
TVM_TIRX_DLL UniqueNameSupply(const ffi::String &prefix="", ffi::Map< ffi::String, int64_t > name_map={})
Constructor.
TVM_TIRX_DLL UniqueNameSupply(Iter begin, Iter end, Lambda f)
Construct UniqueNameSupply by reserving names from the given iterator range.
Definition unique_name_supply.h:131
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