[Mlir-commits] [mlir] [MLIR][CAPI][Python] Add support for querying memory effect instances (PR #213459)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Aug 5 08:05:30 PDT 2026


================
@@ -494,30 +544,70 @@ class PyMemoryEffectsOpInterface
       nb::handle(static_cast<PyObject *>(userData)).dec_ref();
     };
     callbacks.getEffects = [](MlirOperation op,
-                              MlirMemoryEffectInstancesList effects,
-                              void *userData) {
+                              MlirMemoryEffectInstancesCallback callback,
+                              void *callbackUserData, void *userData) {
       nb::handle pyClass(static_cast<PyObject *>(userData));
 
       // Get the 'get_effects' method from the Python class.
       auto pyGetEffects =
           nb::cast<nb::callable>(nb::getattr(pyClass, "get_effects"));
 
-      PyMemoryEffectsInstanceList effectsWrapper{effects};
-
       PyMlirContextRef context =
           PyMlirContext::forContext(mlirOperationGetContext(op));
       auto opview = PyOperation::forOperation(context, op)->createOpView();
 
-      // Invoke `pyClass.get_effects(op, effects)`.
-      pyGetEffects(opview, effectsWrapper);
+      // Invoke `pyClass.get_effects(op)` and pass the resulting instances back
+      // to the C++ interface as a borrowed array.
+      nb::object result = pyGetEffects(opview);
+      nb::iterable iterable;
+      if (!nb::try_cast<nb::iterable>(result, iterable))
+        throw nb::type_error("get_effects must return an iterable");
+
+      std::vector<nb::object> effectObjects;
+      std::vector<MlirMemoryEffectInstance> effects;
+      for (nb::handle object : iterable) {
+        PyMemoryEffectInstance *effect = nullptr;
+        if (!nb::try_cast<PyMemoryEffectInstance *>(object, effect) || !effect)
+          throw nb::type_error(
+              "get_effects must return MemoryEffectInstance objects");
----------------
PragmaTwice wrote:

done in https://github.com/llvm/llvm-project/pull/213459/commits/b16755b3d45e1b12ce71ad220a6f3fb7bf574024

https://github.com/llvm/llvm-project/pull/213459


More information about the Mlir-commits mailing list