-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[mlir][scf] Expose isPerfectlyNestedForLoops #152115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][scf] Expose isPerfectlyNestedForLoops #152115
Conversation
@llvm/pr-subscribers-mlir-scf @llvm/pr-subscribers-mlir Author: Shay Kleiman (shay-kl) ChangesFull diff: https://github.com/llvm/llvm-project/pull/152115.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h b/mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h
index 3205da6e448fc..1177aee560f6a 100644
--- a/mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h
+++ b/mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h
@@ -364,6 +364,14 @@ FailureOr<scf::SCFTilingResult>
tileReductionUsingScf(RewriterBase &b, PartialReductionOpInterface op,
ArrayRef<OpFoldResult> tileSizes);
+/// Check if the provided loops are perfectly nested for-loops. Perfect nesting
+/// means:
+/// 1. All loops are scf.for operations
+/// 2. Each outer loop's region iter args match the inner loop's init args
+/// 3. Each outer loop's yields match the inner loop's results
+/// 4. Each region iter arg and result has exactly one use
+bool isPerfectlyNestedForLoops(MutableArrayRef<LoopLikeOpInterface> loops);
+
} // namespace scf
} // namespace mlir
diff --git a/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp b/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
index c0e47ee1e74fc..0a717de3bda0d 100644
--- a/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
@@ -1927,8 +1927,7 @@ static FailureOr<OpOperand *> getConsumerFromLoopUses(RewriterBase &rewriter,
/// yield %1
/// ```
/// Here loops should be [%0, %1].
-static bool
-isPerfectlyNestedForLoops(MutableArrayRef<LoopLikeOpInterface> loops) {
+bool mlir::scf::isPerfectlyNestedForLoops(MutableArrayRef<LoopLikeOpInterface> loops) {
assert(!loops.empty() && "unexpected empty loop nest");
if (loops.size() == 1) {
return isa_and_nonnull<scf::ForOp>(loops.front().getOperation());
@@ -1991,7 +1990,7 @@ getUntiledConsumerFromSlice(RewriterBase &rewriter,
}
// 2. Check that the loop is perfectly nested.
- if (!isPerfectlyNestedForLoops(loops)) {
+ if (!mlir::scf::isPerfectlyNestedForLoops(loops)) {
return rewriter.notifyMatchFailure(
candidateSliceOp, "expected passed loops to be perfectly nested.");
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
5aa8d01
to
9e9093f
Compare
Ping |
Hi @shay-kl - if the utility has to be moved/exposed, I'd rather it be done as part of https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/SCF/Utils/Utils.h instead. |
Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
The function isPerfectlyNestedForLoops is useful on its own and so I'm exposing it for downstream use.