MLIR 22.0.0git
mlir::python::PyMlirContext Class Reference

#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.
PyMlirContextRef getRef ()
 Gets a strong reference to this context, which will ensure it is kept alive for the life of the reference.
nanobind::object getCapsule ()
 Gets a capsule wrapping the void* within the MlirContext.
size_t getLiveModuleCount ()
 Gets the count of live modules associated with this context.
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).
void setEmitErrorDiagnostics (bool value)
 Controls whether error diagnostics should be propagated to diagnostic handlers, instead of being captured by ErrorCapture.
bool getEmitErrorDiagnostics ()

Static Public Member Functions

static PyMlirContextRef forContext (MlirContext context)
 Returns a context reference for the singleton PyMlirContext wrapper for the given context.
static nanobind::object createFromCapsule (nanobind::object capsule)
 Creates a PyMlirContext from the MlirContext wrapped by a capsule.
static size_t getLiveCount ()
 Gets the count of live context objects. Used for testing.
static nanobind::object contextEnter (nanobind::object context)
 Enter and exit the context manager.

Friends

class PyModule
class PyOperation

Detailed Description

Definition at line 191 of file IRModule.h.

Constructor & Destructor Documentation

◆ PyMlirContext() [1/4]

mlir::python::PyMlirContext::PyMlirContext ( )
delete

◆ PyMlirContext() [2/4]

PyMlirContext::PyMlirContext ( MlirContext context)

Definition at line 537 of file IRCore.cpp.

◆ PyMlirContext() [3/4]

mlir::python::PyMlirContext::PyMlirContext ( const PyMlirContext & )
delete

References PyMlirContext().

◆ PyMlirContext() [4/4]

mlir::python::PyMlirContext::PyMlirContext ( PyMlirContext && )
delete

References PyMlirContext().

◆ ~PyMlirContext()

PyMlirContext::~PyMlirContext ( )

Definition at line 544 of file IRCore.cpp.

References mlirContextDestroy().

Member Function Documentation

◆ attachDiagnosticHandler()

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 607 of file IRCore.cpp.

References get(), mlir::python::PyDiagnostic::invalidate(), mlirContextAttachDiagnosticHandler(), mlirLogicalResultFailure(), mlirLogicalResultSuccess(), and result.

◆ contextEnter()

nb::object PyMlirContext::contextEnter ( nanobind::object context)
static

Enter and exit the context manager.

Definition at line 597 of file IRCore.cpp.

References mlir::python::PyThreadContextEntry::pushContext().

◆ contextExit()

void PyMlirContext::contextExit ( const nanobind::object & excType,
const nanobind::object & excVal,
const nanobind::object & excTb )

Definition at line 601 of file IRCore.cpp.

References mlir::python::PyThreadContextEntry::popContext().

◆ createFromCapsule()

nb::object PyMlirContext::createFromCapsule ( nanobind::object capsule)
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 560 of file IRCore.cpp.

References forContext(), mlirContextIsNull(), mlirPythonCapsuleToContext(), and mlir::python::PyObjectRef< T >::releaseObject().

◆ forContext()

◆ get()

◆ getCapsule()

nb::object PyMlirContext::getCapsule ( )

Gets a capsule wrapping the void* within the MlirContext.

Definition at line 556 of file IRCore.cpp.

References get(), and mlirPythonContextToCapsule().

◆ getEmitErrorDiagnostics()

bool mlir::python::PyMlirContext::getEmitErrorDiagnostics ( )
inline

Definition at line 241 of file IRModule.h.

◆ getLiveCount()

size_t PyMlirContext::getLiveCount ( )
static

Gets the count of live context objects. Used for testing.

Definition at line 592 of file IRCore.cpp.

◆ getLiveModuleCount()

size_t PyMlirContext::getLiveModuleCount ( )

Gets the count of live modules associated with this context.

Used for testing.

Definition at line 2007 of file IRCore.cpp.

◆ getRef()

PyMlirContextRef mlir::python::PyMlirContext::getRef ( )
inline

Gets a strong reference to this context, which will ensure it is kept alive for the life of the reference.

Definition at line 208 of file IRModule.h.

Referenced by getValueTypes().

◆ setEmitErrorDiagnostics()

void mlir::python::PyMlirContext::setEmitErrorDiagnostics ( bool value)
inline

Controls whether error diagnostics should be propagated to diagnostic handlers, instead of being captured by ErrorCapture.

Definition at line 240 of file IRModule.h.

◆ PyModule

friend class PyModule
friend

Definition at line 266 of file IRModule.h.

References PyModule.

Referenced by PyModule.

◆ PyOperation

friend class PyOperation
friend

Definition at line 267 of file IRModule.h.

References PyOperation.

Referenced by PyOperation.


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