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 (py::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...
 
py::object getOperationObject ()
 Returns the operation instance from which this object was constructed. More...
 
py::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 (py::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 = py::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 145 of file IRInterfaces.cpp.

Member Typedef Documentation

◆ ClassTy

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

Definition at line 147 of file IRInterfaces.cpp.

◆ GetTypeIDFunctionTy

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

Definition at line 148 of file IRInterfaces.cpp.

Constructor & Destructor Documentation

◆ PyConcreteOpInterface()

template<typename ConcreteIface >
mlir::python::PyConcreteOpInterface< ConcreteIface >::PyConcreteOpInterface ( py::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 154 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 ( py::module &  m)
inlinestatic

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

Definition at line 196 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 210 of file IRInterfaces.cpp.

◆ getOperationObject()

template<typename ConcreteIface >
py::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 219 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 240 of file IRInterfaces.cpp.

◆ getOpView()

template<typename ConcreteIface >
py::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 230 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 214 of file IRInterfaces.cpp.


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