56 #ifndef TVM_IR_TRANSFORM_H_ 57 #define TVM_IR_TRANSFORM_H_ 108 template <
typename TObjectRef>
111 static_assert(std::is_base_of<ObjectRef, TObjectRef>::value,
112 "Can only call GetAttr with ObjectRef types.");
113 if (!config.
defined())
return default_value;
114 auto it = config.
find(key);
115 if (it != config.
end()) {
116 return Downcast<Optional<TObjectRef>>((*it).second);
118 return default_value;
122 template <
typename TObjectRef>
129 v->Visit(
"required_pass", &required_pass);
130 v->Visit(
"disabled_pass", &disabled_pass);
131 v->Visit(
"instruments", &instruments);
132 v->Visit(
"config", &config);
133 v->Visit(
"diag_ctx", &diag_ctx);
136 static constexpr
const char*
_type_key =
"transform.PassContext";
163 ICHECK(
get() !=
nullptr);
171 ICHECK(
get() !=
nullptr);
197 TVM_DLL
void InstrumentEnterPassContext();
204 TVM_DLL
void InstrumentExitPassContext();
226 TVM_DLL
void InstrumentAfterPass(
const IRModule& mod,
const PassInfo& info)
const;
233 TVM_DLL
bool PassEnabled(
const PassInfo& info)
const;
241 template <
typename ValueType>
243 using ValueNodeType =
typename ValueType::ContainerType;
245 uint32_t tindex = ValueNodeType::_GetOrAllocRuntimeTypeIndex();
246 RegisterConfigOption(key, tindex);
256 TVM_DLL
void EnterWithScope();
258 TVM_DLL
void ExitWithScope();
260 TVM_DLL
static void RegisterConfigOption(
const char* key, uint32_t value_type_index);
263 friend class Internal;
267 #define TVM_PASS_CTX_CONFIG_VAR_DEF static TVM_ATTRIBUTE_UNUSED uint32_t __make_PassContext_tid 275 #define TVM_REGISTER_PASS_CONFIG_OPTION(Key, ValueType) \ 276 TVM_STR_CONCAT(TVM_PASS_CTX_CONFIG_VAR_DEF, __COUNTER__) = \ 277 ::tvm::transform::PassContext::RegisterConfigOption<ValueType>(Key) 297 v->Visit(
"opt_level", &opt_level);
298 v->Visit(
"name", &name);
299 v->Visit(
"required", &required);
302 static constexpr
const char*
_type_key =
"transform.PassInfo";
359 static constexpr
const char*
_type_key =
"transform.Pass";
395 class SequentialNode;
420 const SequentialNode* operator->()
const;
449 #endif // TVM_IR_TRANSFORM_H_ int opt_level
The default optimization level.
Definition: transform.h:81
Array< String > required_pass
The list of required passes.
Definition: transform.h:84
Array< instrument::PassInstrument > instruments
A list of pass instrument implementations.
Definition: transform.h:93
A custom smart pointer for Object.
Definition: object.h:356
static constexpr const char * _type_key
Definition: transform.h:136
static PassContext Current()
Get the default pass context in the current scope.
Runtime String container types.
IRModule that holds the functions and type definitions.
Performance counters for profiling via the PAPI library.
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:109
base class of all object containers.
Definition: object.h:165
static constexpr bool _type_has_method_sequal_reduce
Definition: transform.h:137
Runtime Array container types.
Utilities for error tracking and reporting.
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:242
Map< String, ObjectRef > config
Pass specific configurations.
Definition: transform.h:90
bool defined() const
Definition: object.h:537
const PassContextNode * operator->() const
const accessor.
Definition: transform.h:162
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
iterator find(const K &key) const
Definition: map.h:1347
TVM_DECLARE_FINAL_OBJECT_INFO(PassContextNode, Object)
PassContext that is used to configure the pass behavior.
Definition: transform.h:154
Reference to string objects.
Definition: string.h:129
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:136
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:706
Optional< TObjectRef > GetConfig(const std::string &key, TObjectRef default_value) const
Definition: transform.h:123
Optional< DiagnosticContext > diag_ctx
The diagnostic context.
Definition: transform.h:88
RAII wrapper function to enter and exit a context object similar to python's with syntax...
Definition: with.h:57
PassContextNode()=default
Base class of all object reference.
Definition: object.h:504
iterator end() const
Definition: map.h:1345
Array< String > disabled_pass
The list of disabled passes.
Definition: transform.h:86
Managed reference class to IRModuleNode.
Definition: module.h:352
PassContextNode contains the information that a pass can rely on, such as analysis results...
Definition: transform.h:78
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:1235
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
void VisitAttrs(AttrVisitor *v)
Definition: transform.h:127
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:271
A new diagnostic interface for TVM error reporting.
PassContext()
Definition: transform.h:156
PassContextNode * operator->()
mutable accessor.
Definition: transform.h:170
#define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
helper macro to declare a base object type that can be inherited.
Definition: object.h:641
PassContext(ObjectPtr< Object > n)
Definition: transform.h:157
RAII wrapper function to enter and exit a context object similar to python's with syntax...