Skip to content

Commit 9e9093f

Browse files
author
Shay Kleiman
committed
[mlir][scf] Expose isPerfectlyNestedForLoops
1 parent e0df5f8 commit 9e9093f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ FailureOr<scf::SCFTilingResult>
364364
tileReductionUsingScf(RewriterBase &b, PartialReductionOpInterface op,
365365
ArrayRef<OpFoldResult> tileSizes);
366366

367+
/// Check if the provided loops are perfectly nested for-loops. Perfect nesting
368+
/// means:
369+
/// 1. All loops are scf.for operations
370+
/// 2. Each outer loop's region iter args match the inner loop's init args
371+
/// 3. Each outer loop's yields match the inner loop's results
372+
/// 4. Each region iter arg and result has exactly one use
373+
bool isPerfectlyNestedForLoops(MutableArrayRef<LoopLikeOpInterface> loops);
374+
367375
} // namespace scf
368376
} // namespace mlir
369377

mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,8 +1927,8 @@ static FailureOr<OpOperand *> getConsumerFromLoopUses(RewriterBase &rewriter,
19271927
/// yield %1
19281928
/// ```
19291929
/// Here loops should be [%0, %1].
1930-
static bool
1931-
isPerfectlyNestedForLoops(MutableArrayRef<LoopLikeOpInterface> loops) {
1930+
bool mlir::scf::isPerfectlyNestedForLoops(
1931+
MutableArrayRef<LoopLikeOpInterface> loops) {
19321932
assert(!loops.empty() && "unexpected empty loop nest");
19331933
if (loops.size() == 1) {
19341934
return isa_and_nonnull<scf::ForOp>(loops.front().getOperation());
@@ -1991,7 +1991,7 @@ getUntiledConsumerFromSlice(RewriterBase &rewriter,
19911991
}
19921992

19931993
// 2. Check that the loop is perfectly nested.
1994-
if (!isPerfectlyNestedForLoops(loops)) {
1994+
if (!mlir::scf::isPerfectlyNestedForLoops(loops)) {
19951995
return rewriter.notifyMatchFailure(
19961996
candidateSliceOp, "expected passed loops to be perfectly nested.");
19971997
}

0 commit comments

Comments
 (0)