MLIR  18.0.0git
Interop.h
Go to the documentation of this file.
1 //===-- mlir-c/Interop.h - Constants for Python/C-API interop -----*- C -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
4 // Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This header declares constants and helpers necessary for C-level
11 // interop with the MLIR Python extension module. Since the Python bindings
12 // are a thin wrapper around the MLIR C-API, a further C-API is not provided
13 // specifically for the Python extension. Instead, simple facilities are
14 // provided for translating between Python types and corresponding MLIR C-API
15 // types.
16 //
17 // This header is standalone, requiring nothing beyond normal linking against
18 // the Python implementation.
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef MLIR_C_BINDINGS_PYTHON_INTEROP_H
22 #define MLIR_C_BINDINGS_PYTHON_INTEROP_H
23 
24 // We *should*, in theory, include Python.h here in order to import the correct
25 // definitions for what we need below, however, importing Python.h directly on
26 // Windows results in the enforcement of either pythonX.lib or pythonX_d.lib
27 // depending on the build flavor. Instead, we rely on the fact that this file
28 // (Interop.h) is always included AFTER pybind11 and will therefore have access
29 // to the definitions from Python.h in addition to having a workaround applied
30 // through the pybind11 headers that allows us to control which python library
31 // is used.
32 #if !defined(_MSC_VER)
33 #include <Python.h>
34 #endif
35 
36 #include "mlir-c/AffineExpr.h"
37 #include "mlir-c/AffineMap.h"
38 #include "mlir-c/ExecutionEngine.h"
39 #include "mlir-c/IR.h"
40 #include "mlir-c/IntegerSet.h"
41 #include "mlir-c/Pass.h"
42 
43 // The 'mlir' Python package is relocatable and supports co-existing in multiple
44 // projects. Each project must define its outer package prefix with this define
45 // in order to provide proper isolation and local name resolution.
46 // The default is for the upstream "import mlir" package layout.
47 // Note that this prefix is internally stringified, allowing it to be passed
48 // unquoted on the compiler command line without shell quote escaping issues.
49 #ifndef MLIR_PYTHON_PACKAGE_PREFIX
50 #define MLIR_PYTHON_PACKAGE_PREFIX mlir.
51 #endif
52 
53 // Makes a fully-qualified name relative to the MLIR python package.
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
58 
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")
86 
87 /** Attribute on MLIR Python objects that expose their C-API pointer.
88  * This will be a type-specific capsule created as per one of the helpers
89  * below.
90  *
91  * Ownership is not transferred by acquiring a capsule in this way: the
92  * validity of the pointer wrapped by the capsule will be bounded by the
93  * lifetime of the Python object that produced it. Only the name and pointer
94  * of the capsule are set. The caller is free to set a destructor and context
95  * as needed to manage anything further. */
96 #define MLIR_PYTHON_CAPI_PTR_ATTR "_CAPIPtr"
97 
98 /** Attribute on MLIR Python objects that exposes a factory function for
99  * constructing the corresponding Python object from a type-specific
100  * capsule wrapping the C-API pointer. The signature of the function is:
101  * def _CAPICreate(capsule) -> object
102  * Calling such a function implies a transfer of ownership of the object the
103  * capsule wraps: after such a call, the capsule should be considered invalid,
104  * and its wrapped pointer must not be destroyed.
105  *
106  * Only a very small number of Python objects can be created in such a fashion
107  * (i.e. top-level types such as Context where the lifetime can be cleanly
108  * delineated). */
109 #define MLIR_PYTHON_CAPI_FACTORY_ATTR "_CAPICreate"
110 
111 /** Attribute on MLIR Python objects that expose a function for downcasting the
112  * corresponding Python object to a subclass if the object is in fact a subclass
113  * (Concrete or mlir_type_subclass) of ir.Type. The signature of the function
114  * is: def maybe_downcast(self) -> object where the resulting object will
115  * (possibly) be an instance of the subclass.
116  */
117 #define MLIR_PYTHON_MAYBE_DOWNCAST_ATTR "maybe_downcast"
118 
119 /** Attribute on main C extension module (_mlir) that corresponds to the
120  * type caster registration binding. The signature of the function is:
121  * def register_type_caster(MlirTypeID mlirTypeID, py::function typeCaster,
122  * bool replace)
123  * where replace indicates the typeCaster should replace any existing registered
124  * type casters (such as those for upstream ConcreteTypes).
125  */
126 #define MLIR_PYTHON_CAPI_TYPE_CASTER_REGISTER_ATTR "register_type_caster"
127 
128 /// Gets a void* from a wrapped struct. Needed because const cast is different
129 /// between C/C++.
130 #ifdef __cplusplus
131 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) \
132  (const_cast<void *>((object).ptr))
133 #else
134 #define MLIR_PYTHON_GET_WRAPPED_POINTER(object) (void *)(object.ptr)
135 #endif
136 
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
140 
141 /** Creates a capsule object encapsulating the raw C-API MlirAffineExpr. The
142  * returned capsule does not extend or affect ownership of any Python objects
143  * that reference the expression in any way.
144  */
145 static inline PyObject *mlirPythonAffineExprToCapsule(MlirAffineExpr expr) {
146  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(expr),
148 }
149 
150 /** Extracts an MlirAffineExpr from a capsule as produced from
151  * mlirPythonAffineExprToCapsule. If the capsule is not of the right type, then
152  * a null expression is returned (as checked via mlirAffineExprIsNull). In such
153  * a case, the Python APIs will have already set an error. */
154 static inline MlirAffineExpr mlirPythonCapsuleToAffineExpr(PyObject *capsule) {
155  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_AFFINE_EXPR);
156  MlirAffineExpr expr = {ptr};
157  return expr;
158 }
159 
160 /** Creates a capsule object encapsulating the raw C-API MlirAttribute.
161  * The returned capsule does not extend or affect ownership of any Python
162  * objects that reference the attribute in any way.
163  */
164 static inline PyObject *mlirPythonAttributeToCapsule(MlirAttribute attribute) {
165  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(attribute),
167 }
168 
169 /** Extracts an MlirAttribute from a capsule as produced from
170  * mlirPythonAttributeToCapsule. If the capsule is not of the right type, then
171  * a null attribute is returned (as checked via mlirAttributeIsNull). In such a
172  * case, the Python APIs will have already set an error. */
173 static inline MlirAttribute mlirPythonCapsuleToAttribute(PyObject *capsule) {
174  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_ATTRIBUTE);
175  MlirAttribute attr = {ptr};
176  return attr;
177 }
178 
179 /** Creates a capsule object encapsulating the raw C-API MlirBlock.
180  * The returned capsule does not extend or affect ownership of any Python
181  * objects that reference the module in any way. */
182 static inline PyObject *mlirPythonBlockToCapsule(MlirBlock block) {
183  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(block),
185 }
186 
187 /** Extracts an MlirBlock from a capsule as produced from
188  * mlirPythonBlockToCapsule. If the capsule is not of the right type, then
189  * a null pass manager is returned (as checked via mlirBlockIsNull). */
190 static inline MlirBlock mlirPythonCapsuleToBlock(PyObject *capsule) {
191  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_BLOCK);
192  MlirBlock block = {ptr};
193  return block;
194 }
195 
196 /** Creates a capsule object encapsulating the raw C-API MlirContext.
197  * The returned capsule does not extend or affect ownership of any Python
198  * objects that reference the context in any way.
199  */
200 static inline PyObject *mlirPythonContextToCapsule(MlirContext context) {
201  return PyCapsule_New(context.ptr, MLIR_PYTHON_CAPSULE_CONTEXT, NULL);
202 }
203 
204 /** Extracts a MlirContext from a capsule as produced from
205  * mlirPythonContextToCapsule. If the capsule is not of the right type, then
206  * a null context is returned (as checked via mlirContextIsNull). In such a
207  * case, the Python APIs will have already set an error. */
208 static inline MlirContext mlirPythonCapsuleToContext(PyObject *capsule) {
209  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_CONTEXT);
210  MlirContext context = {ptr};
211  return context;
212 }
213 
214 /** Creates a capsule object encapsulating the raw C-API MlirDialectRegistry.
215  * The returned capsule does not extend or affect ownership of any Python
216  * objects that reference the context in any way.
217  */
218 static inline PyObject *
219 mlirPythonDialectRegistryToCapsule(MlirDialectRegistry registry) {
220  return PyCapsule_New(registry.ptr, MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY,
221  NULL);
222 }
223 
224 /** Extracts an MlirDialectRegistry from a capsule as produced from
225  * mlirPythonDialectRegistryToCapsule. If the capsule is not of the right type,
226  * then a null context is returned (as checked via mlirContextIsNull). In such a
227  * case, the Python APIs will have already set an error. */
228 static inline MlirDialectRegistry
230  void *ptr =
231  PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY);
232  MlirDialectRegistry registry = {ptr};
233  return registry;
234 }
235 
236 /** Creates a capsule object encapsulating the raw C-API MlirLocation.
237  * The returned capsule does not extend or affect ownership of any Python
238  * objects that reference the location in any way. */
239 static inline PyObject *mlirPythonLocationToCapsule(MlirLocation loc) {
240  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(loc),
242 }
243 
244 /** Extracts an MlirLocation from a capsule as produced from
245  * mlirPythonLocationToCapsule. If the capsule is not of the right type, then
246  * a null module is returned (as checked via mlirLocationIsNull). In such a
247  * case, the Python APIs will have already set an error. */
248 static inline MlirLocation mlirPythonCapsuleToLocation(PyObject *capsule) {
249  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_LOCATION);
250  MlirLocation loc = {ptr};
251  return loc;
252 }
253 
254 /** Creates a capsule object encapsulating the raw C-API MlirModule.
255  * The returned capsule does not extend or affect ownership of any Python
256  * objects that reference the module in any way. */
257 static inline PyObject *mlirPythonModuleToCapsule(MlirModule module) {
258  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(module),
260 }
261 
262 /** Extracts an MlirModule from a capsule as produced from
263  * mlirPythonModuleToCapsule. If the capsule is not of the right type, then
264  * a null module is returned (as checked via mlirModuleIsNull). In such a
265  * case, the Python APIs will have already set an error. */
266 static inline MlirModule mlirPythonCapsuleToModule(PyObject *capsule) {
267  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_MODULE);
268  MlirModule module = {ptr};
269  return module;
270 }
271 
272 /** Creates a capsule object encapsulating the raw C-API MlirPassManager.
273  * The returned capsule does not extend or affect ownership of any Python
274  * objects that reference the module in any way. */
275 static inline PyObject *mlirPythonPassManagerToCapsule(MlirPassManager pm) {
276  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(pm),
278 }
279 
280 /** Extracts an MlirPassManager from a capsule as produced from
281  * mlirPythonPassManagerToCapsule. If the capsule is not of the right type, then
282  * a null pass manager is returned (as checked via mlirPassManagerIsNull). */
283 static inline MlirPassManager
284 mlirPythonCapsuleToPassManager(PyObject *capsule) {
285  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_PASS_MANAGER);
286  MlirPassManager pm = {ptr};
287  return pm;
288 }
289 
290 /** Creates a capsule object encapsulating the raw C-API MlirOperation.
291  * The returned capsule does not extend or affect ownership of any Python
292  * objects that reference the operation in any way.
293  */
294 static inline PyObject *mlirPythonOperationToCapsule(MlirOperation operation) {
295  return PyCapsule_New(operation.ptr, MLIR_PYTHON_CAPSULE_OPERATION, NULL);
296 }
297 
298 /** Extracts an MlirOperations from a capsule as produced from
299  * mlirPythonOperationToCapsule. If the capsule is not of the right type, then
300  * a null type is returned (as checked via mlirOperationIsNull). In such a
301  * case, the Python APIs will have already set an error. */
302 static inline MlirOperation mlirPythonCapsuleToOperation(PyObject *capsule) {
303  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_OPERATION);
304  MlirOperation op = {ptr};
305  return op;
306 }
307 
308 /** Creates a capsule object encapsulating the raw C-API MlirTypeID.
309  * The returned capsule does not extend or affect ownership of any Python
310  * objects that reference the type in any way.
311  */
312 static inline PyObject *mlirPythonTypeIDToCapsule(MlirTypeID typeID) {
313  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(typeID),
315 }
316 
317 /** Extracts an MlirTypeID from a capsule as produced from
318  * mlirPythonTypeIDToCapsule. If the capsule is not of the right type, then
319  * a null type is returned (as checked via mlirTypeIDIsNull). In such a
320  * case, the Python APIs will have already set an error. */
321 static inline MlirTypeID mlirPythonCapsuleToTypeID(PyObject *capsule) {
322  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_TYPEID);
323  MlirTypeID typeID = {ptr};
324  return typeID;
325 }
326 
327 /** Creates a capsule object encapsulating the raw C-API MlirType.
328  * The returned capsule does not extend or affect ownership of any Python
329  * objects that reference the type in any way.
330  */
331 static inline PyObject *mlirPythonTypeToCapsule(MlirType type) {
332  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(type),
334 }
335 
336 /** Extracts an MlirType from a capsule as produced from
337  * mlirPythonTypeToCapsule. If the capsule is not of the right type, then
338  * a null type is returned (as checked via mlirTypeIsNull). In such a
339  * case, the Python APIs will have already set an error. */
340 static inline MlirType mlirPythonCapsuleToType(PyObject *capsule) {
341  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_TYPE);
342  MlirType type = {ptr};
343  return type;
344 }
345 
346 /** Creates a capsule object encapsulating the raw C-API MlirAffineMap.
347  * The returned capsule does not extend or affect ownership of any Python
348  * objects that reference the type in any way.
349  */
350 static inline PyObject *mlirPythonAffineMapToCapsule(MlirAffineMap affineMap) {
351  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(affineMap),
353 }
354 
355 /** Extracts an MlirAffineMap from a capsule as produced from
356  * mlirPythonAffineMapToCapsule. If the capsule is not of the right type, then
357  * a null type is returned (as checked via mlirAffineMapIsNull). In such a
358  * case, the Python APIs will have already set an error. */
359 static inline MlirAffineMap mlirPythonCapsuleToAffineMap(PyObject *capsule) {
360  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_AFFINE_MAP);
361  MlirAffineMap affineMap = {ptr};
362  return affineMap;
363 }
364 
365 /** Creates a capsule object encapsulating the raw C-API MlirIntegerSet.
366  * The returned capsule does not extend or affect ownership of any Python
367  * objects that reference the set in any way. */
368 static inline PyObject *
369 mlirPythonIntegerSetToCapsule(MlirIntegerSet integerSet) {
370  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(integerSet),
372 }
373 
374 /** Extracts an MlirIntegerSet from a capsule as produced from
375  * mlirPythonIntegerSetToCapsule. If the capsule is not of the right type, then
376  * a null set is returned (as checked via mlirIntegerSetIsNull). In such a
377  * case, the Python APIs will have already set an error. */
378 static inline MlirIntegerSet mlirPythonCapsuleToIntegerSet(PyObject *capsule) {
379  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_INTEGER_SET);
380  MlirIntegerSet integerSet = {ptr};
381  return integerSet;
382 }
383 
384 /** Creates a capsule object encapsulating the raw C-API MlirExecutionEngine.
385  * The returned capsule does not extend or affect ownership of any Python
386  * objects that reference the set in any way. */
387 static inline PyObject *
388 mlirPythonExecutionEngineToCapsule(MlirExecutionEngine jit) {
389  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(jit),
391 }
392 
393 /** Extracts an MlirExecutionEngine from a capsule as produced from
394  * mlirPythonIntegerSetToCapsule. If the capsule is not of the right type, then
395  * a null set is returned (as checked via mlirExecutionEngineIsNull). In such a
396  * case, the Python APIs will have already set an error. */
397 static inline MlirExecutionEngine
399  void *ptr =
400  PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE);
401  MlirExecutionEngine jit = {ptr};
402  return jit;
403 }
404 
405 /** Creates a capsule object encapsulating the raw C-API MlirValue.
406  * The returned capsule does not extend or affect ownership of any Python
407  * objects that reference the operation in any way.
408  */
409 static inline PyObject *mlirPythonValueToCapsule(MlirValue value) {
410  return PyCapsule_New(MLIR_PYTHON_GET_WRAPPED_POINTER(value),
412 }
413 
414 /** Extracts an MlirValue from a capsule as produced from
415  * mlirPythonValueToCapsule. If the capsule is not of the right type, then a
416  * null type is returned (as checked via mlirValueIsNull). In such a case, the
417  * Python APIs will have already set an error. */
418 static inline MlirValue mlirPythonCapsuleToValue(PyObject *capsule) {
419  void *ptr = PyCapsule_GetPointer(capsule, MLIR_PYTHON_CAPSULE_VALUE);
420  MlirValue value = {ptr};
421  return value;
422 }
423 
424 #ifdef __cplusplus
425 }
426 #endif
427 
428 #endif // MLIR_C_BINDINGS_PYTHON_INTEROP_H
#define MLIR_PYTHON_CAPSULE_TYPEID
Definition: Interop.h:84
static MlirIntegerSet mlirPythonCapsuleToIntegerSet(PyObject *capsule)
Extracts an MlirIntegerSet from a capsule as produced from mlirPythonIntegerSetToCapsule.
Definition: Interop.h:378
static PyObject * mlirPythonModuleToCapsule(MlirModule module)
Creates a capsule object encapsulating the raw C-API MlirModule.
Definition: Interop.h:257
#define MLIR_PYTHON_CAPSULE_ATTRIBUTE
Definition: Interop.h:63
static MlirBlock mlirPythonCapsuleToBlock(PyObject *capsule)
Extracts an MlirBlock from a capsule as produced from mlirPythonBlockToCapsule.
Definition: Interop.h:190
static PyObject * mlirPythonTypeIDToCapsule(MlirTypeID typeID)
Creates a capsule object encapsulating the raw C-API MlirTypeID.
Definition: Interop.h:312
static MlirExecutionEngine mlirPythonCapsuleToExecutionEngine(PyObject *capsule)
Extracts an MlirExecutionEngine from a capsule as produced from mlirPythonIntegerSetToCapsule.
Definition: Interop.h:398
static MlirOperation mlirPythonCapsuleToOperation(PyObject *capsule)
Extracts an MlirOperations from a capsule as produced from mlirPythonOperationToCapsule.
Definition: Interop.h:302
#define MLIR_PYTHON_CAPSULE_AFFINE_EXPR
Definition: Interop.h:59
#define MLIR_PYTHON_GET_WRAPPED_POINTER(object)
Gets a void* from a wrapped struct.
Definition: Interop.h:134
static MlirAttribute mlirPythonCapsuleToAttribute(PyObject *capsule)
Extracts an MlirAttribute from a capsule as produced from mlirPythonAttributeToCapsule.
Definition: Interop.h:173
static PyObject * mlirPythonAttributeToCapsule(MlirAttribute attribute)
Creates a capsule object encapsulating the raw C-API MlirAttribute.
Definition: Interop.h:164
static PyObject * mlirPythonIntegerSetToCapsule(MlirIntegerSet integerSet)
Creates a capsule object encapsulating the raw C-API MlirIntegerSet.
Definition: Interop.h:369
static PyObject * mlirPythonLocationToCapsule(MlirLocation loc)
Creates a capsule object encapsulating the raw C-API MlirLocation.
Definition: Interop.h:239
static MlirAffineMap mlirPythonCapsuleToAffineMap(PyObject *capsule)
Extracts an MlirAffineMap from a capsule as produced from mlirPythonAffineMapToCapsule.
Definition: Interop.h:359
#define MLIR_PYTHON_CAPSULE_MODULE
Definition: Interop.h:76
#define MLIR_PYTHON_CAPSULE_OPERATION
Definition: Interop.h:78
#define MLIR_PYTHON_CAPSULE_LOCATION
Definition: Interop.h:74
#define MLIR_PYTHON_CAPSULE_VALUE
Definition: Interop.h:83
#define MLIR_PYTHON_CAPSULE_AFFINE_MAP
Definition: Interop.h:61
static MlirModule mlirPythonCapsuleToModule(PyObject *capsule)
Extracts an MlirModule from a capsule as produced from mlirPythonModuleToCapsule.
Definition: Interop.h:266
static PyObject * mlirPythonExecutionEngineToCapsule(MlirExecutionEngine jit)
Creates a capsule object encapsulating the raw C-API MlirExecutionEngine.
Definition: Interop.h:388
static MlirContext mlirPythonCapsuleToContext(PyObject *capsule)
Extracts a MlirContext from a capsule as produced from mlirPythonContextToCapsule.
Definition: Interop.h:208
static MlirTypeID mlirPythonCapsuleToTypeID(PyObject *capsule)
Extracts an MlirTypeID from a capsule as produced from mlirPythonTypeIDToCapsule.
Definition: Interop.h:321
static PyObject * mlirPythonDialectRegistryToCapsule(MlirDialectRegistry registry)
Creates a capsule object encapsulating the raw C-API MlirDialectRegistry.
Definition: Interop.h:219
#define MLIR_PYTHON_CAPSULE_CONTEXT
Definition: Interop.h:66
static PyObject * mlirPythonTypeToCapsule(MlirType type)
Creates a capsule object encapsulating the raw C-API MlirType.
Definition: Interop.h:331
#define MLIR_PYTHON_CAPSULE_BLOCK
Definition: Interop.h:65
#define MLIR_PYTHON_CAPSULE_PASS_MANAGER
Definition: Interop.h:81
#define MLIR_PYTHON_CAPSULE_TYPE
Definition: Interop.h:80
static PyObject * mlirPythonPassManagerToCapsule(MlirPassManager pm)
Creates a capsule object encapsulating the raw C-API MlirPassManager.
Definition: Interop.h:275
#define MLIR_PYTHON_CAPSULE_INTEGER_SET
Definition: Interop.h:72
static MlirDialectRegistry mlirPythonCapsuleToDialectRegistry(PyObject *capsule)
Extracts an MlirDialectRegistry from a capsule as produced from mlirPythonDialectRegistryToCapsule.
Definition: Interop.h:229
#define MLIR_PYTHON_CAPSULE_DIALECT_REGISTRY
Definition: Interop.h:68
static PyObject * mlirPythonAffineExprToCapsule(MlirAffineExpr expr)
Creates a capsule object encapsulating the raw C-API MlirAffineExpr.
Definition: Interop.h:145
static MlirType mlirPythonCapsuleToType(PyObject *capsule)
Extracts an MlirType from a capsule as produced from mlirPythonTypeToCapsule.
Definition: Interop.h:340
static MlirValue mlirPythonCapsuleToValue(PyObject *capsule)
Extracts an MlirValue from a capsule as produced from mlirPythonValueToCapsule.
Definition: Interop.h:418
static PyObject * mlirPythonBlockToCapsule(MlirBlock block)
Creates a capsule object encapsulating the raw C-API MlirBlock.
Definition: Interop.h:182
static PyObject * mlirPythonAffineMapToCapsule(MlirAffineMap affineMap)
Creates a capsule object encapsulating the raw C-API MlirAffineMap.
Definition: Interop.h:350
#define MLIR_PYTHON_CAPSULE_EXECUTION_ENGINE
Definition: Interop.h:70
static MlirPassManager mlirPythonCapsuleToPassManager(PyObject *capsule)
Extracts an MlirPassManager from a capsule as produced from mlirPythonPassManagerToCapsule.
Definition: Interop.h:284
static MlirAffineExpr mlirPythonCapsuleToAffineExpr(PyObject *capsule)
Extracts an MlirAffineExpr from a capsule as produced from mlirPythonAffineExprToCapsule.
Definition: Interop.h:154
static PyObject * mlirPythonOperationToCapsule(MlirOperation operation)
Creates a capsule object encapsulating the raw C-API MlirOperation.
Definition: Interop.h:294
static MlirLocation mlirPythonCapsuleToLocation(PyObject *capsule)
Extracts an MlirLocation from a capsule as produced from mlirPythonLocationToCapsule.
Definition: Interop.h:248
static PyObject * mlirPythonValueToCapsule(MlirValue value)
Creates a capsule object encapsulating the raw C-API MlirValue.
Definition: Interop.h:409
static PyObject * mlirPythonContextToCapsule(MlirContext context)
Creates a capsule object encapsulating the raw C-API MlirContext.
Definition: Interop.h:200