diff options
author | Matthias Springer <me@m-sp.org> | 2023-11-01 10:57:17 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-01 10:57:17 +0900 |
commit | 2164a449dc7a9daf610b789ba0ec7d1eca7305ef (patch) | |
tree | 3abae6dbe6ec18ee4e50b8160549bf4721718687 /mlir/lib/Transforms/LoopInvariantCodeMotion.cpp | |
parent | 1abd8d1a8d962a14ca96e19c0f6da4f9ac394d0a (diff) | |
download | llvm-2164a449dc7a9daf610b789ba0ec7d1eca7305ef.zip llvm-2164a449dc7a9daf610b789ba0ec7d1eca7305ef.tar.gz llvm-2164a449dc7a9daf610b789ba0ec7d1eca7305ef.tar.bz2 |
[mlir][Transforms] Add loop-invariant subset hoisting (LISH) transformation (#70619)
Add a loop-invariant subset hoisting pass to `mlir/Interfaces`. This
pass hoist loop-invariant tensor subsets (subset extraction and subset
insertion ops) from loop-like ops. Extraction ops are moved before the
loop. Insertion ops are moved after the loop. The loop body operates on
newly added region iter_args (one per extraction-insertion pair).
This new pass will be improved in subsequent commits (to support more
cases/ops) and will eventually replace
`Linalg/Transforms/SubsetHoisting.cpp`. In contrast to the existing
Linalg subset hoisting, the new pass is op interface-based
(`SubsetOpInterface` and `LoopLikeOpInterface`).
Diffstat (limited to 'mlir/lib/Transforms/LoopInvariantCodeMotion.cpp')
-rw-r--r-- | mlir/lib/Transforms/LoopInvariantCodeMotion.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp index 854fde0..e6d8af8 100644 --- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp +++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp @@ -18,6 +18,7 @@ namespace mlir { #define GEN_PASS_DEF_LOOPINVARIANTCODEMOTION +#define GEN_PASS_DEF_LOOPINVARIANTSUBSETHOISTING #include "mlir/Transforms/Passes.h.inc" } // namespace mlir @@ -29,6 +30,12 @@ struct LoopInvariantCodeMotion : public impl::LoopInvariantCodeMotionBase<LoopInvariantCodeMotion> { void runOnOperation() override; }; + +struct LoopInvariantSubsetHoisting + : public impl::LoopInvariantSubsetHoistingBase< + LoopInvariantSubsetHoisting> { + void runOnOperation() override; +}; } // namespace void LoopInvariantCodeMotion::runOnOperation() { @@ -39,6 +46,19 @@ void LoopInvariantCodeMotion::runOnOperation() { [&](LoopLikeOpInterface loopLike) { moveLoopInvariantCode(loopLike); }); } +void LoopInvariantSubsetHoisting::runOnOperation() { + // Walk through all loops in a function in innermost-loop-first order. This + // way, we first hoist from the inner loop, and place the ops in the outer + // loop, which in turn can be further hoisted from. + getOperation()->walk([&](LoopLikeOpInterface loopLike) { + (void)hoistLoopInvariantSubsets(loopLike); + }); +} + std::unique_ptr<Pass> mlir::createLoopInvariantCodeMotionPass() { return std::make_unique<LoopInvariantCodeMotion>(); } + +std::unique_ptr<Pass> mlir::createLoopInvariantSubsetHoistingPass() { + return std::make_unique<LoopInvariantSubsetHoisting>(); +} |