1 | //===- TestInterfaces.cpp - Test interface generation and application -----===// |
---|---|
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 "TestTypes.h" |
10 | #include "mlir/IR/BuiltinOps.h" |
11 | #include "mlir/Pass/Pass.h" |
12 | |
13 | using namespace mlir; |
14 | using namespace test; |
15 | |
16 | namespace { |
17 | /// This test checks various aspects of Type interface generation and |
18 | /// application. |
19 | struct TestTypeInterfaces |
20 | : public PassWrapper<TestTypeInterfaces, OperationPass<ModuleOp>> { |
21 | MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTypeInterfaces) |
22 | |
23 | StringRef getArgument() const final { return "test-type-interfaces"; } |
24 | StringRef getDescription() const final { |
25 | return "Test type interface support."; |
26 | } |
27 | void runOnOperation() override { |
28 | getOperation().walk([](Operation *op) { |
29 | for (Type type : op->getResultTypes()) { |
30 | if (auto testInterface = dyn_cast<TestTypeInterface>(type)) { |
31 | testInterface.printTypeA(op->getLoc()); |
32 | testInterface.printTypeB(op->getLoc()); |
33 | testInterface.printTypeC(op->getLoc()); |
34 | testInterface.printTypeD(op->getLoc()); |
35 | // Just check that we can assign the result to a variable of interface |
36 | // type. |
37 | TestTypeInterface result = testInterface.printTypeRet(op->getLoc()); |
38 | (void)result; |
39 | } |
40 | if (auto testType = dyn_cast<TestType>(type)) |
41 | testType.printTypeE(op->getLoc()); |
42 | } |
43 | }); |
44 | } |
45 | }; |
46 | } // namespace |
47 | |
48 | namespace mlir { |
49 | namespace test { |
50 | void registerTestInterfaces() { PassRegistration<TestTypeInterfaces>(); } |
51 | } // namespace test |
52 | } // namespace mlir |
53 |