MLIR  22.0.0git
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
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. 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...
 
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 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
 

Detailed Description

Definition at line 188 of file IRModule.h.

Constructor & Destructor Documentation

◆ PyMlirContext() [1/4]

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

Referenced by forContext().

◆ PyMlirContext() [2/4]

PyMlirContext::PyMlirContext ( MlirContext  context)

Definition at line 651 of file IRCore.cpp.

◆ PyMlirContext() [3/4]

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

◆ PyMlirContext() [4/4]

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

◆ ~PyMlirContext()

PyMlirContext::~PyMlirContext ( )

Definition at line 658 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 721 of file IRCore.cpp.

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

◆ contextEnter()

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

Enter and exit the context manager.

Definition at line 711 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 715 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 674 of file IRCore.cpp.

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

◆ forContext()

PyMlirContextRef PyMlirContext::forContext ( MlirContext  context)
static

◆ get()

MlirContext mlir::python::PyMlirContext::get ( )
inline

◆ getCapsule()

nb::object PyMlirContext::getCapsule ( )

Gets a capsule wrapping the void* within the MlirContext.

Definition at line 670 of file IRCore.cpp.

References get(), and mlirPythonContextToCapsule().

◆ getLiveCount()

size_t PyMlirContext::getLiveCount ( )
static

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

Definition at line 706 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 205 of file IRModule.h.

◆ 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 233 of file IRModule.h.

Friends And Related Function Documentation

◆ PyModule

friend class PyModule
friend

Definition at line 250 of file IRModule.h.

◆ PyOperation

friend class PyOperation
friend

Definition at line 251 of file IRModule.h.


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