MLIR  19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
mlir::python::PyGlobals Class Reference

Globals that are always accessible once the extension has been initialized. More...

#include "Bindings/Python/Globals.h"

Public Member Functions

 PyGlobals ()
 
 ~PyGlobals ()
 
std::vector< std::string > & getDialectSearchPrefixes ()
 Get and set the list of parent modules to search for dialect implementation classes. More...
 
void setDialectSearchPrefixes (std::vector< std::string > newValues)
 
bool loadDialectModule (llvm::StringRef dialectNamespace)
 Loads a python module corresponding to the given dialect namespace. More...
 
void registerAttributeBuilder (const std::string &attributeKind, pybind11::function pyFunc, bool replace=false)
 Adds a user-friendly Attribute builder. More...
 
void registerTypeCaster (MlirTypeID mlirTypeID, pybind11::function typeCaster, bool replace=false)
 Adds a user-friendly type caster. More...
 
void registerValueCaster (MlirTypeID mlirTypeID, pybind11::function valueCaster, bool replace=false)
 Adds a user-friendly value caster. More...
 
void registerDialectImpl (const std::string &dialectNamespace, pybind11::object pyClass)
 Adds a concrete implementation dialect class. More...
 
void registerOperationImpl (const std::string &operationName, pybind11::object pyClass, bool replace=false)
 Adds a concrete implementation operation class. More...
 
std::optional< pybind11::function > lookupAttributeBuilder (const std::string &attributeKind)
 Returns the custom Attribute builder for Attribute kind. More...
 
std::optional< pybind11::function > lookupTypeCaster (MlirTypeID mlirTypeID, MlirDialect dialect)
 Returns the custom type caster for MlirTypeID mlirTypeID. More...
 
std::optional< pybind11::function > lookupValueCaster (MlirTypeID mlirTypeID, MlirDialect dialect)
 Returns the custom value caster for MlirTypeID mlirTypeID. More...
 
std::optional< pybind11::object > lookupDialectClass (const std::string &dialectNamespace)
 Looks up a registered dialect class by namespace. More...
 
std::optional< pybind11::object > lookupOperationClass (llvm::StringRef operationName)
 Looks up a registered operation class (deriving from OpView) by operation name. More...
 

Static Public Member Functions

static PyGlobalsget ()
 Most code should get the globals via this static accessor. More...
 

Detailed Description

Globals that are always accessible once the extension has been initialized.

Definition at line 28 of file Globals.h.

Constructor & Destructor Documentation

◆ PyGlobals()

PyGlobals::PyGlobals ( )

Definition at line 29 of file IRModule.cpp.

References MAKE_MLIR_PYTHON_QUALNAME.

◆ ~PyGlobals()

PyGlobals::~PyGlobals ( )

Definition at line 37 of file IRModule.cpp.

Member Function Documentation

◆ get()

static PyGlobals& mlir::python::PyGlobals::get ( )
inlinestatic

◆ getDialectSearchPrefixes()

std::vector<std::string>& mlir::python::PyGlobals::getDialectSearchPrefixes ( )
inline

Get and set the list of parent modules to search for dialect implementation classes.

Definition at line 41 of file Globals.h.

◆ loadDialectModule()

bool PyGlobals::loadDialectModule ( llvm::StringRef  dialectNamespace)

Loads a python module corresponding to the given dialect namespace.

No-ops if the module has already been loaded or is not found. Raises an error on any evaluation issues. Note that this returns void because it is expected that the module contains calls to decorators and helpers that register the salient entities. Returns true if dialect is successfully loaded.

Definition at line 39 of file IRModule.cpp.

Referenced by lookupDialectClass(), lookupOperationClass(), lookupTypeCaster(), and lookupValueCaster().

◆ lookupAttributeBuilder()

std::optional< py::function > PyGlobals::lookupAttributeBuilder ( const std::string &  attributeKind)

Returns the custom Attribute builder for Attribute kind.

Definition at line 124 of file IRModule.cpp.

◆ lookupDialectClass()

std::optional< py::object > PyGlobals::lookupDialectClass ( const std::string &  dialectNamespace)

Looks up a registered dialect class by namespace.

Note that this may trigger loading of the defining module and can arbitrarily re-enter.

Definition at line 158 of file IRModule.cpp.

References loadDialectModule().

◆ lookupOperationClass()

std::optional< pybind11::object > PyGlobals::lookupOperationClass ( llvm::StringRef  operationName)

Looks up a registered operation class (deriving from OpView) by operation name.

Note that this may trigger a load of the dialect, which can arbitrarily re-enter.

Definition at line 172 of file IRModule.cpp.

References loadDialectModule().

Referenced by mlir::python::PyOperation::createOpView().

◆ lookupTypeCaster()

std::optional< py::function > PyGlobals::lookupTypeCaster ( MlirTypeID  mlirTypeID,
MlirDialect  dialect 
)

Returns the custom type caster for MlirTypeID mlirTypeID.

Definition at line 133 of file IRModule.cpp.

References loadDialectModule(), mlirDialectGetNamespace(), and unwrap().

◆ lookupValueCaster()

std::optional< py::function > PyGlobals::lookupValueCaster ( MlirTypeID  mlirTypeID,
MlirDialect  dialect 
)

Returns the custom value caster for MlirTypeID mlirTypeID.

Definition at line 145 of file IRModule.cpp.

References loadDialectModule(), mlirDialectGetNamespace(), and unwrap().

Referenced by mlir::python::PyValue::maybeDownCast().

◆ registerAttributeBuilder()

void PyGlobals::registerAttributeBuilder ( const std::string &  attributeKind,
pybind11::function  pyFunc,
bool  replace = false 
)

Adds a user-friendly Attribute builder.

Raises an exception if the mapping already exists and replace == false. This is intended to be called by implementation code.

Definition at line 68 of file IRModule.cpp.

◆ registerDialectImpl()

void PyGlobals::registerDialectImpl ( const std::string &  dialectNamespace,
pybind11::object  pyClass 
)

Adds a concrete implementation dialect class.

Raises an exception if the mapping already exists. This is intended to be called by implementation code.

Definition at line 101 of file IRModule.cpp.

◆ registerOperationImpl()

void PyGlobals::registerOperationImpl ( const std::string &  operationName,
pybind11::object  pyClass,
bool  replace = false 
)

Adds a concrete implementation operation class.

Raises an exception if the mapping already exists and replace == false. This is intended to be called by implementation code.

Definition at line 112 of file IRModule.cpp.

◆ registerTypeCaster()

void PyGlobals::registerTypeCaster ( MlirTypeID  mlirTypeID,
pybind11::function  typeCaster,
bool  replace = false 
)

Adds a user-friendly type caster.

Raises an exception if the mapping already exists and replace == false. This is intended to be called by implementation code.

Definition at line 81 of file IRModule.cpp.

Referenced by mlir::python::PyConcreteType< DerivedTy, BaseTy >::bind(), and mlir::python::PyConcreteAttribute< DerivedTy, BaseTy >::bind().

◆ registerValueCaster()

void PyGlobals::registerValueCaster ( MlirTypeID  mlirTypeID,
pybind11::function  valueCaster,
bool  replace = false 
)

Adds a user-friendly value caster.

Raises an exception if the mapping already exists and replace == false. This is intended to be called by implementation code.

Definition at line 91 of file IRModule.cpp.

◆ setDialectSearchPrefixes()

void mlir::python::PyGlobals::setDialectSearchPrefixes ( std::vector< std::string >  newValues)
inline

Definition at line 44 of file Globals.h.


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