2019-04-17 12:18:37 -07:00
|
|
|
//===- LoopInvariantCodeMotion.cpp - Code to perform loop fusion-----------===//
|
|
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-04-17 12:18:37 -07:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-04-17 12:18:37 -07:00
|
|
|
//
|
|
|
|
|
// This file implements loop invariant code motion.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-08-30 22:20:36 +02:00
|
|
|
#include "PassDetail.h"
|
2020-03-14 13:36:42 -07:00
|
|
|
#include "mlir/Interfaces/LoopLikeInterface.h"
|
2022-04-16 00:36:22 +00:00
|
|
|
#include "mlir/Transforms/LoopInvariantCodeMotionUtils.h"
|
2022-08-30 22:20:36 +02:00
|
|
|
#include "mlir/Transforms/Passes.h"
|
2022-04-16 00:36:22 +00:00
|
|
|
#include "mlir/Transforms/SideEffectUtils.h"
|
2019-04-17 12:18:37 -07:00
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
/// Loop invariant code motion (LICM) pass.
|
2022-08-30 22:20:36 +02:00
|
|
|
struct LoopInvariantCodeMotion
|
|
|
|
|
: public LoopInvariantCodeMotionBase<LoopInvariantCodeMotion> {
|
2019-10-16 04:28:13 -07:00
|
|
|
void runOnOperation() override;
|
2019-04-17 12:18:37 -07:00
|
|
|
};
|
2021-12-07 18:27:58 +00:00
|
|
|
} // namespace
|
2019-04-17 12:18:37 -07:00
|
|
|
|
2022-08-30 22:20:36 +02:00
|
|
|
void LoopInvariantCodeMotion::runOnOperation() {
|
2019-10-16 04:28:13 -07:00
|
|
|
// Walk through all loops in a function in innermost-loop-first order. This
|
2019-05-11 08:28:15 -07:00
|
|
|
// way, we first LICM from the inner loop, and place the ops in
|
|
|
|
|
// the outer loop, which in turn can be further LICM'ed.
|
2022-04-16 00:36:22 +00:00
|
|
|
getOperation()->walk(
|
|
|
|
|
[&](LoopLikeOpInterface loopLike) { moveLoopInvariantCode(loopLike); });
|
2019-04-17 12:18:37 -07:00
|
|
|
}
|
2022-08-30 22:20:36 +02:00
|
|
|
|
|
|
|
|
std::unique_ptr<Pass> mlir::createLoopInvariantCodeMotionPass() {
|
|
|
|
|
return std::make_unique<LoopInvariantCodeMotion>();
|
|
|
|
|
}
|