[Mlir-commits] [mlir] [mlir][Interfaces][NFC] Add `RegionBranchOpInterface` helper for forwarded values (PR #173981)
Matthias Springer
llvmlistbot at llvm.org
Wed Dec 31 10:51:32 PST 2025
================
@@ -251,30 +251,16 @@ def RegionBranchOpInterface : OpInterface<"RegionBranchOpInterface"> {
"::llvm::SmallVectorImpl<::mlir::RegionBranchPoint> &":$predecessors),
[{}],
/*defaultImplementation=*/[{
- ::llvm::SmallVector<::mlir::RegionSuccessor> successors;
- $_op.getSuccessorRegions(RegionBranchPoint::parent(),
- successors);
- if (llvm::any_of(successors, [&] (const RegionSuccessor & succ) {
+ auto op = cast<RegionBranchOpInterface>($_op.getOperation());
+ for (::mlir::RegionBranchPoint point : op.getAllRegionBranchPoints()) {
+ ::llvm::SmallVector<::mlir::RegionSuccessor> successors;
+ op.getSuccessorRegions(point, successors);
+ bool isPred = llvm::any_of(successors, [&] (const auto &succ) {
return succ.getSuccessor() == successor.getSuccessor() ||
- (succ.isParent() && successor.isParent());
- }))
- predecessors.push_back(RegionBranchPoint::parent());
- for (Region ®ion : $_op->getRegions()) {
- for (::mlir::Block &block : region) {
- if (block.empty())
- continue;
- if (auto terminator =
- dyn_cast<RegionBranchTerminatorOpInterface>(block.back())) {
- ::llvm::SmallVector<::mlir::RegionSuccessor> successors;
- $_op.getSuccessorRegions(RegionBranchPoint(terminator),
- successors);
- if (llvm::any_of(successors, [&] (const RegionSuccessor & succ) {
- return succ.getSuccessor() == successor.getSuccessor() ||
- (succ.isParent() && successor.isParent());
----------------
matthias-springer wrote:
This line checks if the `succ` matches `successor` (the function parameter). We don't care about the successor inputs (they may not be populated), that's why we don't use `operator==`.
Technically, I think `succ.isParent() && successor.isParent()` is not needed because if the region successor is the parent op, `getSuccessor()` would return a `nullptr` region.
https://github.com/llvm/llvm-project/pull/173981
More information about the Mlir-commits
mailing list