[Mlir-commits] [mlir] [mlir][interface] Add getRegionNonforwardedArguments API to RegionSuccessor (PR #175212)
lonely eagle
llvmlistbot at llvm.org
Sat Jan 10 00:23:42 PST 2026
https://github.com/linuxlonelyeagle updated https://github.com/llvm/llvm-project/pull/175212
>From 8b7ec3e2e04bf2258144afb18ceb37523d1e1d16 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Wed, 7 Jan 2026 15:41:34 +0000
Subject: [PATCH 1/4] delete visitRegionSuccessors not run code.
---
mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 33 +++++++------------
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index b9d861830dd38..02f0e0b77831d 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -307,29 +307,20 @@ void AbstractSparseForwardDataFlowAnalysis::visitRegionSuccessors(
"expected the same number of successor inputs as operands");
unsigned firstIndex = 0;
- if (inputs.size() != lattices.size()) {
- if (!point->isBlockStart()) {
- if (!inputs.empty())
- firstIndex = cast<OpResult>(inputs.front()).getResultNumber();
- visitNonControlFlowArgumentsImpl(
- branch,
- RegionSuccessor(
- branch, branch->getResults().slice(firstIndex, inputs.size())),
- lattices, firstIndex);
- } else {
- if (!inputs.empty())
- firstIndex = cast<BlockArgument>(inputs.front()).getArgNumber();
- Region *region = point->getBlock()->getParent();
- visitNonControlFlowArgumentsImpl(
- branch,
- RegionSuccessor(region, region->getArguments().slice(
- firstIndex, inputs.size())),
- lattices, firstIndex);
- }
+ if (inputs.size() != lattices.size() && point->isBlockStart()) {
+ if (!inputs.empty())
+ firstIndex = cast<BlockArgument>(inputs.front()).getArgNumber();
+ Region *region = point->getBlock()->getParent();
+ visitNonControlFlowArgumentsImpl(
+ branch,
+ RegionSuccessor(
+ region, region->getArguments().slice(firstIndex, inputs.size())),
+ lattices, firstIndex);
}
- for (auto it : llvm::zip(*operands, lattices.drop_front(firstIndex)))
- join(std::get<1>(it), *getLatticeElementFor(point, std::get<0>(it)));
+ for (auto [lattice, operand] :
+ llvm::zip_equal(lattices.drop_front(firstIndex), *operands))
+ join(lattice, *getLatticeElementFor(point, operand));
}
}
>From c83202642357242adcbc0ce1c90eb9f89dbca817 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Wed, 7 Jan 2026 16:07:34 +0000
Subject: [PATCH 2/4] don't use zip_equal.
---
mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index 02f0e0b77831d..695226a49df93 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -319,7 +319,7 @@ void AbstractSparseForwardDataFlowAnalysis::visitRegionSuccessors(
}
for (auto [lattice, operand] :
- llvm::zip_equal(lattices.drop_front(firstIndex), *operands))
+ llvm::zip(lattices.drop_front(firstIndex), *operands))
join(lattice, *getLatticeElementFor(point, operand));
}
}
>From 04e9a03538bdea676071453f367f6ef25b37fdf3 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Fri, 9 Jan 2026 11:03:16 +0000
Subject: [PATCH 3/4] add getRegionNonforwardedArguments API.
---
.../mlir/Interfaces/ControlFlowInterfaces.h | 18 ++++++++++++++++++
mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 12 ++----------
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h b/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
index b76c2891fad5a..76aa20f11d84b 100644
--- a/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
+++ b/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
@@ -228,6 +228,24 @@ class RegionSuccessor {
/// the current region.
ValueRange getSuccessorInputs() const { return inputs; }
+ ValueRange getRegionNonforwardedArguments() const {
+ if (isParent())
+ return {};
+ SmallVector<Value> nonForwardArguments;
+ MutableArrayRef<BlockArgument> arguments = getSuccessor()->getArguments();
+ if (arguments.empty())
+ return {};
+ ValueRange inputs = getSuccessorInputs();
+ if (inputs.empty())
+ return arguments;
+ for (BlockArgument argument : arguments) {
+ if (!llvm::is_contained(inputs, argument)) {
+ nonForwardArguments.push_back(argument);
+ }
+ }
+ return nonForwardArguments;
+ }
+
bool operator==(RegionSuccessor rhs) const {
return successor == rhs.successor && inputs == rhs.inputs;
}
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index 695226a49df93..97889415da31a 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -603,16 +603,8 @@ void AbstractSparseBackwardDataFlowAnalysis::visitRegionSuccessors(
if (successor.isParent())
continue;
SmallVector<BlockArgument> noControlFlowArguments;
- MutableArrayRef<BlockArgument> arguments =
- successor.getSuccessor()->getArguments();
- ValueRange inputs = successor.getSuccessorInputs();
- for (BlockArgument argument : arguments) {
- // Visit blockArgument of RegionBranchOp which isn't "control
- // flow block arguments". For example, the IV of a loop.
- if (!llvm::is_contained(inputs, argument)) {
- noControlFlowArguments.push_back(argument);
- }
- }
+ for (Value arg : successor.getRegionNonforwardedArguments())
+ noControlFlowArguments.push_back(cast<BlockArgument>(arg));
visitNonControlFlowArguments(successor, noControlFlowArguments);
}
>From 11aa2ff6b7a9847c8d85779900aeed08961f9e39 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Sat, 10 Jan 2026 08:23:25 +0000
Subject: [PATCH 4/4] fix test.
---
mlir/include/mlir/Interfaces/ControlFlowInterfaces.h | 9 ++++++---
mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 6 ++----
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h b/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
index 76aa20f11d84b..c9af572a4ea8f 100644
--- a/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
+++ b/mlir/include/mlir/Interfaces/ControlFlowInterfaces.h
@@ -228,11 +228,14 @@ class RegionSuccessor {
/// the current region.
ValueRange getSuccessorInputs() const { return inputs; }
- ValueRange getRegionNonforwardedArguments() const {
+ /// If successor is a region, return the non-forwarded arguments of the
+ /// region. If successor is a operation, it don't have non-forwarded
+ /// arguments.
+ SmallVector<BlockArgument> getRegionNonForwardedArguments() const {
if (isParent())
return {};
- SmallVector<Value> nonForwardArguments;
- MutableArrayRef<BlockArgument> arguments = getSuccessor()->getArguments();
+ SmallVector<BlockArgument> nonForwardArguments;
+ SmallVector<BlockArgument> arguments(getSuccessor()->getArguments());
if (arguments.empty())
return {};
ValueRange inputs = getSuccessorInputs();
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index 97889415da31a..df3c230377a30 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -602,10 +602,8 @@ void AbstractSparseBackwardDataFlowAnalysis::visitRegionSuccessors(
for (RegionSuccessor &successor : successors) {
if (successor.isParent())
continue;
- SmallVector<BlockArgument> noControlFlowArguments;
- for (Value arg : successor.getRegionNonforwardedArguments())
- noControlFlowArguments.push_back(cast<BlockArgument>(arg));
- visitNonControlFlowArguments(successor, noControlFlowArguments);
+ visitNonControlFlowArguments(successor,
+ successor.getRegionNonForwardedArguments());
}
// All operands not forwarded to regions are typically parameters of the
More information about the Mlir-commits
mailing list