21 #ifndef MLIR_C_BINDINGS_PYTHON_INTEROP_H
22 #define MLIR_C_BINDINGS_PYTHON_INTEROP_H
32 #if !defined(_MSC_VER)
49 #ifndef MLIR_PYTHON_PACKAGE_PREFIX
50 #define MLIR_PYTHON_PACKAGE_PREFIX mlir.
54 #define MLIR_PYTHON_STRINGIZE(s) #s
55 #define MLIR_PYTHON_STRINGIZE_ARG(arg) MLIR_PYTHON_STRINGIZE(arg)
56 #define MAKE_MLIR_PYTHON_QUALNAME(local) \
57 MLIR_PYTHON_STRINGIZE_ARG(MLIR_PYTHON_PACKAGE_PREFIX) local
59 #define MLIR_PYTHON_CAPSULE_AFFINE_EXPR \
60 MAKE_MLIR_PYTHON_QUALNAME("ir.AffineExpr._CAPIPtr")
61 #define MLIR_PYTHON_CAPSULE_AFFINE_MAP \
62 MAKE_MLIR_PYTHON_QUALNAME("ir.AffineMap._CAPIPtr")
63 #define MLIR_PYTHON_CAPSULE_ATTRIBUTE \
64 MAKE_MLIR_PYTHON_QUALNAME("ir.Attribute._CAPIPtr")
65 #define MLIR_PYTHON_CAPSULE_BLOCK MAKE_MLIR_PYTHON_QUALNAME("ir.Block._CAPIPtr")
66 #define MLIR_PYTHON_CAPSULE_CONTEXT \
67 MAKE_MLIR_PYTHON_QUALNAME("ir.Context._CAPIPtr")
68 #define MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY \
69 MAKE_MLIR_PYTHON_QUALNAME("ir.DialectRegistry._CAPIPtr")
70 #define MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE \
71 MAKE_MLIR_PYTHON_QUALNAME("execution_engine.ExecutionEngine._CAPIPtr")
72 #define MLIR_PYTHON_CAPSULE_INTEGER_SET \
73 MAKE_MLIR_PYTHON_QUALNAME("ir.IntegerSet._CAPIPtr")
74 #define MLIR_PYTHON_CAPSULE_LOCATION \
75 MAKE_MLIR_PYTHON_QUALNAME("ir.Location._CAPIPtr")
76 #define MLIR_PYTHON_CAPSULE_MODULE \
77 MAKE_MLIR_PYTHON_QUALNAME("ir.Module._CAPIPtr")
78 #define MLIR_PYTHON_CAPSULE_OPERATION \
79 MAKE_MLIR_PYTHON_QUALNAME("ir.Operation._CAPIPtr")
80 #define MLIR_PYTHON_CAPSULE_TYPE MAKE_MLIR_PYTHON_QUALNAME("ir.Type._CAPIPtr")
81 #define MLIR_PYTHON_CAPSULE_PASS_MANAGER \
82 MAKE_MLIR_PYTHON_QUALNAME("passmanager.PassManager._CAPIPtr")
83 #define MLIR_PYTHON_CAPSULE_VALUE MAKE_MLIR_PYTHON_QUALNAME("ir.Value._CAPIPtr")
84 #define MLIR_PYTHON_CAPSULE_TYPEID \
85 MAKE_MLIR_PYTHON_QUALNAME("ir.TypeID._CAPIPtr")
96 #define MLIR_PYTHON_CAPI_PTR_ATTR "_CAPIPtr"
109 #define MLIR_PYTHON_CAPI_FACTORY_ATTR "_CAPICreate"
117 #define MLIR_PYTHON_MAYBE_DOWNCAST_ATTR "maybe_downcast"
126 #define MLIR_PYTHON_CAPI_TYPE_CASTER_REGISTER_ATTR "register_type_caster"
131 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) \
132 (const_cast<void *>((object).ptr))
134 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) (void *)(object.ptr)
156 MlirAffineExpr expr = {ptr};
175 MlirAttribute attr = {ptr};
192 MlirBlock block = {ptr};
210 MlirContext context = {ptr};
218 static inline PyObject *
228 static inline MlirDialectRegistry
232 MlirDialectRegistry registry = {ptr};
250 MlirLocation loc = {ptr};
268 MlirModule module = {ptr};
283 static inline MlirPassManager
286 MlirPassManager pm = {ptr};
304 MlirOperation op = {ptr};
323 MlirTypeID typeID = {ptr};
342 MlirType type = {ptr};
361 MlirAffineMap affineMap = {ptr};
368 static inline PyObject *
380 MlirIntegerSet integerSet = {ptr};
387 static inline PyObject *
397 static inline MlirExecutionEngine
401 MlirExecutionEngine jit = {ptr};
420 MlirValue value = {ptr};
#define MLIR_PYTHON_CAPSULE_TYPEID
static MlirIntegerSet mlirPythonCapsuleToIntegerSet(PyObject *capsule)
Extracts an MlirIntegerSet from a capsule as produced from mlirPythonIntegerSetToCapsule.
static PyObject * mlirPythonModuleToCapsule(MlirModule module)
Creates a capsule object encapsulating the raw C-API MlirModule.
#define MLIR_PYTHON_CAPSULE_ATTRIBUTE
static MlirBlock mlirPythonCapsuleToBlock(PyObject *capsule)
Extracts an MlirBlock from a capsule as produced from mlirPythonBlockToCapsule.
static PyObject * mlirPythonTypeIDToCapsule(MlirTypeID typeID)
Creates a capsule object encapsulating the raw C-API MlirTypeID.
static MlirExecutionEngine mlirPythonCapsuleToExecutionEngine(PyObject *capsule)
Extracts an MlirExecutionEngine from a capsule as produced from mlirPythonIntegerSetToCapsule.
static MlirOperation mlirPythonCapsuleToOperation(PyObject *capsule)
Extracts an MlirOperations from a capsule as produced from mlirPythonOperationToCapsule.
#define MLIR_PYTHON_CAPSULE_AFFINE_EXPR
#define MLIR_PYTHON_GET_WRAPPED_POINTER(object)
Gets a void* from a wrapped struct.
static MlirAttribute mlirPythonCapsuleToAttribute(PyObject *capsule)
Extracts an MlirAttribute from a capsule as produced from mlirPythonAttributeToCapsule.
static PyObject * mlirPythonAttributeToCapsule(MlirAttribute attribute)
Creates a capsule object encapsulating the raw C-API MlirAttribute.
static PyObject * mlirPythonIntegerSetToCapsule(MlirIntegerSet integerSet)
Creates a capsule object encapsulating the raw C-API MlirIntegerSet.
static PyObject * mlirPythonLocationToCapsule(MlirLocation loc)
Creates a capsule object encapsulating the raw C-API MlirLocation.
static MlirAffineMap mlirPythonCapsuleToAffineMap(PyObject *capsule)
Extracts an MlirAffineMap from a capsule as produced from mlirPythonAffineMapToCapsule.
#define MLIR_PYTHON_CAPSULE_MODULE
#define MLIR_PYTHON_CAPSULE_OPERATION
#define MLIR_PYTHON_CAPSULE_LOCATION
#define MLIR_PYTHON_CAPSULE_VALUE
#define MLIR_PYTHON_CAPSULE_AFFINE_MAP
static MlirModule mlirPythonCapsuleToModule(PyObject *capsule)
Extracts an MlirModule from a capsule as produced from mlirPythonModuleToCapsule.
static PyObject * mlirPythonExecutionEngineToCapsule(MlirExecutionEngine jit)
Creates a capsule object encapsulating the raw C-API MlirExecutionEngine.
static MlirContext mlirPythonCapsuleToContext(PyObject *capsule)
Extracts a MlirContext from a capsule as produced from mlirPythonContextToCapsule.
static MlirTypeID mlirPythonCapsuleToTypeID(PyObject *capsule)
Extracts an MlirTypeID from a capsule as produced from mlirPythonTypeIDToCapsule.
static PyObject * mlirPythonDialectRegistryToCapsule(MlirDialectRegistry registry)
Creates a capsule object encapsulating the raw C-API MlirDialectRegistry.
#define MLIR_PYTHON_CAPSULE_CONTEXT
static PyObject * mlirPythonTypeToCapsule(MlirType type)
Creates a capsule object encapsulating the raw C-API MlirType.
#define MLIR_PYTHON_CAPSULE_BLOCK
#define MLIR_PYTHON_CAPSULE_PASS_MANAGER
#define MLIR_PYTHON_CAPSULE_TYPE
static PyObject * mlirPythonPassManagerToCapsule(MlirPassManager pm)
Creates a capsule object encapsulating the raw C-API MlirPassManager.
#define MLIR_PYTHON_CAPSULE_INTEGER_SET
static MlirDialectRegistry mlirPythonCapsuleToDialectRegistry(PyObject *capsule)
Extracts an MlirDialectRegistry from a capsule as produced from mlirPythonDialectRegistryToCapsule.
#define MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY
static PyObject * mlirPythonAffineExprToCapsule(MlirAffineExpr expr)
Creates a capsule object encapsulating the raw C-API MlirAffineExpr.
static MlirType mlirPythonCapsuleToType(PyObject *capsule)
Extracts an MlirType from a capsule as produced from mlirPythonTypeToCapsule.
static MlirValue mlirPythonCapsuleToValue(PyObject *capsule)
Extracts an MlirValue from a capsule as produced from mlirPythonValueToCapsule.
static PyObject * mlirPythonBlockToCapsule(MlirBlock block)
Creates a capsule object encapsulating the raw C-API MlirBlock.
static PyObject * mlirPythonAffineMapToCapsule(MlirAffineMap affineMap)
Creates a capsule object encapsulating the raw C-API MlirAffineMap.
#define MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE
static MlirPassManager mlirPythonCapsuleToPassManager(PyObject *capsule)
Extracts an MlirPassManager from a capsule as produced from mlirPythonPassManagerToCapsule.
static MlirAffineExpr mlirPythonCapsuleToAffineExpr(PyObject *capsule)
Extracts an MlirAffineExpr from a capsule as produced from mlirPythonAffineExprToCapsule.
static PyObject * mlirPythonOperationToCapsule(MlirOperation operation)
Creates a capsule object encapsulating the raw C-API MlirOperation.
static MlirLocation mlirPythonCapsuleToLocation(PyObject *capsule)
Extracts an MlirLocation from a capsule as produced from mlirPythonLocationToCapsule.
static PyObject * mlirPythonValueToCapsule(MlirValue value)
Creates a capsule object encapsulating the raw C-API MlirValue.
static PyObject * mlirPythonContextToCapsule(MlirContext context)
Creates a capsule object encapsulating the raw C-API MlirContext.