[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / unittests / IR / InterfaceTest.cpp
blob5ab4d9a106231a1e7ac7fae171ab30e7b98c2eb8
1 //===- InterfaceTest.cpp - Test interfaces --------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "mlir/IR/BuiltinAttributes.h"
10 #include "mlir/IR/BuiltinDialect.h"
11 #include "mlir/IR/BuiltinOps.h"
12 #include "mlir/IR/BuiltinTypes.h"
13 #include "mlir/IR/OwningOpRef.h"
14 #include "gtest/gtest.h"
16 #include "../../test/lib/Dialect/Test/TestAttributes.h"
17 #include "../../test/lib/Dialect/Test/TestDialect.h"
18 #include "../../test/lib/Dialect/Test/TestTypes.h"
20 using namespace mlir;
21 using namespace test;
23 TEST(InterfaceTest, OpInterfaceDenseMapKey) {
24 MLIRContext context;
25 context.loadDialect<test::TestDialect>();
27 OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context));
28 OpBuilder builder(module->getBody(), module->getBody()->begin());
29 auto op1 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(),
30 builder.getI32Type());
31 auto op2 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(),
32 builder.getI32Type());
33 auto op3 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(),
34 builder.getI32Type());
35 DenseSet<MemoryEffectOpInterface> opSet;
36 opSet.insert(op1);
37 opSet.insert(op2);
38 opSet.erase(op1);
39 EXPECT_FALSE(opSet.contains(op1));
40 EXPECT_TRUE(opSet.contains(op2));
41 EXPECT_FALSE(opSet.contains(op3));
44 TEST(InterfaceTest, TypeInterfaceDenseMapKey) {
45 MLIRContext context;
46 context.loadDialect<test::TestDialect>();
48 OpBuilder builder(&context);
49 DenseSet<DataLayoutTypeInterface> typeSet;
50 auto type1 = builder.getType<test::TestTypeWithLayoutType>(1);
51 auto type2 = builder.getType<test::TestTypeWithLayoutType>(2);
52 auto type3 = builder.getType<test::TestTypeWithLayoutType>(3);
53 typeSet.insert(type1);
54 typeSet.insert(type2);
55 typeSet.erase(type1);
56 EXPECT_FALSE(typeSet.contains(type1));
57 EXPECT_TRUE(typeSet.contains(type2));
58 EXPECT_FALSE(typeSet.contains(type3));
61 TEST(InterfaceTest, TestCustomClassOf) {
62 MLIRContext context;
63 context.loadDialect<test::TestDialect>();
65 OpBuilder builder(&context);
66 auto op = builder.create<TestOpOptionallyImplementingInterface>(
67 builder.getUnknownLoc(), /*implementsInterface=*/true);
68 EXPECT_TRUE(isa<TestOptionallyImplementedOpInterface>(*op));
69 op.setImplementsInterface(false);
70 EXPECT_FALSE(isa<TestOptionallyImplementedOpInterface>(*op));
71 op.erase();
74 TEST(InterfaceTest, TestImplicitConversion) {
75 MLIRContext context;
76 context.loadDialect<test::TestDialect>();
78 TestBaseTypeInterfacePrintTypeB typeB;
79 TestBaseTypeInterfacePrintTypeA typeA = typeB;
80 EXPECT_EQ(typeA, nullptr);
82 typeB = TestType::get(&context);
83 typeA = typeB;
84 EXPECT_EQ(typeA, typeB);