MLIR  20.0.0git
LoopCoalescing.cpp
Go to the documentation of this file.
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 
10 
17 #include "mlir/Transforms/Passes.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>>
53  return std::make_unique<LoopCoalescingPass>();
54 }
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
std::unique_ptr< OperationPass< func::FuncOp > > createLoopCoalescingPass()
Creates a pass that transforms perfectly nested loops with independent bounds into a single loop.
LogicalResult coalescePerfectlyNestedAffineLoops(AffineForOp op)
Walk an affine.for to find a band to coalesce.
Definition: LoopUtils.cpp:2739
Include the generated interface declarations.
LogicalResult coalescePerfectlyNestedSCFForLoops(scf::ForOp op)
Walk an affine.for to find a band to coalesce.
Definition: Utils.cpp:986