MLIR  20.0.0git
Public Member Functions | Static Public Member Functions | Protected Types | List of all members
mlir::python::PyConcreteOpInterface< ConcreteIface > Class Template Reference

CRTP base class for Python classes representing MLIR Op interfaces. More...

+ Inheritance diagram for mlir::python::PyConcreteOpInterface< ConcreteIface >:

Public Member Functions

 PyConcreteOpInterface (nb::object object, DefaultingPyMlirContext context)
 Constructs an interface instance from an object that is either an operation or a subclass of OpView. More...
 
bool isStatic ()
 Returns true if this object was constructed from a subclass of OpView rather than from an operation instance. More...
 
nb::object getOperationObject ()
 Returns the operation instance from which this object was constructed. More...
 
nb::object getOpView ()
 Returns the opview of the operation instance from which this object was constructed. More...
 
const std::string & getOpName ()
 Returns the canonical name of the operation this interface is constructed from. More...
 

Static Public Member Functions

static void bind (nb::module_ &m)
 Creates the Python bindings for this class in the given module. More...
 
static void bindDerived (ClassTy &cls)
 Hook for derived classes to add class-specific bindings. More...
 

Protected Types

using ClassTy = nb::class_< ConcreteIface >
 
using GetTypeIDFunctionTy = MlirTypeID(*)()
 

Detailed Description

template<typename ConcreteIface>
class mlir::python::PyConcreteOpInterface< ConcreteIface >

CRTP base class for Python classes representing MLIR Op interfaces.

Interface hierarchies are flat so no base class is expected here. The derived class is expected to define the following static fields:

An interface class may be constructed from either an Operation/OpView object or from a subclass of OpView. In the latter case, only the static interface methods are available, similarly to calling ConcereteOp::staticMethod on the C++ side. Implementations of concrete interfaces can use the isStatic method to check whether the interface object was constructed from a class or an operation/opview instance. The getOpName always succeeds and returns a canonical name of the operation suitable for lookups.

Definition at line 144 of file IRInterfaces.cpp.

Member Typedef Documentation

◆ ClassTy

template<typename ConcreteIface >
using mlir::python::PyConcreteOpInterface< ConcreteIface >::ClassTy = nb::class_<ConcreteIface>
protected

Definition at line 146 of file IRInterfaces.cpp.

◆ GetTypeIDFunctionTy

template<typename ConcreteIface >
using mlir::python::PyConcreteOpInterface< ConcreteIface >::GetTypeIDFunctionTy = MlirTypeID (*)()
protected

Definition at line 147 of file IRInterfaces.cpp.

Constructor & Destructor Documentation

◆ PyConcreteOpInterface()

template<typename ConcreteIface >
mlir::python::PyConcreteOpInterface< ConcreteIface >::PyConcreteOpInterface ( nb::object  object,
DefaultingPyMlirContext  context 
)
inline

Constructs an interface instance from an object that is either an operation or a subclass of OpView.

In the latter case, only the static methods of the interface are accessible to the caller.

Definition at line 153 of file IRInterfaces.cpp.

References MlirStringRef::data, mlir::python::PyMlirContext::get(), mlir::python::PyOperation::getOperation(), MlirStringRef::length, mlirIdentifierStr(), mlirOperationGetName(), mlirOperationImplementsInterface(), mlirOperationImplementsInterfaceStatic(), mlirStringRefCreate(), and mlir::python::DefaultingPyMlirContext::resolve().

Member Function Documentation

◆ bind()

template<typename ConcreteIface >
static void mlir::python::PyConcreteOpInterface< ConcreteIface >::bind ( nb::module_ &  m)
inlinestatic

Creates the Python bindings for this class in the given module.

Definition at line 195 of file IRInterfaces.cpp.

◆ bindDerived()

template<typename ConcreteIface >
static void mlir::python::PyConcreteOpInterface< ConcreteIface >::bindDerived ( ClassTy cls)
inlinestatic

Hook for derived classes to add class-specific bindings.

Definition at line 206 of file IRInterfaces.cpp.

◆ getOperationObject()

template<typename ConcreteIface >
nb::object mlir::python::PyConcreteOpInterface< ConcreteIface >::getOperationObject ( )
inline

Returns the operation instance from which this object was constructed.

Throws a type error if this object was constructed from a subclass of OpView.

Definition at line 215 of file IRInterfaces.cpp.

References mlir::python::PyOperation::getRef(), and mlir::python::PyObjectRef< T >::releaseObject().

◆ getOpName()

template<typename ConcreteIface >
const std::string& mlir::python::PyConcreteOpInterface< ConcreteIface >::getOpName ( )
inline

Returns the canonical name of the operation this interface is constructed from.

Definition at line 236 of file IRInterfaces.cpp.

◆ getOpView()

template<typename ConcreteIface >
nb::object mlir::python::PyConcreteOpInterface< ConcreteIface >::getOpView ( )
inline

Returns the opview of the operation instance from which this object was constructed.

Throws a type error if this object was constructed form a subclass of OpView.

Definition at line 226 of file IRInterfaces.cpp.

References mlir::python::PyOperation::createOpView().

◆ isStatic()

template<typename ConcreteIface >
bool mlir::python::PyConcreteOpInterface< ConcreteIface >::isStatic ( )
inline

Returns true if this object was constructed from a subclass of OpView rather than from an operation instance.

Definition at line 210 of file IRInterfaces.cpp.


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