[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / mlir / unittests / IR / AdaptorTest.cpp
blob66ce53bbbadec980da7cbab7745f8eb56c0bf5b2
1 //===- AdaptorTest.cpp - Adaptor unit tests -------------------------------===//
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 "../../test/lib/Dialect/Test/TestDialect.h"
10 #include "../../test/lib/Dialect/Test/TestOpsSyntax.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
15 using namespace mlir;
16 using namespace test;
18 using testing::ElementsAre;
20 TEST(Adaptor, GenericAdaptorsOperandAccess) {
21 MLIRContext context;
22 context.loadDialect<test::TestDialect>();
23 Builder builder(&context);
25 // Has normal and Variadic arguments.
26 MixedNormalVariadicOperandOp::FoldAdaptor a({});
28 SmallVector<int> v = {0, 1, 2, 3, 4};
29 MixedNormalVariadicOperandOp::GenericAdaptor<ArrayRef<int>> b(v);
30 EXPECT_THAT(b.getInput1(), ElementsAre(0, 1));
31 EXPECT_EQ(b.getInput2(), 2);
32 EXPECT_THAT(b.getInput3(), ElementsAre(3, 4));
35 // Has optional arguments.
36 OIListSimple::FoldAdaptor c({}, nullptr);
38 // Optional arguments return the default constructed value if not present.
39 // Using optional instead of plain int here to differentiate absence of
40 // value from the value 0.
41 SmallVector<std::optional<int>> v = {0, 4};
42 OIListSimple::Properties prop;
43 prop.operandSegmentSizes = {1, 0, 1};
44 OIListSimple::GenericAdaptor<ArrayRef<std::optional<int>>> d(v, {}, prop,
45 {});
46 EXPECT_EQ(d.getArg0(), 0);
47 EXPECT_EQ(d.getArg1(), std::nullopt);
48 EXPECT_EQ(d.getArg2(), 4);
50 // Check the property comparison operator.
51 OIListSimple::Properties equivalentProp = {1, 0, 1};
52 OIListSimple::Properties differentProp = {0, 0, 1};
53 EXPECT_EQ(d.getProperties(), equivalentProp);
54 EXPECT_NE(d.getProperties(), differentProp);
57 // Has VariadicOfVariadic arguments.
58 FormatVariadicOfVariadicOperand::FoldAdaptor e({});
60 SmallVector<int> v = {0, 1, 2, 3, 4};
61 FormatVariadicOfVariadicOperand::Properties prop;
62 prop.operand_segments = builder.getDenseI32ArrayAttr({3, 2, 0});
63 FormatVariadicOfVariadicOperand::GenericAdaptor<ArrayRef<int>> f(v, {},
64 prop, {});
65 SmallVector<ArrayRef<int>> operand = f.getOperand();
66 ASSERT_EQ(operand.size(), (std::size_t)3);
67 EXPECT_THAT(operand[0], ElementsAre(0, 1, 2));
68 EXPECT_THAT(operand[1], ElementsAre(3, 4));
69 EXPECT_THAT(operand[2], ElementsAre());