14 #include "TypeDetail.h"
29 #include "llvm/ADT/DenseMap.h"
30 #include "llvm/ADT/DenseSet.h"
31 #include "llvm/ADT/SmallString.h"
32 #include "llvm/ADT/StringSet.h"
33 #include "llvm/ADT/Twine.h"
34 #include "llvm/Support/Allocator.h"
35 #include "llvm/Support/CommandLine.h"
36 #include "llvm/Support/Compiler.h"
37 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/Mutex.h"
39 #include "llvm/Support/RWMutex.h"
40 #include "llvm/Support/ThreadPool.h"
41 #include "llvm/Support/raw_ostream.h"
45 #define DEBUG_TYPE "mlircontext"
58 struct MLIRContextOptions {
59 llvm::cl::opt<bool> disableThreading{
60 "mlir-disable-threading",
61 llvm::cl::desc(
"Disable multi-threading within MLIR, overrides any "
62 "further call to MLIRContext::enableMultiThreading()")};
64 llvm::cl::opt<bool> printOpOnDiagnostic{
65 "mlir-print-op-on-diagnostic",
66 llvm::cl::desc(
"When a diagnostic is emitted on an operation, also print "
67 "the operation as an attached note"),
68 llvm::cl::init(
true)};
70 llvm::cl::opt<bool> printStackTraceOnDiagnostic{
71 "mlir-print-stacktrace-on-diagnostic",
72 llvm::cl::desc(
"When a diagnostic is emitted, also print the stack trace "
73 "as an attached note")};
77 static llvm::ManagedStatic<MLIRContextOptions>
clOptions;
80 #if LLVM_ENABLE_THREADS != 0
102 struct ScopedWriterLock {
103 ScopedWriterLock(llvm::sys::SmartRWMutex<true> &mutexParam,
bool shouldLock)
104 : mutex(shouldLock ? &mutexParam : nullptr) {
108 ~ScopedWriterLock() {
112 llvm::sys::SmartRWMutex<true> *mutex;
146 bool allowUnregisteredDialects =
false;
149 bool threadingIsEnabled =
true;
155 std::atomic<int> multiThreadedExecutionContext{0};
160 bool printOpOnDiagnostic =
true;
163 bool printStackTraceOnDiagnostic =
false;
173 llvm::ThreadPoolInterface *threadPool =
nullptr;
183 llvm::StringMap<std::unique_ptr<OperationName::Impl>>
operations;
238 IntegerType int1Ty, int8Ty, int16Ty, int32Ty, int64Ty,
int128Ty;
277 : threadingIsEnabled(threadingIsEnabled) {
278 if (threadingIsEnabled) {
279 ownedThreadPool = std::make_unique<llvm::DefaultThreadPool>();
280 threadPool = ownedThreadPool.get();
284 for (
auto typeMapping : registeredTypes)
285 typeMapping.second->~AbstractType();
286 for (
auto attrMapping : registeredAttributes)
287 attrMapping.second->~AbstractAttribute();
308 getOrLoadDialect<BuiltinDialect>();
315 impl->f8E5M2Ty = TypeUniquer::get<Float8E5M2Type>(
this);
316 impl->f8E4M3Ty = TypeUniquer::get<Float8E4M3Type>(
this);
317 impl->f8E4M3FNTy = TypeUniquer::get<Float8E4M3FNType>(
this);
318 impl->f8E5M2FNUZTy = TypeUniquer::get<Float8E5M2FNUZType>(
this);
319 impl->f8E4M3FNUZTy = TypeUniquer::get<Float8E4M3FNUZType>(
this);
320 impl->f8E4M3B11FNUZTy = TypeUniquer::get<Float8E4M3B11FNUZType>(
this);
321 impl->bf16Ty = TypeUniquer::get<BFloat16Type>(
this);
322 impl->f16Ty = TypeUniquer::get<Float16Type>(
this);
323 impl->tf32Ty = TypeUniquer::get<FloatTF32Type>(
this);
324 impl->f32Ty = TypeUniquer::get<Float32Type>(
this);
325 impl->f64Ty = TypeUniquer::get<Float64Type>(
this);
326 impl->f80Ty = TypeUniquer::get<Float80Type>(
this);
327 impl->f128Ty = TypeUniquer::get<Float128Type>(
this);
329 impl->indexTy = TypeUniquer::get<IndexType>(
this);
331 impl->int1Ty = TypeUniquer::get<IntegerType>(
this, 1, IntegerType::Signless);
332 impl->int8Ty = TypeUniquer::get<IntegerType>(
this, 8, IntegerType::Signless);
334 TypeUniquer::get<IntegerType>(
this, 16, IntegerType::Signless);
336 TypeUniquer::get<IntegerType>(
this, 32, IntegerType::Signless);
338 TypeUniquer::get<IntegerType>(
this, 64, IntegerType::Signless);
340 TypeUniquer::get<IntegerType>(
this, 128, IntegerType::Signless);
342 impl->noneType = TypeUniquer::get<NoneType>(
this);
348 impl->unknownLocAttr = AttributeUniquer::get<UnknownLoc>(
this);
350 impl->falseAttr = IntegerAttr::getBoolAttrUnchecked(
impl->int1Ty,
false);
351 impl->trueAttr = IntegerAttr::getBoolAttrUnchecked(
impl->int1Ty,
true);
353 impl->unitAttr = AttributeUniquer::get<UnitAttr>(
this);
355 impl->emptyDictionaryAttr = DictionaryAttr::getEmptyUnchecked(
this);
357 impl->emptyStringAttr = StringAttr::getEmptyStringAttrUnchecked(
this);
373 template <
typename T>
376 auto result = allocator.Allocate<T>(elements.size());
377 std::uninitialized_copy(elements.begin(), elements.end(), result);
390 void MLIRContext::executeActionInternal(
function_ref<
void()> actionFn,
392 assert(
getImpl().actionHandler);
413 assert(
impl->multiThreadedExecutionContext == 0 &&
414 "appending to the MLIRContext dialect registry while in a "
415 "multi-threaded execution context");
423 return impl->dialectsRegistry;
428 std::vector<Dialect *> result;
429 result.reserve(
impl->loadedDialects.size());
430 for (
auto &dialect :
impl->loadedDialects)
431 result.push_back(dialect.second.get());
432 llvm::array_pod_sort(result.begin(), result.end(),
434 return (*lhs)->getNamespace() < (*rhs)->getNamespace();
439 std::vector<StringRef> result;
440 for (
auto dialect :
impl->dialectsRegistry.getDialectNames())
441 result.push_back(dialect);
449 auto it =
impl->loadedDialects.find(name);
450 return (it !=
impl->loadedDialects.end()) ? it->second.get() :
nullptr;
458 impl->dialectsRegistry.getDialectAllocator(name);
459 return allocator ? allocator(
this) :
nullptr;
470 auto dialectIt =
impl.loadedDialects.try_emplace(dialectNamespace,
nullptr);
472 if (dialectIt.second) {
473 LLVM_DEBUG(llvm::dbgs()
474 <<
"Load new dialect in Context " << dialectNamespace <<
"\n");
476 if (
impl.multiThreadedExecutionContext != 0)
477 llvm::report_fatal_error(
478 "Loading a dialect (" + dialectNamespace +
479 ") while in a multi-threaded execution context (maybe "
480 "the PassManager): this can indicate a "
481 "missing `dependentDialects` in a pass for example.");
487 std::unique_ptr<Dialect> &dialectOwned =
488 impl.loadedDialects[dialectNamespace] = ctor();
489 Dialect *dialect = dialectOwned.get();
490 assert(dialect &&
"dialect ctor failed");
495 auto stringAttrsIt =
impl.dialectReferencingStrAttrs.find(dialectNamespace);
496 if (stringAttrsIt !=
impl.dialectReferencingStrAttrs.end()) {
499 impl.dialectReferencingStrAttrs.erase(stringAttrsIt);
503 impl.dialectsRegistry.applyExtensions(dialect);
508 if (dialectIt.first->second ==
nullptr)
509 llvm::report_fatal_error(
510 "Loading (and getting) a dialect (" + dialectNamespace +
511 ") while the same dialect is still loading: use loadDialect instead "
512 "of getOrLoadDialect.");
516 std::unique_ptr<Dialect> &dialect = dialectIt.first->second;
517 if (dialect->getTypeID() != dialectID)
518 llvm::report_fatal_error(
"a dialect with namespace '" + dialectNamespace +
519 "' has already been registered");
521 return dialect.get();
524 bool MLIRContext::isDialectLoading(StringRef dialectNamespace) {
534 auto dialectIt =
impl.loadedDialects.find(dialectNamespace);
536 if (dialectIt !=
impl.loadedDialects.end()) {
537 if (
auto *dynDialect = dyn_cast<DynamicDialect>(dialectIt->second.get()))
539 llvm::report_fatal_error(
"a dialect with namespace '" + dialectNamespace +
540 "' has already been registered");
543 LLVM_DEBUG(llvm::dbgs() <<
"Load new dynamic dialect in Context "
544 << dialectNamespace <<
"\n");
546 if (
impl.multiThreadedExecutionContext != 0)
547 llvm::report_fatal_error(
548 "Loading a dynamic dialect (" + dialectNamespace +
549 ") while in a multi-threaded execution context (maybe "
550 "the PassManager): this can indicate a "
551 "missing `dependentDialects` in a pass for example.");
558 return std::unique_ptr<DynamicDialect>(dialect);
571 llvm::hash_code hash(0);
573 hash = llvm::hash_combine(hash,
impl->loadedDialects.size());
574 hash = llvm::hash_combine(hash,
impl->registeredAttributes.size());
575 hash = llvm::hash_combine(hash,
impl->registeredOperations.size());
576 hash = llvm::hash_combine(hash,
impl->registeredTypes.size());
581 return impl->allowUnregisteredDialects;
585 assert(
impl->multiThreadedExecutionContext == 0 &&
586 "changing MLIRContext `allow-unregistered-dialects` configuration "
587 "while in a multi-threaded execution context");
588 impl->allowUnregisteredDialects = allowing;
593 return impl->threadingIsEnabled && llvm::llvm_is_multithreaded();
602 assert(
impl->multiThreadedExecutionContext == 0 &&
603 "changing MLIRContext `disable-threading` configuration while "
604 "in a multi-threaded execution context");
606 impl->threadingIsEnabled = !disable;
609 impl->affineUniquer.disableMultithreading(disable);
610 impl->attributeUniquer.disableMultithreading(disable);
611 impl->typeUniquer.disableMultithreading(disable);
619 if (
impl->ownedThreadPool) {
620 assert(
impl->threadPool);
621 impl->threadPool =
nullptr;
622 impl->ownedThreadPool.reset();
624 }
else if (!
impl->threadPool) {
626 assert(!
impl->ownedThreadPool);
627 impl->ownedThreadPool = std::make_unique<llvm::DefaultThreadPool>();
628 impl->threadPool =
impl->ownedThreadPool.get();
634 "expected multi-threading to be disabled when setting a ThreadPool");
635 impl->threadPool = &pool;
636 impl->ownedThreadPool.reset();
642 assert(
impl->threadPool &&
643 "multi-threading is enabled but threadpool not set");
644 return impl->threadPool->getMaxConcurrency();
652 "expected multi-threading to be enabled within the context");
653 assert(
impl->threadPool &&
654 "multi-threading is enabled but threadpool not set");
655 return *
impl->threadPool;
660 ++
impl->multiThreadedExecutionContext;
665 --
impl->multiThreadedExecutionContext;
672 return impl->printOpOnDiagnostic;
678 assert(
impl->multiThreadedExecutionContext == 0 &&
679 "changing MLIRContext `print-op-on-diagnostic` configuration while in "
680 "a multi-threaded execution context");
681 impl->printOpOnDiagnostic = enable;
687 return impl->printStackTraceOnDiagnostic;
693 assert(
impl->multiThreadedExecutionContext == 0 &&
694 "changing MLIRContext `print-stacktrace-on-diagnostic` configuration "
695 "while in a multi-threaded execution context");
696 impl->printStackTraceOnDiagnostic = enable;
701 return impl->sortedRegisteredOperations;
710 assert(
impl.multiThreadedExecutionContext == 0 &&
711 "Registering a new type kind while in a multi-threaded execution "
716 if (!
impl.registeredTypes.insert({typeID, newInfo}).second)
717 llvm::report_fatal_error(
"Dialect Type already registered.");
718 if (!
impl.nameToType.insert({newInfo->getName(), newInfo}).second)
719 llvm::report_fatal_error(
"Dialect Type with name " + newInfo->getName() +
720 " is already registered.");
725 assert(
impl.multiThreadedExecutionContext == 0 &&
726 "Registering a new attribute kind while in a multi-threaded execution "
731 if (!
impl.registeredAttributes.insert({typeID, newInfo}).second)
732 llvm::report_fatal_error(
"Dialect Attribute already registered.");
733 if (!
impl.nameToAttribute.insert({newInfo->getName(), newInfo}).second)
734 llvm::report_fatal_error(
"Dialect Attribute with name " +
735 newInfo->getName() +
" is already registered.");
747 llvm::report_fatal_error(
"Trying to create an Attribute that was not "
748 "registered in this MLIRContext.");
755 return impl.registeredAttributes.lookup(typeID);
758 std::optional<std::reference_wrapper<const AbstractAttribute>>
775 std::move(interfaceMap)) {}
782 if (isMultithreadingEnabled) {
788 impl = registeredIt->second.impl;
795 impl = it->second.get();
803 auto it = ctxImpl.
operations.insert({name,
nullptr});
806 it.first->second = std::make_unique<UnregisteredOpModel>(
807 nameAttr, nameAttr.getReferencedDialect(), TypeID::get<void>(),
810 impl = it.first->second.get();
815 return dialect->getNamespace();
830 llvm::report_fatal_error(
"getParseAssemblyFn hook called on unregistered op");
847 std::optional<Attribute>
850 auto dict = dyn_cast_or_null<DictionaryAttr>(getPropertiesAsAttr(op));
860 auto dict = dyn_cast_or_null<DictionaryAttr>(getPropertiesAsAttr(op));
863 attrs.
set(name, value);
907 return llvm::hash_combine(*prop.
as<
Attribute *>());
914 std::optional<RegisteredOperationName>
917 auto it =
impl.registeredOperations.find(typeID);
918 if (it !=
impl.registeredOperations.end())
923 std::optional<RegisteredOperationName>
926 auto it =
impl.registeredOperationsByName.find(name);
927 if (it !=
impl.registeredOperationsByName.end())
928 return it->getValue();
933 std::unique_ptr<RegisteredOperationName::Impl> ownedImpl,
937 auto &ctxImpl = ctx->
getImpl();
938 assert(ctxImpl.multiThreadedExecutionContext == 0 &&
939 "registering a new operation kind while in a multi-threaded execution "
944 if (!attrNames.empty()) {
946 ctxImpl.abstractDialectSymbolAllocator.Allocate<StringAttr>(
949 for (
unsigned i : llvm::seq<unsigned>(0, attrNames.size()))
950 new (&cachedAttrNames[i]) StringAttr(
StringAttr::get(ctx, attrNames[i]));
951 impl->attributeNames = cachedAttrNames;
953 StringRef name =
impl->getName().strref();
955 auto it = ctxImpl.operations.insert({name,
nullptr});
956 it.first->second = std::move(ownedImpl);
959 auto emplaced = ctxImpl.registeredOperations.try_emplace(
961 assert(emplaced.second &&
"operation name registration must be successful");
962 auto emplacedByName = ctxImpl.registeredOperationsByName.try_emplace(
964 (void)emplacedByName;
965 assert(emplacedByName.second &&
966 "operation name registration must be successful");
970 ctxImpl.sortedRegisteredOperations.
insert(
971 llvm::upper_bound(ctxImpl.sortedRegisteredOperations, value,
972 [](
auto &lhs,
auto &rhs) {
973 return lhs.getIdentifier().compare(
974 rhs.getIdentifier());
984 const AbstractType *type = lookupMutable(typeID, context);
986 llvm::report_fatal_error(
987 "Trying to create a Type that was not registered in this MLIRContext.");
993 return impl.registeredTypes.lookup(typeID);
996 std::optional<std::reference_wrapper<const AbstractType>>
1002 return std::nullopt;
1063 IntegerType::SignednessSemantics signedness,
1065 if (signedness != IntegerType::Signless)
1066 return IntegerType();
1082 return IntegerType();
1087 IntegerType::SignednessSemantics signedness) {
1090 return Base::get(context, width, signedness);
1096 SignednessSemantics signedness) {
1099 return Base::getChecked(
emitError, context, width, signedness);
1118 return getImpl().attributeUniquer;
1122 void AttributeUniquer::initializeAttributeStorage(
AttributeStorage *storage,
1141 detail::DistinctAttributeUniquer::allocateStorage(
MLIRContext *context,
1147 DictionaryAttr DictionaryAttr::getEmpty(
MLIRContext *context) {
1154 auto dialectNamePair = value.split(
'.');
1155 if (dialectNamePair.first.empty() || dialectNamePair.second.empty())
1161 if ((referencedDialect = context->
getLoadedDialect(dialectNamePair.first)))
1165 llvm::sys::SmartScopedLock<true> lock(
impl.dialectRefStrAttrMutex);
1166 impl.dialectReferencingStrAttrs[dialectNamePair.first].push_back(
this);
1179 return getImpl().affineUniquer;
1182 AffineMap AffineMap::getImpl(
unsigned dimCount,
unsigned symbolCount,
1188 symbolCount, results);
1197 LLVM_ATTRIBUTE_UNUSED
static bool
1200 int64_t maxDimPosition = -1;
1201 int64_t maxSymbolPosition = -1;
1204 if ((maxDimPosition >= dimCount) || (maxSymbolPosition >= symbolCount)) {
1207 <<
"maximum dimensional identifier position in result expression must "
1208 "be less than `dimCount` and maximum symbolic identifier position "
1209 "in result expression must be less than `symbolCount`\n");
1216 return getImpl(0, 0, {}, context);
1221 return getImpl(dimCount, symbolCount, {}, context);
1233 return getImpl(dimCount, symbolCount, results, context);
1245 assert(!constraints.empty());
1246 assert(constraints.size() == eqFlags.size());
1248 auto &
impl = constraints[0].getContext()->getImpl();
static MLIRContext * getContext(OpFoldResult val)
static LLVM_ATTRIBUTE_UNUSED bool willBeValidAffineMap(unsigned dimCount, unsigned symbolCount, ArrayRef< AffineExpr > results)
Check whether the arguments passed to the AffineMap::get() are consistent.
static bool isThreadingGloballyDisabled()
static ArrayRef< T > copyArrayRefInto(llvm::BumpPtrAllocator &allocator, ArrayRef< T > elements)
Copy the specified array of elements into memory managed by the provided bump pointer allocator.
static llvm::ManagedStatic< MLIRContextOptions > clOptions
static IntegerType getCachedIntegerType(unsigned width, IntegerType::SignednessSemantics signedness, MLIRContext *context)
Return an existing integer type instance if one is cached within the context.
This class contains all of the static information common to all instances of a registered Attribute.
static const AbstractAttribute & lookup(TypeID typeID, MLIRContext *context)
Look up the specified abstract attribute in the MLIRContext and return a reference to it.
This class contains all of the static information common to all instances of a registered Type.
static const AbstractType & lookup(TypeID typeID, MLIRContext *context)
Look up the specified abstract type in the MLIRContext and return a reference to it.
Base type for affine expression.
MLIRContext * getContext() const
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
static AffineMap get(MLIRContext *context)
Returns a zero result affine map with no dimensions or symbols: () -> ().
Base storage class appearing in an attribute.
void initializeAbstractAttribute(const AbstractAttribute &abstractAttr)
Set the abstract attribute for this storage instance.
Attributes are known-constant values of operations.
Special case of IntegerAttr to represent boolean integers, i.e., signless i1 integers.
static BoolAttr get(MLIRContext *context, bool value)
This class is the main interface for diagnostics.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool isSubsetOf(const DialectRegistry &rhs) const
Returns true if the current registry is a subset of 'rhs', i.e.
void appendTo(DialectRegistry &destination) const
void applyExtensions(Dialect *dialect) const
Apply any held extensions that require the given dialect.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
A dialect that can be defined at runtime.
This class represents a diagnostic that is inflight and set to be reported.
An integer set representing a conjunction of one or more affine equalities and inequalities.
static IntegerSet get(unsigned dimCount, unsigned symbolCount, ArrayRef< AffineExpr > constraints, ArrayRef< bool > eqFlags)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This is the implementation of the MLIRContext class, using the pImpl idiom.
DictionaryAttr emptyDictionaryAttr
llvm::DenseMap< StringRef, AbstractAttribute * > nameToAttribute
This is a mapping from attribute name to the abstract attribute describing it.
DenseMap< StringRef, std::unique_ptr< Dialect > > loadedDialects
This is a list of dialects that are created referring to this context.
llvm::DenseMap< TypeID, RegisteredOperationName > registeredOperations
A vector of operation info specifically for registered operations.
BoolAttr falseAttr
Cached Attribute Instances.
llvm::sys::SmartRWMutex< true > operationInfoMutex
A mutex used when accessing operation information.
Float8E5M2FNUZType f8E5M2FNUZTy
DenseMap< StringRef, SmallVector< StringAttrStorage * > > dialectReferencingStrAttrs
llvm::StringMap< RegisteredOperationName > registeredOperationsByName
StringAttr emptyStringAttr
std::function< void(function_ref< void()>, const tracing::Action &)> actionHandler
An action handler for handling actions that are dispatched through this context.
llvm::sys::SmartMutex< true > dialectRefStrAttrMutex
Map of string attributes that may reference a dialect, that are awaiting that dialect to be loaded.
llvm::DenseMap< StringRef, AbstractType * > nameToType
This is a mapping from type name to the abstract type describing it.
StorageUniquer typeUniquer
llvm::BumpPtrAllocator abstractDialectSymbolAllocator
An allocator used for AbstractAttribute and AbstractType objects.
DenseMap< TypeID, AbstractType * > registeredTypes
Float8E5M2Type f8E5M2Ty
Cached Type Instances.
StorageUniquer affineUniquer
DiagnosticEngine diagEngine
UnknownLoc unknownLocAttr
DenseMap< TypeID, AbstractAttribute * > registeredAttributes
llvm::StringMap< std::unique_ptr< OperationName::Impl > > operations
This is a mapping from operation name to the operation info describing it.
Float8E4M3FNUZType f8E4M3FNUZTy
Float8E4M3B11FNUZType f8E4M3B11FNUZTy
std::unique_ptr< llvm::ThreadPoolInterface > ownedThreadPool
In case where the thread pool is owned by the context, this ensures destruction with the context.
SmallVector< RegisteredOperationName, 0 > sortedRegisteredOperations
This is a sorted container of registered operations for a deterministic and efficient getRegisteredOp...
Float8E4M3FNType f8E4M3FNTy
DistinctAttributeAllocator distinctAttributeAllocator
A distinct attribute allocator that allocates every time since the address of the distinct attribute ...
MLIRContextImpl(bool threadingIsEnabled)
StorageUniquer attributeUniquer
DialectRegistry dialectsRegistry
MLIRContext is the top-level object for a collection of MLIR operations.
void appendDialectRegistry(const DialectRegistry ®istry)
Append the contents of the given dialect registry to the registry associated with this context.
bool shouldPrintStackTraceOnDiagnostic()
Return true if we should attach the current stacktrace to diagnostics when emitted.
unsigned getNumThreads()
Return the number of threads used by the thread pool in this context.
bool isOperationRegistered(StringRef name)
Return true if this operation name is registered in this context.
MLIRContext(Threading multithreading=Threading::ENABLED)
Create a new Context.
void disableMultithreading(bool disable=true)
Set the flag specifying if multi-threading is disabled by the context.
void printStackTraceOnDiagnostic(bool enable)
Set the flag specifying if we should attach the current stacktrace when emitting diagnostics.
Dialect * getLoadedDialect(StringRef name)
Get a registered IR dialect with the given namespace.
bool hasActionHandler()
Return true if a valid ActionHandler is set.
void setThreadPool(llvm::ThreadPoolInterface &pool)
Set a new thread pool to be used in this context.
void enableMultithreading(bool enable=true)
std::vector< Dialect * > getLoadedDialects()
Return information about all IR dialects loaded in the context.
void printOpOnDiagnostic(bool enable)
Set the flag specifying if we should attach the operation to diagnostics emitted via Operation::emit.
void registerActionHandler(HandlerTy handler)
Register a handler for handling actions that are dispatched through this context.
ArrayRef< RegisteredOperationName > getRegisteredOperations()
Return a sorted array containing the information about all registered operations.
llvm::hash_code getRegistryHash()
Returns a hash of the registry of the context that may be used to give a rough indicator of if the st...
void enterMultiThreadedExecution()
These APIs are tracking whether the context will be used in a multithreading environment: this has no...
const DialectRegistry & getDialectRegistry()
Return the dialect registry associated with this context.
DynamicDialect * getOrLoadDynamicDialect(StringRef dialectNamespace, function_ref< void(DynamicDialect *)> ctor)
Get (or create) a dynamic dialect for the given name.
StorageUniquer & getAttributeUniquer()
Returns the storage uniquer used for constructing attribute storage instances.
StorageUniquer & getAffineUniquer()
Returns the storage uniquer used for creating affine constructs.
StorageUniquer & getTypeUniquer()
Returns the storage uniquer used for constructing type storage instances.
llvm::ThreadPoolInterface & getThreadPool()
Return the thread pool used by this context.
std::vector< StringRef > getAvailableDialects()
Return information about all available dialects in the registry in this context.
bool isMultithreadingEnabled()
Return true if multi-threading is enabled by the context.
void allowUnregisteredDialects(bool allow=true)
Enables creating operations in unregistered dialects.
bool allowsUnregisteredDialects()
Return true if we allow to create operation for unregistered dialects.
T * getLoadedDialect()
Get a registered IR dialect for the given derived dialect type.
DiagnosticEngine & getDiagEngine()
Returns the diagnostic engine for this context.
std::function< void(function_ref< void()>, const tracing::Action &)> HandlerTy
Signatures for the action handler that can be registered with the context.
MLIRContextImpl & getImpl()
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
void exitMultiThreadedExecution()
bool shouldPrintOpOnDiagnostic()
Return true if we should attach the operation to diagnostics emitted via Operation::emit.
void loadAllAvailableDialects()
Load all dialects available in the registry in this context.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
Attribute set(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printGenericOp(Operation *op, bool printOpName=true)=0
Print the entire operation with the default generic assembly form.
Simple wrapper around a void* in order to express generically how to pass in op properties through AP...
Impl(StringRef, Dialect *dialect, TypeID typeID, detail::InterfaceMap interfaceMap)
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
llvm::unique_function< ParseResult(OpAsmParser &, OperationState &)> ParseAssemblyFn
Dialect * getDialect() const
Return the dialect this operation is registered to if the dialect is loaded in the context,...
OperationName(StringRef name, MLIRContext *context)
StringRef getDialectNamespace() const
Return the name of the dialect this operation is registered to.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
OpaqueProperties getPropertiesStorage()
Returns the properties storage.
This is a "type erased" representation of a registered operation.
static void insert(Dialect &dialect)
Register a new operation in a Dialect object.
static std::optional< RegisteredOperationName > lookup(StringRef name, MLIRContext *ctx)
Lookup the registered operation information for the given operation.
A utility class to get or create instances of "storage classes".
This class provides an efficient unique identifier for a specific C++ type.
An allocator for distinct attribute storage instances.
DistinctAttrStorage * allocate(Attribute referencedAttr)
Allocates a distinct attribute storage using a thread local bump pointer allocator to enable synchron...
This class provides an efficient mapping between a given Interface type, and a particular implementat...
An action is a specific action that is to be taken by the compiler, that can be toggled and controlle...
llvm::unique_function< InFlightDiagnostic()> getDefaultDiagnosticEmitFn(MLIRContext *ctx)
Utility method to generate a callback that can be used to generate a diagnostic when checking the con...
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
void registerMLIRContextCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
static void getMaxDimAndSymbol(ArrayRef< AffineExprContainer > exprsList, int64_t &maxDim, int64_t &maxSym)
Calculates maximum dimension and symbol positions from the expressions in exprsLists and stores them ...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult foldHook(Operation *, ArrayRef< Attribute >, SmallVectorImpl< OpFoldResult > &) final
llvm::hash_code hashProperties(OpaqueProperties) final
void populateInherentAttrs(Operation *op, NamedAttrList &attrs) final
void deleteProperties(OpaqueProperties) final
LogicalResult setPropertiesFromAttr(OperationName, OpaqueProperties, Attribute, function_ref< InFlightDiagnostic()> emitError) final
int getOpPropertyByteSize() final
void setInherentAttr(Operation *op, StringAttr name, Attribute value) final
void populateDefaultProperties(OperationName opName, OpaqueProperties properties) final
OperationName::ParseAssemblyFn getParseAssemblyFn() final
bool hasTrait(TypeID) final
LogicalResult verifyRegionInvariants(Operation *) final
std::optional< Attribute > getInherentAttr(Operation *op, StringRef name) final
Implementation for properties.
void getCanonicalizationPatterns(RewritePatternSet &, MLIRContext *) final
void initProperties(OperationName opName, OpaqueProperties storage, OpaqueProperties init) final
void populateDefaultAttrs(const OperationName &, NamedAttrList &) final
void printAssembly(Operation *, OpAsmPrinter &, StringRef) final
LogicalResult verifyInvariants(Operation *) final
void copyProperties(OpaqueProperties, OpaqueProperties) final
LogicalResult verifyInherentAttrs(OperationName opName, NamedAttrList &attributes, function_ref< InFlightDiagnostic()> emitError) final
Attribute getPropertiesAsAttr(Operation *) final
bool compareProperties(OpaqueProperties, OpaqueProperties) final
A binary operation appearing in an affine expression.
An integer constant appearing in affine expression.
A dimensional or symbolic identifier appearing in an affine expression.
An attribute to store a distinct reference to another attribute.
Dialect * referencedDialect
If the string value contains a dialect namespace prefix (e.g.