1 | //===- TestDecomposeAffineOps.cpp - Test affine ops decomposition utility -===// |
---|---|
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 pass to test affine data copy utility functions and |
10 | // options. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "mlir/Dialect/Affine/IR/AffineOps.h" |
15 | #include "mlir/Dialect/Affine/Transforms/Transforms.h" |
16 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
17 | #include "mlir/IR/PatternMatch.h" |
18 | #include "mlir/Pass/Pass.h" |
19 | #include "mlir/Transforms/Passes.h" |
20 | |
21 | #define PASS_NAME "test-decompose-affine-ops" |
22 | |
23 | using namespace mlir; |
24 | using namespace mlir::affine; |
25 | |
26 | namespace { |
27 | |
28 | struct TestDecomposeAffineOps |
29 | : public PassWrapper<TestDecomposeAffineOps, OperationPass<func::FuncOp>> { |
30 | MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestDecomposeAffineOps) |
31 | |
32 | StringRef getArgument() const final { return PASS_NAME; } |
33 | StringRef getDescription() const final { |
34 | return "Tests affine ops decomposition utility functions."; |
35 | } |
36 | TestDecomposeAffineOps() = default; |
37 | TestDecomposeAffineOps(const TestDecomposeAffineOps &pass) = default; |
38 | |
39 | void runOnOperation() override; |
40 | }; |
41 | |
42 | } // namespace |
43 | |
44 | void TestDecomposeAffineOps::runOnOperation() { |
45 | IRRewriter rewriter(&getContext()); |
46 | this->getOperation().walk([&](AffineApplyOp op) { |
47 | rewriter.setInsertionPoint(op); |
48 | reorderOperandsByHoistability(rewriter, op); |
49 | (void)decompose(rewriter, op); |
50 | }); |
51 | } |
52 | |
53 | namespace mlir { |
54 | void registerTestDecomposeAffineOpPass() { |
55 | PassRegistration<TestDecomposeAffineOps>(); |
56 | } |
57 | } // namespace mlir |
58 |