diff options
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>(); +} |