[llvm] [mlir][CAPI, python bindings] Expose `Operation::setSuccessor` (PR #67922)

Oleksandr Alex Zinenko via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 02:14:11 PDT 2023


================
@@ -2924,7 +2924,17 @@ void mlir::python::populateIRCore(py::module &m) {
                              &PyOperation::getCapsule)
       .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyOperation::createFromCapsule)
       .def_property_readonly("operation", [](py::object self) { return self; })
-      .def_property_readonly("opview", &PyOperation::createOpView);
+      .def_property_readonly("opview", &PyOperation::createOpView)
+      .def_property_readonly(
+          "num_successors",
+          [](PyOperation &self) { return mlirOperationGetNumSuccessors(self); })
+      .def("get_successor",
+           [](PyOperation &self, int pos) -> PyBlock {
+             return {self.getRef(), mlirOperationGetSuccessor(self, pos)};
+           })
+      .def("set_successor", [](PyOperation &self, PyBlock block, int pos) {
+        mlirOperationSetSuccessor(self, block.get(), pos);
+      });
----------------
ftynse wrote:

Have you considered a more Pythonic and less imperative syntax here? E.g., defining an list-like `successors` field so one can do `len(op.successors)` or `op.successor[42] = ...`?  We do something similar with operand and results, so there is even the C++ glue code for defining interface classes.

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


More information about the llvm-commits mailing list