MLIR
20.0.0git
|
#include "Bindings/Python/IRModule.h"
Classes | |
struct | ErrorCapture |
RAII object that captures any error diagnostics emitted to the provided context. More... | |
Public Member Functions | |
PyMlirContext ()=delete | |
PyMlirContext (MlirContext context) | |
PyMlirContext (const PyMlirContext &)=delete | |
PyMlirContext (PyMlirContext &&)=delete | |
~PyMlirContext () | |
MlirContext | get () |
Accesses the underlying MlirContext. More... | |
PyMlirContextRef | getRef () |
Gets a strong reference to this context, which will ensure it is kept alive for the life of the reference. More... | |
nanobind::object | getCapsule () |
Gets a capsule wrapping the void* within the MlirContext. More... | |
std::vector< PyOperation * > | getLiveOperationObjects () |
Get a list of Python objects which are still in the live context map. More... | |
size_t | getLiveOperationCount () |
Gets the count of live operations associated with this context. More... | |
size_t | clearLiveOperations () |
Clears the live operations map, returning the number of entries which were invalidated. More... | |
void | clearOperation (MlirOperation op) |
Removes an operation from the live operations map and sets it invalid. More... | |
void | clearOperationsInside (PyOperationBase &op) |
Clears all operations nested inside the given op using clearOperation(MlirOperation) . More... | |
void | clearOperationsInside (MlirOperation op) |
void | clearOperationAndInside (PyOperationBase &op) |
Clears the operaiton and all operations inside using clearOperation(MlirOperation) . More... | |
size_t | getLiveModuleCount () |
Gets the count of live modules associated with this context. More... | |
void | contextExit (const nanobind::object &excType, const nanobind::object &excVal, const nanobind::object &excTb) |
nanobind::object | attachDiagnosticHandler (nanobind::object callback) |
Attaches a Python callback as a diagnostic handler, returning a registration object (internally a PyDiagnosticHandler). More... | |
void | setEmitErrorDiagnostics (bool value) |
Controls whether error diagnostics should be propagated to diagnostic handlers, instead of being captured by ErrorCapture . More... | |
Static Public Member Functions | |
static PyMlirContext * | createNewContextForInit () |
For the case of a python init (nanobind::init) method, pybind11 is quite strict about needing to return a pointer that is not yet associated to an nanobind::object. More... | |
static PyMlirContextRef | forContext (MlirContext context) |
Returns a context reference for the singleton PyMlirContext wrapper for the given context. More... | |
static nanobind::object | createFromCapsule (nanobind::object capsule) |
Creates a PyMlirContext from the MlirContext wrapped by a capsule. More... | |
static size_t | getLiveCount () |
Gets the count of live context objects. Used for testing. More... | |
static nanobind::object | contextEnter (nanobind::object context) |
Enter and exit the context manager. More... | |
Friends | |
class | PyModule |
class | PyOperation |
Definition at line 163 of file IRModule.h.
|
delete |
Referenced by forContext().
PyMlirContext::PyMlirContext | ( | MlirContext | context | ) |
Definition at line 607 of file IRCore.cpp.
|
delete |
|
delete |
PyMlirContext::~PyMlirContext | ( | ) |
Definition at line 613 of file IRCore.cpp.
References mlirContextDestroy().
nb::object PyMlirContext::attachDiagnosticHandler | ( | nanobind::object | callback | ) |
Attaches a Python callback as a diagnostic handler, returning a registration object (internally a PyDiagnosticHandler).
Definition at line 730 of file IRCore.cpp.
References get(), mlir::python::PyDiagnostic::invalidate(), mlirContextAttachDiagnosticHandler(), mlirLogicalResultFailure(), and mlirLogicalResultSuccess().
size_t PyMlirContext::clearLiveOperations | ( | ) |
Clears the live operations map, returning the number of entries which were invalidated.
To be used as a safety mechanism so that API end-users can't corrupt by holding references they shouldn't have accessed in the first place.
Definition at line 666 of file IRCore.cpp.
void PyMlirContext::clearOperation | ( | MlirOperation | op | ) |
Removes an operation from the live operations map and sets it invalid.
This is useful for when some non-bindings code destroys the operation and the bindings need to made aware. For example, in the case when pass manager is run.
Note that this does NOT clear the nested operations.
Definition at line 674 of file IRCore.cpp.
Referenced by clearOperationAndInside(), and mlir::python::PyOperation::~PyOperation().
void PyMlirContext::clearOperationAndInside | ( | PyOperationBase & | op | ) |
Clears the operaiton and all operations inside using clearOperation(MlirOperation)
.
Definition at line 707 of file IRCore.cpp.
References clearOperation(), mlir::python::BaseContextObject::getContext(), mlir::python::PyOperationBase::getOperation(), mlirOperationWalk(), MlirWalkPreOrder, and MlirWalkResultAdvance.
Referenced by mlir::python::PyOperation::erase().
void PyMlirContext::clearOperationsInside | ( | MlirOperation | op | ) |
Definition at line 702 of file IRCore.cpp.
References clearOperationsInside(), mlir::python::PyOperation::forOperation(), mlir::python::PyOperation::getOperation(), and getRef().
void PyMlirContext::clearOperationsInside | ( | PyOperationBase & | op | ) |
Clears all operations nested inside the given op using clearOperation(MlirOperation)
.
Definition at line 682 of file IRCore.cpp.
References mlir::python::PyOperationBase::getOperation(), mlirOperationWalk(), MlirWalkPreOrder, and MlirWalkResultAdvance.
Referenced by clearOperationsInside().
|
static |
Enter and exit the context manager.
Definition at line 720 of file IRCore.cpp.
References mlir::python::PyThreadContextEntry::pushContext().
void PyMlirContext::contextExit | ( | const nanobind::object & | excType, |
const nanobind::object & | excVal, | ||
const nanobind::object & | excTb | ||
) |
Definition at line 724 of file IRCore.cpp.
References mlir::python::PyThreadContextEntry::popContext().
|
static |
Creates a PyMlirContext from the MlirContext wrapped by a capsule.
Note that PyMlirContext instances are uniqued, so the returned object may be a pre-existing object. Ownership of the underlying MlirContext is taken by calling this function.
Definition at line 626 of file IRCore.cpp.
References forContext(), mlirContextIsNull(), mlirPythonCapsuleToContext(), and mlir::python::PyObjectRef< T >::releaseObject().
|
static |
For the case of a python init (nanobind::init) method, pybind11 is quite strict about needing to return a pointer that is not yet associated to an nanobind::object.
Since the forContext() method acts like a pool, possibly returning a recycled context, it does not satisfy this need. The usual way in python to accomplish such a thing is to override new, but that is also not supported by pybind11. Instead, we use this entry point which always constructs a fresh context (which cannot alias an existing one because it is fresh).
|
static |
Returns a context reference for the singleton PyMlirContext wrapper for the given context.
Definition at line 633 of file IRCore.cpp.
References PyMlirContext().
Referenced by createFromCapsule(), mlir::python::PyLocation::createFromCapsule(), mlir::python::PyOperation::createFromCapsule(), mlir::python::PyType::createFromCapsule(), mlir::python::PyAttribute::createFromCapsule(), mlir::python::PyValue::createFromCapsule(), mlir::python::PyAffineExpr::createFromCapsule(), mlir::python::PyAffineMap::createFromCapsule(), mlir::python::PyIntegerSet::createFromCapsule(), mlir::python::PyModule::forModule(), and mlir::python::PyDiagnostic::getLocation().
|
inline |
Accesses the underlying MlirContext.
Definition at line 186 of file IRModule.h.
Referenced by attachDiagnosticHandler(), mlir::python::PyOpView::buildGeneric(), getCapsule(), mlir::python::PyInferShapedTypeOpInterface::inferReturnTypeComponents(), mlir::python::PyInferTypeOpInterface::inferReturnTypes(), mlir::python::PyOperation::parse(), mlir::python::PyConcreteOpInterface< ConcreteIface >::PyConcreteOpInterface(), mlir::python::PySymbolTable::setSymbolName(), mlir::python::PySymbolTable::setVisibility(), and mlir::python::PyMlirContext::ErrorCapture::~ErrorCapture().
nb::object PyMlirContext::getCapsule | ( | ) |
Gets a capsule wrapping the void* within the MlirContext.
Definition at line 622 of file IRCore.cpp.
References get(), and mlirPythonContextToCapsule().
|
static |
Gets the count of live context objects. Used for testing.
Definition at line 655 of file IRCore.cpp.
size_t PyMlirContext::getLiveModuleCount | ( | ) |
Gets the count of live modules associated with this context.
Used for testing.
Definition at line 718 of file IRCore.cpp.
size_t PyMlirContext::getLiveOperationCount | ( | ) |
Gets the count of live operations associated with this context.
Used for testing.
Definition at line 657 of file IRCore.cpp.
std::vector< PyOperation * > PyMlirContext::getLiveOperationObjects | ( | ) |
Get a list of Python objects which are still in the live context map.
Definition at line 659 of file IRCore.cpp.
|
inline |
Gets a strong reference to this context, which will ensure it is kept alive for the life of the reference.
Definition at line 190 of file IRModule.h.
Referenced by clearOperationsInside().
|
inline |
Controls whether error diagnostics should be propagated to diagnostic handlers, instead of being captured by ErrorCapture
.
Definition at line 252 of file IRModule.h.
Definition at line 284 of file IRModule.h.
|
friend |
Definition at line 285 of file IRModule.h.