[RFC] Add getSuccessorForwardOperands method to BranchOpInterface

Background

I’m looking to implement a reduction pattern for mlir-reduce that targets IR with multiple execution paths (e.g., cf.cond_br, cf.switch). The goal is to reduce the IR into the simplest “interesting” path. The general approach is to iterate through the targets of branching ops, replace conditional branches with cf.br, and then run the canonicalization pass to check for interestingness. Through this iterative process, we can gradually obtain the simplest IR while also achieving block elimination

Issue

I’ve encountered an issue where, although I can identify the successor of a conditional branch (block*), I cannot retrieve the corresponding successor operands. I need to obtain the correct operands; otherwise, mismatches in operand count or type will occur. Therefore, I propose adding a getSuccessorForwardOperandsmethod to the BranchOpInterface. This method would take a Block* (a successor of the branch op) as input and return the specific values (successor operands) being forwarded to that successor.

End

You can see the PR in [mlir][interface] Add getSuccessorForwardOperands to BranchOpInterface by linuxlonelyeagle · Pull Request #190735 · llvm/llvm-project · GitHub. I’d appreciate a review on this. Thanks, everyone! Please let me know if you have any questions.:heart:

Does getSuccessorBlockArgument not work for you? (You can query it for every operand index.) edit: what Fabian said…

Isn’t BranchOpInterface::getSuccessorOperands already offering what you’re looking for?

Note that in general there’s no 1-1 mapping between a block and successor operands. There’s nothing preventing a block appearing many times.

Haha, that’s a bit embarrassing :sweat_smile:. I’ll give it a try when I have some time. But it is through these repeated interactions with everyone that I have truly grown. :thinking: