1 | //===- TestShapeMappingInfo.cpp -------------------------------------------===// |
---|---|
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 | #include "mlir/Dialect/Shape/Analysis/ShapeMappingAnalysis.h" |
10 | #include "mlir/IR/BuiltinOps.h" |
11 | #include "mlir/Pass/Pass.h" |
12 | #include <optional> |
13 | |
14 | using namespace mlir; |
15 | |
16 | namespace { |
17 | |
18 | struct TestShapeMappingPass |
19 | : public PassWrapper<TestShapeMappingPass, OperationPass<ModuleOp>> { |
20 | MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestShapeMappingPass) |
21 | |
22 | StringRef getArgument() const final { return "test-print-shape-mapping"; } |
23 | StringRef getDescription() const final { |
24 | return "Print the contents of a constructed shape mapping information."; |
25 | } |
26 | void runOnOperation() override { |
27 | std::optional<std::reference_wrapper<shape::ShapeMappingAnalysis>> |
28 | maybeAnalysis = getCachedAnalysis<shape::ShapeMappingAnalysis>(); |
29 | if (maybeAnalysis.has_value()) |
30 | maybeAnalysis->get().print(os&: llvm::errs()); |
31 | else |
32 | llvm::errs() << "No cached ShapeMappingAnalysis existed."; |
33 | } |
34 | }; |
35 | |
36 | } // namespace |
37 | |
38 | namespace mlir { |
39 | namespace test { |
40 | void registerTestShapeMappingPass() { |
41 | PassRegistration<TestShapeMappingPass>(); |
42 | } |
43 | } // namespace test |
44 | } // namespace mlir |
45 |