xref: /llvm-project/mlir/lib/Dialect/Affine/Transforms/AffineLoopNormalize.cpp (revision 039b969b32b64b64123dce30dd28ec4e343d893f)
1 //===- AffineLoopNormalize.cpp - AffineLoopNormalize 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 normalizer for affine loop-like ops.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "PassDetail.h"
14 #include "mlir/Dialect/Affine/IR/AffineOps.h"
15 #include "mlir/Dialect/Affine/Passes.h"
16 #include "mlir/Dialect/Affine/Utils.h"
17 
18 using namespace mlir;
19 
20 namespace {
21 
22 /// Normalize affine.parallel ops so that lower bounds are 0 and steps are 1.
23 /// As currently implemented, this pass cannot fail, but it might skip over ops
24 /// that are already in a normalized form.
25 struct AffineLoopNormalizePass
26     : public AffineLoopNormalizeBase<AffineLoopNormalizePass> {
27 
28   void runOnOperation() override {
29     getOperation().walk([](Operation *op) {
30       if (auto affineParallel = dyn_cast<AffineParallelOp>(op))
31         normalizeAffineParallel(affineParallel);
32       else if (auto affineFor = dyn_cast<AffineForOp>(op))
33         (void)normalizeAffineFor(affineFor);
34     });
35   }
36 };
37 
38 } // namespace
39 
40 std::unique_ptr<OperationPass<func::FuncOp>>
41 mlir::createAffineLoopNormalizePass() {
42   return std::make_unique<AffineLoopNormalizePass>();
43 }
44