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_CONTEXT \
66 MAKE_MLIR_PYTHON_QUALNAME("ir.Context._CAPIPtr")
67 #define MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY \
68 MAKE_MLIR_PYTHON_QUALNAME("ir.DialectRegistry._CAPIPtr")
69 #define MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE \
70 MAKE_MLIR_PYTHON_QUALNAME("execution_engine.ExecutionEngine._CAPIPtr")
71 #define MLIR_PYTHON_CAPSULE_INTEGER_SET \
72 MAKE_MLIR_PYTHON_QUALNAME("ir.IntegerSet._CAPIPtr")
73 #define MLIR_PYTHON_CAPSULE_LOCATION \
74 MAKE_MLIR_PYTHON_QUALNAME("ir.Location._CAPIPtr")
75 #define MLIR_PYTHON_CAPSULE_MODULE \
76 MAKE_MLIR_PYTHON_QUALNAME("ir.Module._CAPIPtr")
77 #define MLIR_PYTHON_CAPSULE_OPERATION \
78 MAKE_MLIR_PYTHON_QUALNAME("ir.Operation._CAPIPtr")
79 #define MLIR_PYTHON_CAPSULE_TYPE MAKE_MLIR_PYTHON_QUALNAME("ir.Type._CAPIPtr")
80 #define MLIR_PYTHON_CAPSULE_PASS_MANAGER \
81 MAKE_MLIR_PYTHON_QUALNAME("passmanager.PassManager._CAPIPtr")
82 #define MLIR_PYTHON_CAPSULE_VALUE MAKE_MLIR_PYTHON_QUALNAME("ir.Value._CAPIPtr")
93 #define MLIR_PYTHON_CAPI_PTR_ATTR "_CAPIPtr"
106 #define MLIR_PYTHON_CAPI_FACTORY_ATTR "_CAPICreate"
111 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) \
112 (const_cast<void *>((object).ptr))
114 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) (void *)(object.ptr)
136 MlirAffineExpr expr = {ptr};
155 MlirAttribute attr = {ptr};
173 MlirContext context = {ptr};
181 static inline PyObject *
191 static inline MlirDialectRegistry
195 MlirDialectRegistry registry = {ptr};
213 MlirLocation loc = {ptr};
231 MlirModule module = {ptr};
246 static inline MlirPassManager
249 MlirPassManager pm = {ptr};
267 MlirOperation op = {ptr};
286 MlirType type = {ptr};
305 MlirAffineMap affineMap = {ptr};
312 static inline PyObject *
324 MlirIntegerSet integerSet = {ptr};
331 static inline PyObject *
341 static inline MlirExecutionEngine
345 MlirExecutionEngine jit = {ptr};
364 MlirValue value = {ptr};
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 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 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_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 * 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.