| 1 | //===- AffineScalarReplacement.cpp - Affine scalar replacement pass -------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements a pass to forward affine memref stores to loads, thereby |
| 10 | // potentially getting rid of intermediate memrefs entirely. It also removes |
| 11 | // redundant loads. |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "mlir/Dialect/Affine/Passes.h" |
| 15 | |
| 16 | #include "mlir/Analysis/AliasAnalysis.h" |
| 17 | #include "mlir/Dialect/Affine/Utils.h" |
| 18 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
| 19 | #include "mlir/IR/Dominance.h" |
| 20 | #include <algorithm> |
| 21 | |
| 22 | namespace mlir { |
| 23 | namespace affine { |
| 24 | #define GEN_PASS_DEF_AFFINESCALARREPLACEMENT |
| 25 | #include "mlir/Dialect/Affine/Passes.h.inc" |
| 26 | } // namespace affine |
| 27 | } // namespace mlir |
| 28 | |
| 29 | #define DEBUG_TYPE "affine-scalrep" |
| 30 | |
| 31 | using namespace mlir; |
| 32 | using namespace mlir::affine; |
| 33 | |
| 34 | namespace { |
| 35 | struct AffineScalarReplacement |
| 36 | : public affine::impl::AffineScalarReplacementBase< |
| 37 | AffineScalarReplacement> { |
| 38 | void runOnOperation() override; |
| 39 | }; |
| 40 | |
| 41 | } // namespace |
| 42 | |
| 43 | std::unique_ptr<OperationPass<func::FuncOp>> |
| 44 | mlir::affine::createAffineScalarReplacementPass() { |
| 45 | return std::make_unique<AffineScalarReplacement>(); |
| 46 | } |
| 47 | |
| 48 | void AffineScalarReplacement::runOnOperation() { |
| 49 | affineScalarReplace(getOperation(), getAnalysis<DominanceInfo>(), |
| 50 | getAnalysis<PostDominanceInfo>(), |
| 51 | getAnalysis<AliasAnalysis>()); |
| 52 | } |
| 53 | |