[Mlir-commits] [mlir] [mlir][python] bind block predecessors and successors (PR #145116)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Sat Jun 21 00:10:31 PDT 2025


================
@@ -1059,6 +1059,26 @@ void mlirBlockPrint(MlirBlock block, MlirStringCallback callback,
   unwrap(block)->print(stream);
 }
 
+intptr_t mlirBlockGetNumSuccessors(MlirBlock block) {
+  return static_cast<intptr_t>(unwrap(block)->getNumSuccessors());
+}
+
+MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos) {
+  return wrap(unwrap(block)->getSuccessor(static_cast<unsigned>(pos)));
+}
+
+intptr_t mlirBlockGetNumPredecessors(MlirBlock block) {
+  Block *b = unwrap(block);
+  return static_cast<intptr_t>(std::distance(b->pred_begin(), b->pred_end()));
+}
+
+MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos) {
+  Block *b = unwrap(block);
+  Block::pred_iterator it = b->pred_begin();
+  std::advance(it, pos);
+  return wrap(*it);
----------------
ftynse wrote:

I'd rather avoid iterating over the use-def list every time... This goes through block's use-def chain, maybe there is a way to expose a `BlockOperand` (and incidentally `OpOperand` if it isn't) and a `getNextUse`.

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


More information about the Mlir-commits mailing list