Skip to content

Commit 5d49511

Browse files
qacobondhugula
authored andcommitted
Apply the permutation map on each affine nest
When using -test-loop-permutation="permutation-map=...", applies the permutation map on each affine nest in the function (and not only the first one). If the size of the permutation map and the size of a nest are not consistent, do nothing on this particular nest (instead of making MLIR crash). Differential Revision: https://reviews.llvm.org/D112947
1 parent 79d3132 commit 5d49511

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

mlir/test/lib/Dialect/Affine/TestLoopPermutation.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,22 @@ struct TestLoopPermutation
4747
} // end anonymous namespace
4848

4949
void TestLoopPermutation::runOnFunction() {
50-
// Get the first maximal perfect nest.
51-
SmallVector<AffineForOp, 6> nest;
52-
for (auto &op : getFunction().front()) {
53-
if (auto forOp = dyn_cast<AffineForOp>(op)) {
54-
getPerfectlyNestedLoops(nest, forOp);
55-
break;
56-
}
57-
}
58-
59-
// Nothing to do.
60-
if (nest.size() < 2)
61-
return;
6250

6351
SmallVector<unsigned, 4> permMap(permList.begin(), permList.end());
64-
permuteLoops(nest, permMap);
52+
53+
SmallVector<AffineForOp, 2> forOps;
54+
getFunction().walk([&](AffineForOp forOp) { forOps.push_back(forOp); });
55+
56+
for (auto forOp : forOps) {
57+
SmallVector<AffineForOp, 6> nest;
58+
// Get the maximal perfect nest.
59+
getPerfectlyNestedLoops(nest, forOp);
60+
// Permute if the nest's size is consistent with the specified
61+
// permutation.
62+
if (nest.size() >= 2 && nest.size() == permMap.size()) {
63+
permuteLoops(nest, permMap);
64+
}
65+
}
6566
}
6667

6768
namespace mlir {

0 commit comments

Comments
 (0)