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);
115 return Downcast<Optional<TObjectRef>>((*it).second);
117 return default_value;
121 template <
typename TObjectRef>
131 v->Visit(
"config", &
config);
135 static constexpr
const char*
_type_key =
"transform.PassContext";
162 ICHECK(
get() !=
nullptr);
170 ICHECK(
get() !=
nullptr);
240 template <
typename ValueType>
242 using ValueNodeType =
typename ValueType::ContainerType;
244 uint32_t tindex = ValueNodeType::_GetOrAllocRuntimeTypeIndex();
255 TVM_DLL
void EnterWithScope();
257 TVM_DLL
void ExitWithScope();
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)
297 v->Visit(
"name", &
name);
301 static constexpr
const char*
_type_key =
"transform.PassInfo";
358 static constexpr
const char*
_type_key =
"transform.Pass";
416 v->Visit(
"passes", &
passes);
449 static constexpr
const char*
_type_key =
"transform.Sequential";
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
Managed reference class to IRModuleNode.
Definition: module.h:348
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with.h:58
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
A custom smart pointer for Object.
Definition: object.h:360
Base class of all object reference.
Definition: object.h:517
const Object * get() const
Definition: object.h:552
Object * get_mutable() const
Definition: object.h:605
base class of all object containers.
Definition: object.h:169
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:61
PassContextNode contains the information that a pass can rely on, such as analysis results.
Definition: transform.h:77
Array< String > required_pass
The list of required passes.
Definition: transform.h:83
static constexpr bool _type_has_method_sequal_reduce
Definition: transform.h:136
Optional< TObjectRef > GetConfig(const std::string &key, TObjectRef default_value) const
Definition: transform.h:122
TVM_DECLARE_FINAL_OBJECT_INFO(PassContextNode, Object)
Optional< DiagnosticContext > diag_ctx
The diagnostic context.
Definition: transform.h:87
PassContextNode()=default
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
void VisitAttrs(AttrVisitor *v)
Definition: transform.h:126
Array< String > disabled_pass
The list of disabled passes.
Definition: transform.h:85
Array< instrument::PassInstrument > instruments
A list of pass instrument implementations.
Definition: transform.h:92
static constexpr const char * _type_key
Definition: transform.h:135
int opt_level
The default optimization level.
Definition: transform.h:80
Map< String, ObjectRef > config
Pass specific configurations.
Definition: transform.h:89
PassContext that is used to configure the pass behavior.
Definition: transform.h:153
static Map< String, Map< String, String > > ListConfigs()
Get all supported configuration names and metadata, registered within the PassContext.
const PassContextNode * operator->() const
const accessor.
Definition: transform.h:161
static PassContext Current()
Get the default pass context in the current scope.
bool PassEnabled(const PassInfo &info) const
Check whether a pass is enabled.
static uint32_t RegisterConfigOption(const char *key)
Register a valid configuration option and its ValueType for validation.
Definition: transform.h:241
friend class Internal
Definition: transform.h:262
PassContext(ObjectPtr< Object > n)
Definition: transform.h:156
PassContext()
Definition: transform.h:155
static PassContext Create()
Construct a PassContext containing the default configurations.
PassContextNode * operator->()
mutable accessor.
Definition: transform.h:169
void InstrumentEnterPassContext()
Call instrument implementations' callbacks when entering PassContext. The callbacks are called in ord...
void InstrumentExitPassContext()
Call instrument implementations' callbacks when exiting PassContext. The callbacks are called in orde...
bool InstrumentBeforePass(const IRModule &mod, const PassInfo &info) const
Call instrument implementations' callbacks before a pass run. The callbacks are called in order,...
void InstrumentAfterPass(const IRModule &mod, const PassInfo &info) const
Call instrument implementations callbacks after a pass run. The callbacks are called in order,...
A new diagnostic interface for TVM error reporting.
IRModule that holds the functions and type definitions.
IRModuleFrame IRModule()
The IRModule declaration statement.
Definition: module.h:341
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Runtime String container types.
RAII wrapper function to enter and exit a context object similar to python's with syntax.