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

Maksim Levental llvmlistbot at llvm.org
Sat Jun 21 03:55:03 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);
----------------
makslevental wrote:

Don't think so

https://github.com/llvm/llvm-project/blob/1b5d6ec6855369d109fcb740ecd3812231b7a279/mlir/include/mlir/IR/BlockSupport.h#L45

Compare with `SuccessorRange` just below there.

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


More information about the Mlir-commits mailing list