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 // TODO: In the future, similar techniques could be used to eliminate 13 // dead memref store's and perform more complex forwarding when support for 14 // SSA scalars live out of 'affine.for'/'affine.if' statements is available. 15 //===----------------------------------------------------------------------===// 16 17 #include "mlir/Dialect/Affine/Passes.h" 18 19 #include "PassDetail.h" 20 #include "mlir/Dialect/Affine/Utils.h" 21 #include "mlir/IR/Dominance.h" 22 #include "mlir/Support/LogicalResult.h" 23 #include <algorithm> 24 25 #define DEBUG_TYPE "affine-scalrep" 26 27 using namespace mlir; 28 29 namespace { 30 struct AffineScalarReplacement 31 : public AffineScalarReplacementBase<AffineScalarReplacement> { 32 void runOnOperation() override; 33 }; 34 35 } // namespace 36 37 std::unique_ptr<OperationPass<func::FuncOp>> createAffineScalarReplacementPass()38mlir::createAffineScalarReplacementPass() { 39 return std::make_unique<AffineScalarReplacement>(); 40 } 41 runOnOperation()42void AffineScalarReplacement::runOnOperation() { 43 affineScalarReplace(getOperation(), getAnalysis<DominanceInfo>(), 44 getAnalysis<PostDominanceInfo>()); 45 } 46