|
1 |
| -//===- AffineParallelNormalize.cpp - AffineParallelNormalize Pass ---------===// |
| 1 | +//===- AffineLoopNormalize.cpp - AffineLoopNormalize Pass -----------------===// |
2 | 2 | //
|
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
4 | 4 | // See https://llvm.org/LICENSE.txt for license information.
|
5 | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 | //
|
9 |
| -// This file implements a normalizer for affine parallel loops. |
| 9 | +// This file implements a normalizer for affine loop-like ops. |
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "PassDetail.h"
|
14 | 14 | #include "mlir/Dialect/Affine/IR/AffineOps.h"
|
15 | 15 | #include "mlir/Dialect/Affine/IR/AffineValueMap.h"
|
16 | 16 | #include "mlir/Dialect/Affine/Passes.h"
|
| 17 | +#include "mlir/Dialect/Affine/Utils.h" |
17 | 18 | #include "mlir/IR/PatternMatch.h"
|
| 19 | +#include "mlir/Transforms/LoopUtils.h" |
18 | 20 |
|
19 | 21 | using namespace mlir;
|
20 | 22 |
|
21 |
| -void normalizeAffineParallel(AffineParallelOp op) { |
| 23 | +void mlir::normalizeAffineParallel(AffineParallelOp op) { |
22 | 24 | AffineMap lbMap = op.lowerBoundsMap();
|
23 | 25 | SmallVector<int64_t, 8> steps = op.getSteps();
|
24 | 26 | // No need to do any work if the parallel op is already normalized.
|
@@ -77,20 +79,36 @@ void normalizeAffineParallel(AffineParallelOp op) {
|
77 | 79 | op.setUpperBounds(ranges.getOperands(), newUpperMap);
|
78 | 80 | }
|
79 | 81 |
|
| 82 | +/// Normalization transformations for affine.for ops. For now, it only removes |
| 83 | +/// single iteration loops. We may want to consider separating redundant loop |
| 84 | +/// elimitation from loop bound normalization, if needed in the future. |
| 85 | +static void normalizeAffineFor(AffineForOp op) { |
| 86 | + if (succeeded(promoteIfSingleIteration(op))) |
| 87 | + return; |
| 88 | + |
| 89 | + // TODO: Normalize loop bounds. |
| 90 | +} |
| 91 | + |
80 | 92 | namespace {
|
81 | 93 |
|
82 | 94 | /// Normalize affine.parallel ops so that lower bounds are 0 and steps are 1.
|
83 | 95 | /// As currently implemented, this pass cannot fail, but it might skip over ops
|
84 | 96 | /// that are already in a normalized form.
|
85 |
| -struct AffineParallelNormalizePass |
86 |
| - : public AffineParallelNormalizeBase<AffineParallelNormalizePass> { |
| 97 | +struct AffineLoopNormalizePass |
| 98 | + : public AffineLoopNormalizeBase<AffineLoopNormalizePass> { |
87 | 99 |
|
88 |
| - void runOnFunction() override { getFunction().walk(normalizeAffineParallel); } |
| 100 | + void runOnFunction() override { |
| 101 | + getFunction().walk([](Operation *op) { |
| 102 | + if (auto affineParallel = dyn_cast<AffineParallelOp>(op)) |
| 103 | + normalizeAffineParallel(affineParallel); |
| 104 | + else if (auto affineFor = dyn_cast<AffineForOp>(op)) |
| 105 | + normalizeAffineFor(affineFor); |
| 106 | + }); |
| 107 | + } |
89 | 108 | };
|
90 | 109 |
|
91 | 110 | } // namespace
|
92 | 111 |
|
93 |
| -std::unique_ptr<OperationPass<FuncOp>> |
94 |
| -mlir::createAffineParallelNormalizePass() { |
95 |
| - return std::make_unique<AffineParallelNormalizePass>(); |
| 112 | +std::unique_ptr<OperationPass<FuncOp>> mlir::createAffineLoopNormalizePass() { |
| 113 | + return std::make_unique<AffineLoopNormalizePass>(); |
96 | 114 | }
|
0 commit comments