aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
diff options
context:
space:
mode:
authorChris Lattner <clattner@google.com>2019-05-11 08:28:15 -0700
committerMehdi Amini <joker.eph@gmail.com>2019-05-20 13:36:17 -0700
commit0134b5df3a00018f7db2a0ee5be6c4abf9bee4b2 (patch)
tree6ef2be0983de121801a53540cb8ac7b0819acff3 /mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
parentecd4c7d67af8d167c51fbd86dbfcfca5bbc22102 (diff)
downloadllvm-0134b5df3a00018f7db2a0ee5be6c4abf9bee4b2.zip
llvm-0134b5df3a00018f7db2a0ee5be6c4abf9bee4b2.tar.gz
llvm-0134b5df3a00018f7db2a0ee5be6c4abf9bee4b2.tar.bz2
Cleanups and simplifications to code, noticed by inspection. NFC.
-- PiperOrigin-RevId: 247758075
Diffstat (limited to 'mlir/lib/Transforms/LoopInvariantCodeMotion.cpp')
-rw-r--r--mlir/lib/Transforms/LoopInvariantCodeMotion.cpp24
1 files changed, 7 insertions, 17 deletions
diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
index b03a3c7..2f95db9 100644
--- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
+++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
@@ -19,9 +19,6 @@
//
//===----------------------------------------------------------------------===//
-#include <iomanip>
-#include <sstream>
-
#include "mlir/AffineOps/AffineOps.h"
#include "mlir/Analysis/AffineAnalysis.h"
#include "mlir/Analysis/AffineStructures.h"
@@ -57,7 +54,6 @@ namespace {
struct LoopInvariantCodeMotion : public FunctionPass<LoopInvariantCodeMotion> {
void runOnFunction() override;
void runOnAffineForOp(AffineForOp forOp);
- std::vector<AffineForOp> forOps;
};
} // end anonymous namespace
@@ -81,7 +77,7 @@ void LoopInvariantCodeMotion::runOnAffineForOp(AffineForOp forOp) {
LLVM_DEBUG(for (auto i
: loopDefinedOps) {
- (i->print(llvm::dbgs() << "\nLoop-dependent op\n"));
+ i->print(llvm::dbgs() << "\nLoop-dependent op\n");
});
for (auto &op : *loopBody) {
@@ -109,20 +105,14 @@ void LoopInvariantCodeMotion::runOnAffineForOp(AffineForOp forOp) {
}
void LoopInvariantCodeMotion::runOnFunction() {
- forOps.clear();
-
- // Gather all loops in a function, and order them in innermost-loop-first
- // order. This way, we first LICM from the inner loop, and place the ops in
- // the outer loop, which in turn can be further LICM'ed. This saves iterating
- // on the inner loop operations while LICMing through the outer loop.
- getFunction().walk<AffineForOp>(
- [&](AffineForOp forOp) { forOps.push_back(forOp); });
- // We gather loops first, and then go over them later because we don't want to
- // mess the iterators up.
- for (auto op : forOps) {
+
+ // Walk through all loops in a function in innermost-loop-first order. This
+ // way, we first LICM from the inner loop, and place the ops in
+ // the outer loop, which in turn can be further LICM'ed.
+ getFunction().walk<AffineForOp>([&](AffineForOp op) {
LLVM_DEBUG(op.getOperation()->print(llvm::dbgs() << "\nOriginal loop\n"));
runOnAffineForOp(op);
- }
+ });
}
static PassRegistration<LoopInvariantCodeMotion>