Extending Control-Flow Interfaces

The current control-flow interfaces (in particular the BranchOpInterface) allow us to query information about successor operands. In addition, there is a generic LoopLikeOpInterface which can give us more information about loops in general.

However, we want to analyze structured control flow (loops, to be precise) and determine which arguments are passed “back” to the entry block of a nested region (the first block in the loop). This should also cover cases where we “drop” values that will not “returned” to the entry block. It looks like we need to store a custom mapping that somehow wires terminator operands to block arguments in the entry block.

On the one hand, it would sufficient for us to assume that a custom loop back-edge (such as linalg.yield) would return to the beginning of the region instead of jumping to another block within the region it belongs to. On the other hand, having a more generic interface that also captures these cases might be interesting to think about. However, we have spent some time investigating the latter case and have stumbled upon the fact that “successors” are currently closely linked to the world of non-structured control flow: You can query the successors of blocks but the last block in a region does not have any successors (as intended). Creating an interface that allows you to enumerate the successors in the structured-control-flow world would add another “interpretation” of successors in the scope of MLIR. (Another question would be: Is such a generic functionality really necessary? I can imagine some sophisticated cases that do not seem to be important, as they can be modelled with nested regions).

Are there any current activities on creating/designing such an interface?

There is no requirement that the last block of a region have no successors. The only constraint on block ordering is that the entry block comes first.

If you want to do any kind of generic dataflow analysis on structured control flow(somewhat common), you will have to create an interface of some kind.

Yes, work is already on-going. I just recently added an interface that provides enough to perform SCCP on structured control flow regions, e.g. loops and ifs. It contains enough to support those cases, and can be modified/extended to support others based on need.


@River707 Yes you are totally right regarding the successor of the last block in a region (I phrased the sentence misunderstandably).

Good news; this looks very promising :slight_smile: