21 #ifndef MLIR_C_BINDINGS_PYTHON_INTEROP_H
22 #define MLIR_C_BINDINGS_PYTHON_INTEROP_H
32 #if !defined(_MSC_VER)
50 #ifndef MLIR_PYTHON_PACKAGE_PREFIX
51 #define MLIR_PYTHON_PACKAGE_PREFIX mlir.
55 #define MLIR_PYTHON_STRINGIZE(s) #s
56 #define MLIR_PYTHON_STRINGIZE_ARG(arg) MLIR_PYTHON_STRINGIZE(arg)
57 #define MAKE_MLIR_PYTHON_QUALNAME(local) \
58 MLIR_PYTHON_STRINGIZE_ARG(MLIR_PYTHON_PACKAGE_PREFIX) local
60 #define MLIR_PYTHON_CAPSULE_AFFINE_EXPR \
61 MAKE_MLIR_PYTHON_QUALNAME("ir.AffineExpr._CAPIPtr")
62 #define MLIR_PYTHON_CAPSULE_AFFINE_MAP \
63 MAKE_MLIR_PYTHON_QUALNAME("ir.AffineMap._CAPIPtr")
64 #define MLIR_PYTHON_CAPSULE_ATTRIBUTE \
65 MAKE_MLIR_PYTHON_QUALNAME("ir.Attribute._CAPIPtr")
66 #define MLIR_PYTHON_CAPSULE_BLOCK MAKE_MLIR_PYTHON_QUALNAME("ir.Block._CAPIPtr")
67 #define MLIR_PYTHON_CAPSULE_CONTEXT \
68 MAKE_MLIR_PYTHON_QUALNAME("ir.Context._CAPIPtr")
69 #define MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY \
70 MAKE_MLIR_PYTHON_QUALNAME("ir.DialectRegistry._CAPIPtr")
71 #define MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE \
72 MAKE_MLIR_PYTHON_QUALNAME("execution_engine.ExecutionEngine._CAPIPtr")
73 #define MLIR_PYTHON_CAPSULE_INTEGER_SET \
74 MAKE_MLIR_PYTHON_QUALNAME("ir.IntegerSet._CAPIPtr")
75 #define MLIR_PYTHON_CAPSULE_LOCATION \
76 MAKE_MLIR_PYTHON_QUALNAME("ir.Location._CAPIPtr")
77 #define MLIR_PYTHON_CAPSULE_MODULE \
78 MAKE_MLIR_PYTHON_QUALNAME("ir.Module._CAPIPtr")
79 #define MLIR_PYTHON_CAPSULE_OPERATION \
80 MAKE_MLIR_PYTHON_QUALNAME("ir.Operation._CAPIPtr")
81 #define MLIR_PYTHON_CAPSULE_TYPE MAKE_MLIR_PYTHON_QUALNAME("ir.Type._CAPIPtr")
82 #define MLIR_PYTHON_CAPSULE_PASS_MANAGER \
83 MAKE_MLIR_PYTHON_QUALNAME("passmanager.PassManager._CAPIPtr")
84 #define MLIR_PYTHON_CAPSULE_VALUE MAKE_MLIR_PYTHON_QUALNAME("ir.Value._CAPIPtr")
85 #define MLIR_PYTHON_CAPSULE_TYPEID \
86 MAKE_MLIR_PYTHON_QUALNAME("ir.TypeID._CAPIPtr")
97 #define MLIR_PYTHON_CAPI_PTR_ATTR "_CAPIPtr"
110 #define MLIR_PYTHON_CAPI_FACTORY_ATTR "_CAPICreate"
118 #define MLIR_PYTHON_MAYBE_DOWNCAST_ATTR "maybe_downcast"
130 #define MLIR_PYTHON_CAPI_TYPE_CASTER_REGISTER_ATTR "register_type_caster"
142 #define MLIR_PYTHON_CAPI_VALUE_CASTER_REGISTER_ATTR "register_value_caster"
147 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) \
148 (const_cast<void *>((object).ptr))
150 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) (void *)(object.ptr)
172 MlirAffineExpr expr = {ptr};
191 MlirAttribute attr = {ptr};
208 MlirBlock block = {ptr};
226 MlirContext context = {ptr};
234 static inline PyObject *
244 static inline MlirDialectRegistry
248 MlirDialectRegistry registry = {ptr};
266 MlirLocation loc = {ptr};
284 MlirModule module = {ptr};
292 static inline PyObject *
301 static inline MlirFrozenRewritePatternSet
304 MlirFrozenRewritePatternSet pm = {ptr};
319 static inline MlirPassManager
322 MlirPassManager pm = {ptr};
340 MlirOperation op = {ptr};
359 MlirTypeID typeID = {ptr};
378 MlirType type = {ptr};
397 MlirAffineMap affineMap = {ptr};
404 static inline PyObject *
416 MlirIntegerSet integerSet = {ptr};
423 static inline PyObject *
433 static inline MlirExecutionEngine
437 MlirExecutionEngine jit = {ptr};
456 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.
static MlirFrozenRewritePatternSet mlirPythonCapsuleToFrozenRewritePatternSet(PyObject *capsule)
Extracts an MlirFrozenRewritePatternSet from a capsule as produced from mlirPythonFrozenRewritePatter...
#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 PyObject * mlirPythonFrozenRewritePatternSetToCapsule(MlirFrozenRewritePatternSet pm)
Creates a capsule object encapsulating the raw C-API MlirFrozenRewritePatternSet.
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.