56 #ifndef TVM_IR_TRANSFORM_H_ 57 #define TVM_IR_TRANSFORM_H_ 107 template <
typename TObjectRef>
110 static_assert(std::is_base_of<ObjectRef, TObjectRef>::value,
111 "Can only call GetAttr with ObjectRef types.");
112 if (!config.
defined())
return default_value;
113 auto it = config.
find(key);
114 if (it != config.
end()) {
115 return Downcast<Optional<TObjectRef>>((*it).second);
117 return default_value;
121 template <
typename TObjectRef>
128 v->Visit(
"required_pass", &required_pass);
129 v->Visit(
"disabled_pass", &disabled_pass);
130 v->Visit(
"instruments", &instruments);
131 v->Visit(
"config", &config);
132 v->Visit(
"diag_ctx", &diag_ctx);
135 static constexpr
const char*
_type_key =
"transform.PassContext";
162 ICHECK(
get() !=
nullptr);
170 ICHECK(
get() !=
nullptr);
196 TVM_DLL
void InstrumentEnterPassContext();
203 TVM_DLL
void InstrumentExitPassContext();
225 TVM_DLL
void InstrumentAfterPass(
const IRModule& mod,
const PassInfo& info)
const;
232 TVM_DLL
bool PassEnabled(
const PassInfo& info)
const;
240 template <
typename ValueType>
242 using ValueNodeType =
typename ValueType::ContainerType;
244 uint32_t tindex = ValueNodeType::_GetOrAllocRuntimeTypeIndex();
245 RegisterConfigOption(key, tindex);
255 TVM_DLL
void EnterWithScope();
257 TVM_DLL
void ExitWithScope();
259 TVM_DLL
static void RegisterConfigOption(
const char* key, uint32_t value_type_index);
262 friend class Internal;
266 #define TVM_PASS_CTX_CONFIG_VAR_DEF static TVM_ATTRIBUTE_UNUSED uint32_t __make_PassContext_tid 274 #define TVM_REGISTER_PASS_CONFIG_OPTION(Key, ValueType) \ 275 TVM_STR_CONCAT(TVM_PASS_CTX_CONFIG_VAR_DEF, __COUNTER__) = \ 276 ::tvm::transform::PassContext::RegisterConfigOption<ValueType>(Key) 296 v->Visit(
"opt_level", &opt_level);
297 v->Visit(
"name", &name);
298 v->Visit(
"required", &required);
301 static constexpr
const char*
_type_key =
"transform.PassInfo";
358 static constexpr
const char*
_type_key =
"transform.Pass";
395 const PassContext& pass_ctx);
415 v->Visit(
"pass_info", &pass_info);
416 v->Visit(
"passes", &passes);
451 static constexpr
const char*
_type_key =
"transform.Sequential";
507 #endif // TVM_IR_TRANSFORM_H_ int opt_level
The default optimization level.
Definition: transform.h:80
Array< String > required_pass
The list of required passes.
Definition: transform.h:83
Array< instrument::PassInstrument > instruments
A list of pass instrument implementations.
Definition: transform.h:92
A custom smart pointer for Object.
Definition: object.h:358
static constexpr const char * _type_key
Definition: transform.h:135
static PassContext Current()
Get the default pass context in the current scope.
Runtime String container types.
IRModule that holds the functions and type definitions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Optional< TObjectRef > GetConfig(const std::string &key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
Get a config value from the pass context.
Definition: transform.h:108
base class of all object containers.
Definition: object.h:167
static constexpr bool _type_has_method_sequal_reduce
Definition: transform.h:136
Runtime Array container types.
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
static uint32_t RegisterConfigOption(const char *key)
Register a valid configuration option and its ValueType for validation.
Definition: transform.h:241
Map< String, ObjectRef > config
Pass specific configurations.
Definition: transform.h:89
bool defined() const
Definition: object.h:544
const PassContextNode * operator->() const
const accessor.
Definition: transform.h:161
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
iterator find(const K &key) const
Definition: map.h:1383
TVM_DECLARE_FINAL_OBJECT_INFO(PassContextNode, Object)
PassContext that is used to configure the pass behavior.
Definition: transform.h:153
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
Optional< TObjectRef > GetConfig(const std::string &key, TObjectRef default_value) const
Definition: transform.h:122
Optional< DiagnosticContext > diag_ctx
The diagnostic context.
Definition: transform.h:87
RAII wrapper function to enter and exit a context object similar to python's with syntax...
Definition: with.h:58
PassContextNode()=default
Base class of all object reference.
Definition: object.h:511
iterator end() const
Definition: map.h:1381
Array< String > disabled_pass
The list of disabled passes.
Definition: transform.h:85
Managed reference class to IRModuleNode.
Definition: module.h:348
PassContextNode contains the information that a pass can rely on, such as analysis results...
Definition: transform.h:77
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
void VisitAttrs(AttrVisitor *v)
Definition: transform.h:126
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
A new diagnostic interface for TVM error reporting.
PassContext()
Definition: transform.h:155
PassContextNode * operator->()
mutable accessor.
Definition: transform.h:169
#define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
helper macro to declare a base object type that can be inherited.
Definition: object.h:648
IRModuleFrame IRModule()
The IRModule declaration statement.
PassContext(ObjectPtr< Object > n)
Definition: transform.h:156
RAII wrapper function to enter and exit a context object similar to python's with syntax...