MLIR  14.0.0git
Public Types | Public Member Functions | List of all members
mlir::MLIRContext Class Reference

MLIRContext is the top-level object for a collection of MLIR operations. More...

#include "mlir/IR/MLIRContext.h"

Public Types

enum  Threading { Threading::DISABLED, Threading::ENABLED }
 

Public Member Functions

 MLIRContext (Threading multithreading=Threading::ENABLED)
 Create a new Context. More...
 
 MLIRContext (const DialectRegistry &registry, Threading multithreading=Threading::ENABLED)
 
 ~MLIRContext ()
 
std::vector< Dialect * > getLoadedDialects ()
 Return information about all IR dialects loaded in the context. More...
 
const DialectRegistrygetDialectRegistry ()
 Return the dialect registry associated with this context. More...
 
void appendDialectRegistry (const DialectRegistry &registry)
 Append the contents of the given dialect registry to the registry associated with this context. More...
 
std::vector< StringRef > getAvailableDialects ()
 Return information about all available dialects in the registry in this context. More...
 
DialectgetLoadedDialect (StringRef name)
 Get a registered IR dialect with the given namespace. More...
 
template<typename T >
T * getLoadedDialect ()
 Get a registered IR dialect for the given derived dialect type. More...
 
template<typename T >
T * getOrLoadDialect ()
 Get (or create) a dialect for the given derived dialect type. More...
 
template<typename Dialect >
void loadDialect ()
 Load a dialect in the context. More...
 
template<typename Dialect , typename OtherDialect , typename... MoreDialects>
void loadDialect ()
 Load a list dialects in the context. More...
 
void loadAllAvailableDialects ()
 Load all dialects available in the registry in this context. More...
 
DialectgetOrLoadDialect (StringRef name)
 Get (or create) a dialect for the given derived dialect name. More...
 
bool allowsUnregisteredDialects ()
 Return true if we allow to create operation for unregistered dialects. More...
 
void allowUnregisteredDialects (bool allow=true)
 Enables creating operations in unregistered dialects. More...
 
bool isMultithreadingEnabled ()
 Return true if multi-threading is enabled by the context. More...
 
void disableMultithreading (bool disable=true)
 Set the flag specifying if multi-threading is disabled by the context. More...
 
void enableMultithreading (bool enable=true)
 
void setThreadPool (llvm::ThreadPool &pool)
 Set a new thread pool to be used in this context. More...
 
llvm::ThreadPool & getThreadPool ()
 Return the thread pool used by this context. More...
 
bool shouldPrintOpOnDiagnostic ()
 Return true if we should attach the operation to diagnostics emitted via Operation::emit. More...
 
void printOpOnDiagnostic (bool enable)
 Set the flag specifying if we should attach the operation to diagnostics emitted via Operation::emit. More...
 
bool shouldPrintStackTraceOnDiagnostic ()
 Return true if we should attach the current stacktrace to diagnostics when emitted. More...
 
void printStackTraceOnDiagnostic (bool enable)
 Set the flag specifying if we should attach the current stacktrace when emitting diagnostics. More...
 
std::vector< RegisteredOperationNamegetRegisteredOperations ()
 Return information about all registered operations. More...
 
bool isOperationRegistered (StringRef name)
 Return true if this operation name is registered in this context. More...
 
MLIRContextImplgetImpl ()
 
DiagnosticEnginegetDiagEngine ()
 Returns the diagnostic engine for this context. More...
 
StorageUniquergetAffineUniquer ()
 Returns the storage uniquer used for creating affine constructs. More...
 
StorageUniquergetTypeUniquer ()
 Returns the storage uniquer used for constructing type storage instances. More...
 
StorageUniquergetAttributeUniquer ()
 Returns the storage uniquer used for constructing attribute storage instances. More...
 
DebugActionManagergetDebugActionManager ()
 Returns the manager of debug actions within the context. More...
 
void enterMultiThreadedExecution ()
 These APIs are tracking whether the context will be used in a multithreading environment: this has no effect other than enabling assertions on misuses of some APIs. More...
 
void exitMultiThreadedExecution ()
 
DialectgetOrLoadDialect (StringRef dialectNamespace, TypeID dialectID, function_ref< std::unique_ptr< Dialect >()> ctor)
 Get a dialect for the provided namespace and TypeID: abort the program if a dialect exist for this namespace with different TypeID. More...
 
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 state of the context registry has changed. More...
 

Detailed Description

MLIRContext is the top-level object for a collection of MLIR operations.

It holds immortal uniqued objects like types, and the tables used to unique them.

MLIRContext gets a redundant "MLIR" prefix because otherwise it ends up with a very generic name ("Context") and because it is uncommon for clients to interact with it.

The context wrap some multi-threading facilities, and in particular by default it will implicitly create a thread pool. This can be undesirable if multiple context exists at the same time or if a process will be long-lived and create and destroy contexts. To control better thread spawning, an externally owned ThreadPool can be injected in the context. For example:

llvm::ThreadPool myThreadPool; while (auto *request = nextCompilationRequests()) { MLIRContext ctx(registry, MLIRContext::Threading::DISABLED); ctx.setThreadPool(myThreadPool); processRequest(request, cxt); }

Definition at line 55 of file MLIRContext.h.

Member Enumeration Documentation

◆ Threading

Enumerator
DISABLED 
ENABLED 

Definition at line 57 of file MLIRContext.h.

Constructor & Destructor Documentation

◆ MLIRContext() [1/2]

MLIRContext::MLIRContext ( Threading  multithreading = Threading::ENABLED)
explicit

Create a new Context.

Definition at line 352 of file MLIRContext.cpp.

◆ MLIRContext() [2/2]

MLIRContext::MLIRContext ( const DialectRegistry registry,
Threading  multithreading = Threading::ENABLED 
)
explicit

Types. Floating-point Types.

Index Type.

Integer Types.

None Type.

of the above types internally. Unknown Location Attribute.

Bool Attributes.

Unit Attribute.

The empty dictionary attribute.

The empty string attribute.

Definition at line 355 of file MLIRContext.cpp.

References mlir::DialectRegistry::appendTo(), clOptions, printOpOnDiagnostic(), and printStackTraceOnDiagnostic().

◆ ~MLIRContext()

MLIRContext::~MLIRContext ( )

Definition at line 420 of file MLIRContext.cpp.

Member Function Documentation

◆ allowsUnregisteredDialects()

bool MLIRContext::allowsUnregisteredDialects ( )

Return true if we allow to create operation for unregistered dialects.

Definition at line 561 of file MLIRContext.cpp.

Referenced by mlir::BoolAttr::classof(), and iterateIndicesExcept().

◆ allowUnregisteredDialects()

void MLIRContext::allowUnregisteredDialects ( bool  allow = true)

Enables creating operations in unregistered dialects.

Definition at line 565 of file MLIRContext.cpp.

Referenced by getLspDiagnoticFromDiag(), and processBuffer().

◆ appendDialectRegistry()

void MLIRContext::appendDialectRegistry ( const DialectRegistry registry)

◆ disableMultithreading()

void MLIRContext::disableMultithreading ( bool  disable = true)

Set the flag specifying if multi-threading is disabled by the context.

The command line debugging flag --mlir-disable-threading is overriding this call and making it a no-op!

Definition at line 575 of file MLIRContext.cpp.

References isThreadingGloballyDisabled().

Referenced by performActions().

◆ enableMultithreading()

void mlir::MLIRContext::enableMultithreading ( bool  enable = true)
inline

Definition at line 135 of file MLIRContext.h.

Referenced by performActions(), and setThreadPool().

◆ enterMultiThreadedExecution()

void MLIRContext::enterMultiThreadedExecution ( )

These APIs are tracking whether the context will be used in a multithreading environment: this has no effect other than enabling assertions on misuses of some APIs.

Definition at line 623 of file MLIRContext.cpp.

Referenced by mlir::PassManager::run().

◆ exitMultiThreadedExecution()

void MLIRContext::exitMultiThreadedExecution ( )

Definition at line 628 of file MLIRContext.cpp.

Referenced by mlir::PassManager::run().

◆ getAffineUniquer()

StorageUniquer & MLIRContext::getAffineUniquer ( )

◆ getAttributeUniquer()

StorageUniquer & MLIRContext::getAttributeUniquer ( )

◆ getAvailableDialects()

std::vector< StringRef > MLIRContext::getAvailableDialects ( )

Return information about all available dialects in the registry in this context.

Definition at line 475 of file MLIRContext.cpp.

Referenced by loadAllAvailableDialects().

◆ getDebugActionManager()

DebugActionManager & MLIRContext::getDebugActionManager ( )

Returns the manager of debug actions within the context.

Definition at line 436 of file MLIRContext.cpp.

References mlir::MLIRContextImpl::debugActionManager, and getImpl().

Referenced by processBuffer().

◆ getDiagEngine()

DiagnosticEngine & MLIRContext::getDiagEngine ( )

Returns the diagnostic engine for this context.

Definition at line 445 of file MLIRContext.cpp.

References mlir::MLIRContextImpl::diagEngine, and getImpl().

Referenced by emitDiag(), and mlir::detail::ParallelDiagnosticHandlerImpl::ParallelDiagnosticHandlerImpl().

◆ getDialectRegistry()

const DialectRegistry & MLIRContext::getDialectRegistry ( )

Return the dialect registry associated with this context.

Definition at line 459 of file MLIRContext.cpp.

Referenced by roundTripModule().

◆ getImpl()

MLIRContextImpl& mlir::MLIRContext::getImpl ( )
inline

◆ getLoadedDialect() [1/2]

Dialect * MLIRContext::getLoadedDialect ( StringRef  name)

Get a registered IR dialect with the given namespace.

If an exact match is not found, then return nullptr.

If none is found, then return nullptr.

Definition at line 484 of file MLIRContext.cpp.

Referenced by mlir::BoolAttr::classof(), combineOneSpec(), mlir::detail::StringAttrStorage::initialize(), and iterateIndicesExcept().

◆ getLoadedDialect() [2/2]

template<typename T >
T* mlir::MLIRContext::getLoadedDialect ( )
inline

Get a registered IR dialect for the given derived dialect type.

The derived type must provide a static 'getDialectNamespace' method.

Definition at line 85 of file MLIRContext.h.

Referenced by getOrLoadDialect().

◆ getLoadedDialects()

std::vector< Dialect * > MLIRContext::getLoadedDialects ( )

Return information about all IR dialects loaded in the context.

Return information about all registered IR dialects.

Definition at line 464 of file MLIRContext.cpp.

Referenced by mlir::detail::DialectInterfaceCollectionBase::DialectInterfaceCollectionBase().

◆ getOrLoadDialect() [1/3]

template<typename T >
T* mlir::MLIRContext::getOrLoadDialect ( )
inline

Get (or create) a dialect for the given derived dialect type.

The derived type must provide a static 'getDialectNamespace' method.

Definition at line 92 of file MLIRContext.h.

Referenced by mlir::DialectRegistry::insert(), loadAllAvailableDialects(), mlir::detail::Parser::parseAttributeDict(), mlir::detail::Parser::parseExtendedAttr(), prepareLLVMModule(), and mlir::PassManager::run().

◆ getOrLoadDialect() [2/3]

Dialect * MLIRContext::getOrLoadDialect ( StringRef  name)

Get (or create) a dialect for the given derived dialect name.

The dialect will be loaded from the registry if no dialect is found. If no dialect is loaded for this name and none is available in the registry, returns nullptr.

Definition at line 490 of file MLIRContext.cpp.

References getLoadedDialect().

◆ getOrLoadDialect() [3/3]

Dialect * MLIRContext::getOrLoadDialect ( StringRef  dialectNamespace,
TypeID  dialectID,
function_ref< std::unique_ptr< Dialect >()>  ctor 
)

Get a dialect for the provided namespace and TypeID: abort the program if a dialect exist for this namespace with different TypeID.

If a dialect has not been loaded for this namespace/TypeID yet, use the provided ctor to create one on the fly and load it. Returns a pointer to the dialect owned by the context. The use of this method is in general discouraged in favor of 'getOrLoadDialect<DialectClass>()'.

Returns a pointer to the dialect owned by the context.

Definition at line 503 of file MLIRContext.cpp.

References getImpl(), and mlir::detail::StringAttrStorage::referencedDialect.

◆ getRegisteredOperations()

std::vector< RegisteredOperationName > MLIRContext::getRegisteredOperations ( )

Return information about all registered operations.

This isn't very efficient: typically you should ask the operations about their properties directly.

This isn't very efficient, typically you should ask the operations about their properties directly.

Definition at line 661 of file MLIRContext.cpp.

◆ getRegistryHash()

llvm::hash_code MLIRContext::getRegistryHash ( )

Returns a hash of the registry of the context that may be used to give a rough indicator of if the state of the context registry has changed.

The context registry correlates to loaded dialects and their entities (attributes, operations, types, etc.).

Definition at line 551 of file MLIRContext.cpp.

Referenced by mlir::PassManager::run().

◆ getThreadPool()

llvm::ThreadPool & MLIRContext::getThreadPool ( )

Return the thread pool used by this context.

This method requires that multithreading be enabled within the context, and should generally not be used directly. Users should instead prefer the threading utilities within Threading.h.

Definition at line 615 of file MLIRContext.cpp.

References isMultithreadingEnabled().

Referenced by mlir::failableParallelForEach().

◆ getTypeUniquer()

StorageUniquer & MLIRContext::getTypeUniquer ( )

◆ isMultithreadingEnabled()

bool MLIRContext::isMultithreadingEnabled ( )

◆ isOperationRegistered()

bool MLIRContext::isOperationRegistered ( StringRef  name)

Return true if this operation name is registered in this context.

Definition at line 677 of file MLIRContext.cpp.

References mlir::OperationName::isRegistered().

◆ loadAllAvailableDialects()

void MLIRContext::loadAllAvailableDialects ( )

Load all dialects available in the registry in this context.

Definition at line 546 of file MLIRContext.cpp.

References getAvailableDialects(), and getOrLoadDialect().

Referenced by processBuffer(), and roundTripModule().

◆ loadDialect() [1/2]

template<typename Dialect >
void mlir::MLIRContext::loadDialect ( )
inline

Load a dialect in the context.

Definition at line 102 of file MLIRContext.h.

Referenced by deserializeModule(), and mlir::translateLLVMIRToModule().

◆ loadDialect() [2/2]

template<typename Dialect , typename OtherDialect , typename... MoreDialects>
void mlir::MLIRContext::loadDialect ( )
inline

Load a list dialects in the context.

Definition at line 108 of file MLIRContext.h.

◆ printOpOnDiagnostic()

void MLIRContext::printOpOnDiagnostic ( bool  enable)

Set the flag specifying if we should attach the operation to diagnostics emitted via Operation::emit.

Definition at line 642 of file MLIRContext.cpp.

Referenced by MLIRContext(), mlir::mlirTranslateMain(), and processBuffer().

◆ printStackTraceOnDiagnostic()

void MLIRContext::printStackTraceOnDiagnostic ( bool  enable)

Set the flag specifying if we should attach the current stacktrace when emitting diagnostics.

Definition at line 654 of file MLIRContext.cpp.

Referenced by MLIRContext().

◆ setThreadPool()

void MLIRContext::setThreadPool ( llvm::ThreadPool &  pool)

Set a new thread pool to be used in this context.

This method requires that multithreading is disabled for this context prior to the call. This allows to share a thread pool across multiple contexts, as well as decoupling the lifetime of the threads from the contexts. The thread pool must outlive the context. Multi-threading will be enabled as part of this method. The command line debugging flag --mlir-disable-threading will still prevent threading from being enabled and threading won't be enabled after this call in this case.

Definition at line 607 of file MLIRContext.cpp.

References enableMultithreading(), and isMultithreadingEnabled().

Referenced by processBuffer().

◆ shouldPrintOpOnDiagnostic()

bool MLIRContext::shouldPrintOpOnDiagnostic ( )

Return true if we should attach the operation to diagnostics emitted via Operation::emit.

Definition at line 636 of file MLIRContext.cpp.

◆ shouldPrintStackTraceOnDiagnostic()

bool MLIRContext::shouldPrintStackTraceOnDiagnostic ( )

Return true if we should attach the current stacktrace to diagnostics when emitted.

Definition at line 648 of file MLIRContext.cpp.

Referenced by emitDiag().


The documentation for this class was generated from the following files: