MLIR  20.0.0git
AffineLoopNormalize.cpp
Go to the documentation of this file.
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 
14 
18 
19 namespace mlir {
20 namespace affine {
21 #define GEN_PASS_DEF_AFFINELOOPNORMALIZE
22 #include "mlir/Dialect/Affine/Passes.h.inc"
23 } // namespace affine
24 } // namespace mlir
25 
26 using namespace mlir;
27 using namespace mlir::affine;
28 
29 namespace {
30 
31 /// Normalize affine.parallel ops so that lower bounds are 0 and steps are 1.
32 /// As currently implemented, this pass cannot fail, but it might skip over ops
33 /// that are already in a normalized form.
34 struct AffineLoopNormalizePass
35  : public affine::impl::AffineLoopNormalizeBase<AffineLoopNormalizePass> {
36  explicit AffineLoopNormalizePass(bool promoteSingleIter) {
37  this->promoteSingleIter = promoteSingleIter;
38  }
39 
40  void runOnOperation() override {
41  getOperation().walk([&](Operation *op) {
42  if (auto affineParallel = dyn_cast<AffineParallelOp>(op))
43  normalizeAffineParallel(affineParallel);
44  else if (auto affineFor = dyn_cast<AffineForOp>(op))
45  (void)normalizeAffineFor(affineFor, promoteSingleIter);
46  });
47  }
48 };
49 
50 } // namespace
51 
52 std::unique_ptr<OperationPass<func::FuncOp>>
54  return std::make_unique<AffineLoopNormalizePass>(promoteSingleIter);
55 }
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
void normalizeAffineParallel(AffineParallelOp op)
Normalize a affine.parallel op so that lower bounds are 0 and steps are 1.
Definition: Utils.cpp:492
std::unique_ptr< OperationPass< func::FuncOp > > createAffineLoopNormalizePass(bool promoteSingleIter=false)
Apply normalization transformations to affine loop-like ops.
LogicalResult normalizeAffineFor(AffineForOp op, bool promoteSingleIter=false)
Normalize an affine.for op.
Definition: Utils.cpp:556
Include the generated interface declarations.