brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 5cc38f7 Raw
56 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a normalizer for affine loop-like ops.10//11//===----------------------------------------------------------------------===//12 13#include "mlir/Dialect/Affine/Passes.h"14 15#include "mlir/Dialect/Affine/IR/AffineOps.h"16#include "mlir/Dialect/Affine/Utils.h"17#include "mlir/Dialect/Func/IR/FuncOps.h"18 19namespace mlir {20namespace affine {21#define GEN_PASS_DEF_AFFINELOOPNORMALIZE22#include "mlir/Dialect/Affine/Passes.h.inc"23} // namespace affine24} // namespace mlir25 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 ops33/// that are already in a normalized form.34struct AffineLoopNormalizePass35    : 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} // namespace51 52std::unique_ptr<OperationPass<func::FuncOp>>53mlir::affine::createAffineLoopNormalizePass(bool promoteSingleIter) {54  return std::make_unique<AffineLoopNormalizePass>(promoteSingleIter);55}56