14#include "TypeDetail.h" 
   29#include "llvm/ADT/DenseMap.h" 
   30#include "llvm/ADT/Twine.h" 
   31#include "llvm/Support/Allocator.h" 
   32#include "llvm/Support/CommandLine.h" 
   33#include "llvm/Support/Compiler.h" 
   34#include "llvm/Support/DebugLog.h" 
   35#include "llvm/Support/ManagedStatic.h" 
   36#include "llvm/Support/Mutex.h" 
   37#include "llvm/Support/RWMutex.h" 
   38#include "llvm/Support/ThreadPool.h" 
   39#include "llvm/Support/raw_ostream.h" 
   43#define DEBUG_TYPE "mlircontext" 
   56struct MLIRContextOptions {
 
   57  llvm::cl::opt<bool> disableThreading{
 
   58      "mlir-disable-threading",
 
   59      llvm::cl::desc(
"Disable multi-threading within MLIR, overrides any " 
   60                     "further call to MLIRContext::enableMultiThreading()")};
 
   62  llvm::cl::opt<bool> printOpOnDiagnostic{
 
   63      "mlir-print-op-on-diagnostic",
 
   64      llvm::cl::desc(
"When a diagnostic is emitted on an operation, also print " 
   65                     "the operation as an attached note"),
 
   66      llvm::cl::init(
true)};
 
   68  llvm::cl::opt<bool> printStackTraceOnDiagnostic{
 
   69      "mlir-print-stacktrace-on-diagnostic",
 
   70      llvm::cl::desc(
"When a diagnostic is emitted, also print the stack trace " 
   71                     "as an attached note")};
 
   75static llvm::ManagedStatic<MLIRContextOptions> 
clOptions;
 
   78#if LLVM_ENABLE_THREADS != 0 
 
  100struct ScopedWriterLock {
 
  101  ScopedWriterLock(llvm::sys::SmartRWMutex<true> &mutexParam, 
bool shouldLock)
 
  102      : mutex(shouldLock ? &mutexParam : 
nullptr) {
 
  106  ~ScopedWriterLock() {
 
  110  llvm::sys::SmartRWMutex<true> *mutex;
 
  186  llvm::StringMap<std::unique_ptr<OperationName::Impl>> 
operations;
 
  282      typeMapping.second->~AbstractType();
 
  284      attrMapping.second->~AbstractAttribute();
 
 
  297    printOpOnDiagnostic(clOptions->printOpOnDiagnostic);
 
  298    printStackTraceOnDiagnostic(clOptions->printStackTraceOnDiagnostic);
 
  341  impl->falseAttr = IntegerAttr::getBoolAttrUnchecked(
impl->int1Ty, 
false);
 
  342  impl->trueAttr = IntegerAttr::getBoolAttrUnchecked(
impl->int1Ty, 
true);
 
  346  impl->emptyDictionaryAttr = DictionaryAttr::getEmptyUnchecked(
this);
 
  348  impl->emptyStringAttr = StringAttr::getEmptyStringAttrUnchecked(
this);
 
 
  362  impl->remarkEngine.reset();
 
 
  370  auto result = allocator.Allocate<T>(elements.size());
 
  371  llvm::uninitialized_copy(elements, 
result);
 
 
  384void MLIRContext::executeActionInternal(
function_ref<
void()> actionFn,
 
  386  assert(
getImpl().actionHandler);
 
  404    std::unique_ptr<remark::detail::RemarkEngine> engine) {
 
 
  420  assert(
impl->multiThreadedExecutionContext == 0 &&
 
  421         "appending to the MLIRContext dialect registry while in a " 
  422         "multi-threaded execution context");
 
 
  430  return impl->dialectsRegistry;
 
 
  435  std::vector<Dialect *> 
result;
 
  437  for (
auto &dialect : 
impl->loadedDialects)
 
  438    result.push_back(dialect.second.get());
 
  441                         return (*lhs)->getNamespace() < (*rhs)->getNamespace();
 
 
  446  std::vector<StringRef> 
result;
 
  447  for (
auto dialect : 
impl->dialectsRegistry.getDialectNames())
 
  448    result.push_back(dialect);
 
 
  456  auto it = 
impl->loadedDialects.find(name);
 
  457  return (it != 
impl->loadedDialects.end()) ? it->second.get() : 
nullptr;
 
 
  465      impl->dialectsRegistry.getDialectAllocator(name);
 
  466  return allocator ? allocator(
this) : 
nullptr;
 
 
  477  auto dialectIt = 
impl.loadedDialects.try_emplace(dialectNamespace, 
nullptr);
 
  479  if (dialectIt.second) {
 
  480    LDBG() << 
"Load new dialect in Context " << dialectNamespace;
 
  482    if (
impl.multiThreadedExecutionContext != 0)
 
  483      llvm::report_fatal_error(
 
  484          "Loading a dialect (" + dialectNamespace +
 
  485          ") while in a multi-threaded execution context (maybe " 
  486          "the PassManager): this can indicate a " 
  487          "missing `dependentDialects` in a pass for example.");
 
  493    std::unique_ptr<Dialect> &dialectOwned =
 
  494        impl.loadedDialects[dialectNamespace] = ctor();
 
  495    Dialect *dialect = dialectOwned.get();
 
  496    assert(dialect && 
"dialect ctor failed");
 
  501    auto stringAttrsIt = 
impl.dialectReferencingStrAttrs.find(dialectNamespace);
 
  502    if (stringAttrsIt != 
impl.dialectReferencingStrAttrs.end()) {
 
  505      impl.dialectReferencingStrAttrs.erase(stringAttrsIt);
 
  509    impl.dialectsRegistry.applyExtensions(dialect);
 
  514  if (dialectIt.first->second == 
nullptr)
 
  515    llvm::report_fatal_error(
 
  516        "Loading (and getting) a dialect (" + dialectNamespace +
 
  517        ") while the same dialect is still loading: use loadDialect instead " 
  518        "of getOrLoadDialect.");
 
  522  std::unique_ptr<Dialect> &dialect = dialectIt.first->second;
 
  523  if (dialect->getTypeID() != dialectID)
 
  524    llvm::report_fatal_error(
"a dialect with namespace '" + dialectNamespace +
 
  525                             "' has already been registered");
 
  527  return dialect.get();
 
 
  530bool MLIRContext::isDialectLoading(StringRef dialectNamespace) {
 
  540  auto dialectIt = 
impl.loadedDialects.find(dialectNamespace);
 
  542  if (dialectIt != 
impl.loadedDialects.end()) {
 
  543    if (
auto *dynDialect = dyn_cast<DynamicDialect>(dialectIt->second.get()))
 
  545    llvm::report_fatal_error(
"a dialect with namespace '" + dialectNamespace +
 
  546                             "' has already been registered");
 
  549  LDBG() << 
"Load new dynamic dialect in Context " << dialectNamespace;
 
  551  if (
impl.multiThreadedExecutionContext != 0)
 
  552    llvm::report_fatal_error(
 
  553        "Loading a dynamic dialect (" + dialectNamespace +
 
  554        ") while in a multi-threaded execution context (maybe " 
  555        "the PassManager): this can indicate a " 
  556        "missing `dependentDialects` in a pass for example.");
 
  559  auto name = StringAttr::get(
this, dialectNamespace);
 
  563    return std::unique_ptr<DynamicDialect>(dialect);
 
 
  576  llvm::hash_code hash(0);
 
  578  hash = llvm::hash_combine(hash, 
impl->loadedDialects.size());
 
  579  hash = llvm::hash_combine(hash, 
impl->registeredAttributes.size());
 
  580  hash = llvm::hash_combine(hash, 
impl->registeredOperations.size());
 
  581  hash = llvm::hash_combine(hash, 
impl->registeredTypes.size());
 
 
  586  return impl->allowUnregisteredDialects;
 
 
  590  assert(
impl->multiThreadedExecutionContext == 0 &&
 
  591         "changing MLIRContext `allow-unregistered-dialects` configuration " 
  592         "while in a multi-threaded execution context");
 
  593  impl->allowUnregisteredDialects = allowing;
 
 
  598  return impl->threadingIsEnabled && llvm::llvm_is_multithreaded();
 
 
  607  assert(
impl->multiThreadedExecutionContext == 0 &&
 
  608         "changing MLIRContext `disable-threading` configuration while " 
  609         "in a multi-threaded execution context");
 
  611  impl->threadingIsEnabled = !disable;
 
  614  impl->affineUniquer.disableMultithreading(disable);
 
  615  impl->attributeUniquer.disableMultithreading(disable);
 
  616  impl->typeUniquer.disableMultithreading(disable);
 
  624    if (
impl->ownedThreadPool) {
 
  625      assert(
impl->threadPool);
 
  626      impl->threadPool = 
nullptr;
 
  627      impl->ownedThreadPool.reset();
 
  629  } 
else if (!
impl->threadPool) {
 
  631    assert(!
impl->ownedThreadPool);
 
  632    impl->ownedThreadPool = std::make_unique<llvm::DefaultThreadPool>();
 
  633    impl->threadPool = 
impl->ownedThreadPool.get();
 
 
  639         "expected multi-threading to be disabled when setting a ThreadPool");
 
  640  impl->threadPool = &pool;
 
  641  impl->ownedThreadPool.reset();
 
 
  647    assert(
impl->threadPool &&
 
  648           "multi-threading is enabled but threadpool not set");
 
  649    return impl->threadPool->getMaxConcurrency();
 
 
  657         "expected multi-threading to be enabled within the context");
 
  658  assert(
impl->threadPool &&
 
  659         "multi-threading is enabled but threadpool not set");
 
  660  return *
impl->threadPool;
 
 
  665  ++
impl->multiThreadedExecutionContext;
 
 
  670  --
impl->multiThreadedExecutionContext;
 
 
  677  return impl->printOpOnDiagnostic;
 
 
  683  assert(
impl->multiThreadedExecutionContext == 0 &&
 
  684         "changing MLIRContext `print-op-on-diagnostic` configuration while in " 
  685         "a multi-threaded execution context");
 
  686  impl->printOpOnDiagnostic = enable;
 
 
  692  return impl->printStackTraceOnDiagnostic;
 
 
  698  assert(
impl->multiThreadedExecutionContext == 0 &&
 
  699         "changing MLIRContext `print-stacktrace-on-diagnostic` configuration " 
  700         "while in a multi-threaded execution context");
 
  701  impl->printStackTraceOnDiagnostic = enable;
 
 
  706  return impl->sortedRegisteredOperations;
 
 
  712  auto *lowerBound = llvm::lower_bound(
 
  713      impl->sortedRegisteredOperations, dialectName, [](
auto &
lhs, 
auto &
rhs) {
 
  714        return lhs.getDialect().getNamespace().compare(rhs);
 
  717  if (lowerBound == 
impl->sortedRegisteredOperations.end() ||
 
  718      lowerBound->getDialect().getNamespace() != dialectName)
 
  722      std::upper_bound(lowerBound, 
impl->sortedRegisteredOperations.end(),
 
  723                       dialectName, [](
auto &
lhs, 
auto &
rhs) {
 
  724                         return lhs.compare(rhs.getDialect().getNamespace());
 
  727  size_t count = std::distance(lowerBound, upperBound);
 
  728  return ArrayRef(&*lowerBound, count);
 
 
  736  auto &
impl = context->getImpl();
 
  737  assert(
impl.multiThreadedExecutionContext == 0 &&
 
  738         "Registering a new type kind while in a multi-threaded execution " 
  743  if (!
impl.registeredTypes.insert({typeID, newInfo}).second)
 
  744    llvm::report_fatal_error(
"Dialect Type already registered.");
 
  745  if (!
impl.nameToType.insert({newInfo->getName(), newInfo}).second)
 
  746    llvm::report_fatal_error(
"Dialect Type with name " + newInfo->getName() +
 
  747                             " is already registered.");
 
 
  751  auto &
impl = context->getImpl();
 
  752  assert(
impl.multiThreadedExecutionContext == 0 &&
 
  753         "Registering a new attribute kind while in a multi-threaded execution " 
  758  if (!
impl.registeredAttributes.insert({typeID, newInfo}).second)
 
  759    llvm::report_fatal_error(
"Dialect Attribute already registered.");
 
  760  if (!
impl.nameToAttribute.insert({newInfo->getName(), newInfo}).second)
 
  761    llvm::report_fatal_error(
"Dialect Attribute with name " +
 
  762                             newInfo->getName() + 
" is already registered.");
 
 
  772  const AbstractAttribute *abstract = lookupMutable(typeID, context);
 
  774    llvm::report_fatal_error(
"Trying to create an Attribute that was not " 
  775                             "registered in this MLIRContext.");
 
 
  782  return impl.registeredAttributes.lookup(typeID);
 
  785std::optional<std::reference_wrapper<const AbstractAttribute>>
 
  788  const AbstractAttribute *type = 
impl.nameToAttribute.lookup(name);
 
 
 
  805  MLIRContextImpl &ctxImpl = context->
getImpl();
 
  809  if (isMultithreadingEnabled) {
 
  815      impl = registeredIt->second.impl;
 
  822      impl = it->second.get();
 
  830  auto it = ctxImpl.
operations.try_emplace(name);
 
  832    auto nameAttr = StringAttr::get(context, name);
 
  833    it.first->second = std::make_unique<UnregisteredOpModel>(
 
  837  impl = it.first->second.get();
 
 
  842    return dialect->getNamespace();
 
 
  857  llvm::report_fatal_error(
"getParseAssemblyFn hook called on unregistered op");
 
 
  874std::optional<Attribute>
 
  936  return llvm::hash_combine(*prop.
as<
Attribute *>());
 
 
  943std::optional<RegisteredOperationName>
 
  946  auto it = 
impl.registeredOperations.find(typeID);
 
  947  if (it != 
impl.registeredOperations.end())
 
 
  952std::optional<RegisteredOperationName>
 
  955  auto it = 
impl.registeredOperationsByName.find(name);
 
  956  if (it != 
impl.registeredOperationsByName.end())
 
  957    return it->getValue();
 
 
  962    std::unique_ptr<RegisteredOperationName::Impl> ownedImpl,
 
  966  auto &ctxImpl = ctx->
getImpl();
 
  967  assert(ctxImpl.multiThreadedExecutionContext == 0 &&
 
  968         "registering a new operation kind while in a multi-threaded execution " 
  973  if (!attrNames.empty()) {
 
  975        ctxImpl.abstractDialectSymbolAllocator.Allocate<StringAttr>(
 
  978    for (
unsigned i : llvm::seq<unsigned>(0, attrNames.size()))
 
  979      new (&cachedAttrNames[i]) StringAttr(StringAttr::get(ctx, attrNames[i]));
 
  980    impl->attributeNames = cachedAttrNames;
 
  982  StringRef name = 
impl->getName().strref();
 
  984  ctxImpl.operations[name] = std::move(ownedImpl);
 
  987  auto emplaced = ctxImpl.registeredOperations.try_emplace(
 
  989  assert(emplaced.second && 
"operation name registration must be successful");
 
  990  auto emplacedByName = ctxImpl.registeredOperationsByName.try_emplace(
 
  992  (
void)emplacedByName;
 
  993  assert(emplacedByName.second &&
 
  994         "operation name registration must be successful");
 
  998  ctxImpl.sortedRegisteredOperations.
insert(
 
  999      llvm::upper_bound(ctxImpl.sortedRegisteredOperations, value,
 
 1000                        [](
auto &
lhs, 
auto &
rhs) {
 
 1001                          return lhs.getIdentifier().compare(
 
 1002                              rhs.getIdentifier());
 
 1012  const AbstractType *type = lookupMutable(typeID, context);
 
 1014    llvm::report_fatal_error(
 
 1015        "Trying to create a Type that was not registered in this MLIRContext.");
 
 
 1021  return impl.registeredTypes.lookup(typeID);
 
 1024std::optional<std::reference_wrapper<const AbstractType>>
 
 1027  const AbstractType *type = 
impl.nameToType.lookup(name);
 
 1030    return std::nullopt;
 
 
 1042BFloat16Type BFloat16Type::get(
MLIRContext *context) {
 
 1045Float16Type Float16Type::get(
MLIRContext *context) {
 
 1048FloatTF32Type FloatTF32Type::get(MLIRContext *context) {
 
 1051Float32Type Float32Type::get(MLIRContext *context) {
 
 1054Float64Type Float64Type::get(MLIRContext *context) {
 
 1057Float80Type Float80Type::get(MLIRContext *context) {
 
 1060Float128Type Float128Type::get(MLIRContext *context) {
 
 1065IndexType IndexType::get(MLIRContext *context) {
 
 1073                     IntegerType::SignednessSemantics signedness,
 
 1075  if (signedness != IntegerType::Signless)
 
 1076    return IntegerType();
 
 1092    return IntegerType();
 
 
 1096IntegerType IntegerType::get(MLIRContext *context, 
unsigned width,
 
 1097                             IntegerType::SignednessSemantics signedness) {
 
 1100  return Base::get(context, width, signedness);
 
 1105                        MLIRContext *context, 
unsigned width,
 
 1106                        SignednessSemantics signedness) {
 
 1109  return Base::getChecked(
emitError, context, width, signedness);
 
 1113NoneType NoneType::get(MLIRContext *context) {
 
 1118  return Base::get(context);
 
 1128  return getImpl().attributeUniquer;
 
 
 1132void AttributeUniquer::initializeAttributeStorage(
AttributeStorage *storage,
 
 1150DistinctAttrStorage *
 
 1151detail::DistinctAttributeUniquer::allocateStorage(MLIRContext *context,
 
 1152                                                  Attribute referencedAttr) {
 
 1157DictionaryAttr DictionaryAttr::getEmpty(MLIRContext *context) {
 
 1164  auto dialectNamePair = 
value.split(
'.');
 
 1165  if (dialectNamePair.first.empty() || dialectNamePair.second.empty())
 
 1175  llvm::sys::SmartScopedLock<true> lock(
impl.dialectRefStrAttrMutex);
 
 1176  impl.dialectReferencingStrAttrs[dialectNamePair.first].push_back(
this);
 
 
 1189  return getImpl().affineUniquer;
 
 
 1192AffineMap AffineMap::getImpl(
unsigned dimCount, 
unsigned symbolCount,
 
 1198      symbolCount, results);
 
 1207[[maybe_unused]] 
static bool 
 1211  int64_t maxSymbolPosition = -1;
 
 1214  if ((maxDimPosition >= dimCount) || (maxSymbolPosition >= symbolCount)) {
 
 1216        << 
"maximum dimensional identifier position in result expression must " 
 1217           "be less than `dimCount` and maximum symbolic identifier position " 
 1218           "in result expression must be less than `symbolCount`";
 
 
 1225  return getImpl(0, 0, {}, context);
 
 
 1230  return getImpl(dimCount, symbolCount, {}, context);
 
 
 1242  return getImpl(dimCount, symbolCount, results, context);
 
 
 1254  assert(!constraints.empty());
 
 1255  assert(constraints.size() == eqFlags.size());
 
 1257  auto &
impl = constraints[0].getContext()->getImpl();
 
 
 1272  return [ctx] { 
return emitError(UnknownLoc::get(ctx)); };
 
 
 
static llvm::ManagedStatic< DebugCounterOptions > clOptions
 
static 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 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.
 
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: () -> ().
 
constexpr AffineMap()=default
 
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...
 
void addType(TypeID typeID, AbstractType &&typeInfo)
Register a type instance with this dialect.
 
void addAttribute(TypeID typeID, AbstractAttribute &&attrInfo)
Register an attribute instance with this dialect.
 
A dialect that can be defined at runtime.
 
This class represents a diagnostic that is inflight and set to be reported.
 
constexpr IntegerSet()=default
 
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.
 
llvm::ThreadPoolInterface * threadPool
This points to the ThreadPool used when processing MLIR tasks in parallel.
 
DictionaryAttr emptyDictionaryAttr
 
bool printStackTraceOnDiagnostic
If the current stack trace should be attached when emitting diagnostics.
 
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.
 
BFloat16Type bf16Ty
Cached Type Instances.
 
DenseMap< StringRef, SmallVector< StringAttrStorage * > > dialectReferencingStrAttrs
 
llvm::StringMap< RegisteredOperationName > registeredOperationsByName
 
std::atomic< int > multiThreadedExecutionContext
Track if we are currently executing in a threaded execution environment (like the pass-manager): this...
 
StringAttr emptyStringAttr
 
std::function< void(function_ref< void()>, const tracing::Action &)> actionHandler
An action handler for handling actions that are dispatched through this context.
 
bool allowUnregisteredDialects
In most cases, creating operation in unregistered dialect is not desired and indicate a misconfigurat...
 
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
 
bool printOpOnDiagnostic
If the operation should be attached to diagnostics printed via the Operation::emit methods.
 
llvm::BumpPtrAllocator abstractDialectSymbolAllocator
An allocator used for AbstractAttribute and AbstractType objects.
 
DenseMap< TypeID, AbstractType * > registeredTypes
 
StorageUniquer affineUniquer
 
DiagnosticEngine diagEngine
 
std::unique_ptr< remark::detail::RemarkEngine > remarkEngine
 
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.
 
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...
 
DistinctAttributeAllocator distinctAttributeAllocator
A distinct attribute allocator that allocates every time since the address of the distinct attribute ...
 
MLIRContextImpl(bool threadingIsEnabled)
 
StorageUniquer attributeUniquer
 
DialectRegistry dialectsRegistry
 
bool threadingIsEnabled
Enable support for multi-threading within MLIR.
 
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.
 
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
 
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 setRemarkEngine(std::unique_ptr< remark::detail::RemarkEngine > engine)
Set the remark engine for this context.
 
void setThreadPool(llvm::ThreadPoolInterface &pool)
Set a new thread pool to be used in this context.
 
void enableMultithreading(bool enable=true)
 
remark::detail::RemarkEngine * getRemarkEngine()
Returns the remark engine for this context, or nullptr if none has been set.
 
std::vector< Dialect * > getLoadedDialects()
Return information about all IR dialects loaded in the context.
 
ArrayRef< RegisteredOperationName > getRegisteredOperationsByDialect(StringRef dialectName)
Return a sorted array containing the information for registered operations filtered by dialect name.
 
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.
 
std::function< void(function_ref< void()>, const tracing::Action &)> HandlerTy
Signatures for the action handler that can be registered with the context.
 
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.
 
DiagnosticEngine & getDiagEngine()
Returns the diagnostic engine for this context.
 
MLIRContextImpl & getImpl()
 
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.
 
T * getLoadedDialect()
Get a registered IR dialect for the given derived dialect type.
 
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...
 
StringAttr name
The name of the operation.
 
TypeID typeID
The unique identifier of the derived Op class.
 
Impl(StringRef, Dialect *dialect, TypeID typeID, detail::InterfaceMap interfaceMap)
 
Dialect * dialect
The following fields are only populated when the operation is registered.
 
detail::InterfaceMap interfaceMap
A map of interfaces that were registered to this operation.
 
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
 
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.
 
llvm::unique_function< ParseResult(OpAsmParser &, OperationState &)> ParseAssemblyFn
 
MLIRContext * getContext()
Return the context this operation is associated with.
 
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.
 
static TypeID get()
Construct a type info object for the given type T.
 
static T get(MLIRContext *ctx, Args &&...args)
Get an uniqued instance of an attribute T.
 
An allocator for distinct attribute storage instances.
 
DistinctAttrStorage * allocate(Attribute referencedAttr)
 
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...
 
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
 
function_ref< Dialect *(MLIRContext *)> DialectAllocatorFunctionRef
 
llvm::function_ref< Fn > function_ref
 
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.
 
StringRef value
The raw string value.
 
Dialect * referencedDialect
If the string value contains a dialect namespace prefix (e.g.
 
void initialize(MLIRContext *context)
Initialize the storage given an MLIRContext.
 
static T get(MLIRContext *ctx, Args &&...args)
Get an uniqued instance of a type T.