[Mlir-commits] [mlir] [mlir][python] bind block predecessors and successors (PR #145116)
Jacques Pienaar
llvmlistbot at llvm.org
Mon Jun 23 06:49:45 PDT 2025
================
@@ -2440,6 +2440,52 @@ void testDiagnostics(void) {
mlirContextDestroy(ctx);
}
+int testBlockPredecessorsSuccessors(MlirContext ctx) {
+ // CHECK-LABEL: @testBlockPredecessorsSuccessors
+ fprintf(stderr, "@testBlockPredecessorsSuccessors\n");
+
+ const char *moduleString = "module {\n"
+ " func.func @test(%arg0: i32, %arg1: i16) {\n"
+ " cf.br ^bb1(%arg1 : i16)\n"
+ " ^bb1(%0: i16): // pred: ^bb0\n"
+ " cf.br ^bb2(%arg0 : i32)\n"
+ " ^bb2(%1: i32): // pred: ^bb1\n"
+ " return\n"
+ " }\n"
+ "}\n";
+
+ MlirModule module =
+ mlirModuleCreateParse(ctx, mlirStringRefCreateFromCString(moduleString));
+
+ MlirOperation moduleOp = mlirModuleGetOperation(module);
+ MlirRegion moduleRegion = mlirOperationGetRegion(moduleOp, 0);
+ MlirBlock moduleBlock = mlirRegionGetFirstBlock(moduleRegion);
+ MlirOperation function = mlirBlockGetFirstOperation(moduleBlock);
+ MlirRegion funcRegion = mlirOperationGetRegion(function, 0);
+ MlirBlock entryBlock = mlirRegionGetFirstBlock(funcRegion);
+ MlirBlock middleBlock = mlirBlockGetNextInRegion(entryBlock);
+ MlirBlock successorBlock = mlirBlockGetNextInRegion(middleBlock);
+
+ assert(mlirBlockGetNumPredecessors(entryBlock) == 0);
----------------
jpienaar wrote:
This would not be tested in opt builds. I think one would need explicit tests and return non zero for these.
https://github.com/llvm/llvm-project/pull/145116
More information about the Mlir-commits
mailing list