1 | //===- LoopCoalescing.cpp - Pass transforming loop nests into single loops-===// |
---|---|
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 | #include "mlir/Dialect/Affine/Passes.h" |
10 | |
11 | #include "mlir/Dialect/Affine/IR/AffineOps.h" |
12 | #include "mlir/Dialect/Affine/LoopUtils.h" |
13 | #include "mlir/Dialect/Arith/IR/Arith.h" |
14 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
15 | #include "mlir/Dialect/SCF/IR/SCF.h" |
16 | #include "mlir/Dialect/SCF/Utils/Utils.h" |
17 | #include "mlir/Transforms/Passes.h" |
18 | #include "mlir/Transforms/RegionUtils.h" |
19 | #include "llvm/Support/Debug.h" |
20 | |
21 | namespace mlir { |
22 | namespace affine { |
23 | #define GEN_PASS_DEF_LOOPCOALESCING |
24 | #include "mlir/Dialect/Affine/Passes.h.inc" |
25 | } // namespace affine |
26 | } // namespace mlir |
27 | |
28 | #define PASS_NAME "loop-coalescing" |
29 | #define DEBUG_TYPE PASS_NAME |
30 | |
31 | using namespace mlir; |
32 | using namespace mlir::affine; |
33 | |
34 | namespace { |
35 | struct LoopCoalescingPass |
36 | : public affine::impl::LoopCoalescingBase<LoopCoalescingPass> { |
37 | |
38 | void runOnOperation() override { |
39 | func::FuncOp func = getOperation(); |
40 | func.walk<WalkOrder::PreOrder>([](Operation *op) { |
41 | if (auto scfForOp = dyn_cast<scf::ForOp>(op)) |
42 | (void)coalescePerfectlyNestedSCFForLoops(scfForOp); |
43 | else if (auto affineForOp = dyn_cast<AffineForOp>(op)) |
44 | (void)coalescePerfectlyNestedAffineLoops(affineForOp); |
45 | }); |
46 | } |
47 | }; |
48 | |
49 | } // namespace |
50 | |
51 | std::unique_ptr<OperationPass<func::FuncOp>> |
52 | mlir::affine::createLoopCoalescingPass() { |
53 | return std::make_unique<LoopCoalescingPass>(); |
54 | } |
55 |