[mlir][Linalg] Cleanup the drop unit dims pass in Linalg.
authorMahesh Ravishankar <ravishankarm@google.com>
Wed, 19 Jul 2023 04:58:26 +0000 (04:58 +0000)
committerMahesh Ravishankar <ravishankarm@google.com>
Wed, 19 Jul 2023 17:47:18 +0000 (17:47 +0000)
commit67399932c767f0a64c83a500dc6f7806c09d9401
tree2e2174c6562414ba7e0b1f5dff5222d10f72b848
parent645f6dcd69a5315dbe2a6b49fdd8d356512544e8
[mlir][Linalg] Cleanup the drop unit dims pass in Linalg.

TL;DR the following API functions have been merged

```
void populateFoldUnitExtentDimsViaReshapesPatterns(RewritePatternSet &patterns);
void populateFoldUnitExtentDimsViaSlicesPatterns(RewritePatternSet &patterns);
```

into

```
void populateFoldUnitExtentDimsPatterns(RewritePatternSet &patterns,
                                        ControlDropUnitDims &options);
```

To use the previous functionality use

```
ControlDropUnitDims options;
// By default options.rankReductionStrategy is
// ControlDropUnitDims::RankReductionStrategy::ReassociativeReshape.
populateFoldUnitExtentDimsPatterns(patterns, options);
```

and

```
ControlDropUnitDims options;
options.rankReductionStrategy = ControlDropUnitDims::RankReductionStrategy::ExtractInsertSlice
populateFoldUnitExtentDimsPatterns(patterns, options);

```

This pass is quite old and needed to be updated based on the current
approach to transformations in Linalg

- Instead of two patterns, one to just remove loop dimensions that are
  unit extent (and using 0 in the indexing maps), and another to drop
  the unit-extents in the operand shapes, combine into a single
  transformation. This avoid creating an intermediate step with
  indexing maps having 0's in the domains exp ressions.

- Expose the core transformation as a utility function and add a
  pattern that calls this transformation.

This is a mostly NFC change, apart from the API change and dropping
the patterns/test that only dropped the loops that are unit extents.

Differential Revision: https://reviews.llvm.org/D155518
mlir/include/mlir/Dialect/Linalg/Passes.td
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
mlir/lib/Dialect/Linalg/Transforms/DropUnitDims.cpp
mlir/test/Dialect/Linalg/drop-unit-extent-dims.mlir
mlir/test/Dialect/Linalg/fold-unit-trip-loops.mlir [deleted file]
mlir/test/Dialect/Linalg/test-drop-unit-dims.mlir [new file with mode: 0644]
mlir/test/lib/Dialect/Linalg/CMakeLists.txt
mlir/test/lib/Dialect/Linalg/TestLinalgDropUnitDims.cpp [new file with mode: 0644]
mlir/tools/mlir-opt/mlir-opt.cpp