[Mlir-commits] [mlir] [mlir][transforms] Process RegionBranchOp with empty region (PR #123895)

Xiang Li llvmlistbot at llvm.org
Fri Jan 31 12:16:58 PST 2025


python3kgae wrote:

> Regions can't be dynamically added, they are fixed after creation, which is why the convention has been for ops like scf.if to create both regions immediately. Adding a block and a yield is "not free" and in general we avoided consuming extra resources when not needed, hence the convention about empty regions.
> 
> `scf.if` isn't the only case, for example a function declaration has an empty region as well. This is even codified in the Parser API somehow with the `parseOptionalRegion()` API which follows the pattern in general of:
> 
> ```
>   auto *body = result.addRegion();
>   OptionalParseResult parseResult =
>       parser.parseOptionalRegion(*body, ...);
> ```
> 
> If we want to change, I would look at it holistically: it goes beyond just `scf.if` I believe.

So, it is better for RegionBranchOpInterface not to assume a non-empty region when using getRegions, since getRegions is not a method of RegionBranchOpInterface and there're many cases empty regions are allowed right now?


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


More information about the Mlir-commits mailing list