MLIR 22.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
19namespace mlir {
20namespace affine {
21#define GEN_PASS_DEF_AFFINELOOPNORMALIZE
22#include "mlir/Dialect/Affine/Passes.h.inc"
23} // namespace affine
24} // namespace mlir
25
26using namespace mlir;
27using namespace mlir::affine;
28
29namespace {
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.
34struct 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
52std::unique_ptr<OperationPass<func::FuncOp>>
54 return std::make_unique<AffineLoopNormalizePass>(promoteSingleIter);
55}
std::unique_ptr< OperationPass< func::FuncOp > > createAffineLoopNormalizePass(bool promoteSingleIter=false)
Apply normalization transformations to affine loop-like ops.
Include the generated interface declarations.