[LLD][COFF] Emit tail merge pdata for delay load thunks on ARM64EC (#116810)
[llvm-project.git] / mlir / unittests / IR / AdaptorTest.cpp
blob0a5fa8d3c475c3325f104baf52d87c33d256cf5f
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/TestOps.h"
11 #include "../../test/lib/Dialect/Test/TestOpsSyntax.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
15 using namespace llvm;
16 using namespace mlir;
17 using namespace test;
19 using testing::ElementsAre;
21 TEST(Adaptor, GenericAdaptorsOperandAccess) {
22 MLIRContext context;
23 context.loadDialect<test::TestDialect>();
24 Builder builder(&context);
26 // Has normal and Variadic arguments.
27 MixedNormalVariadicOperandOp::FoldAdaptor a({});
29 SmallVector<int> v = {0, 1, 2, 3, 4};
30 MixedNormalVariadicOperandOp::GenericAdaptor<ArrayRef<int>> b(v);
31 EXPECT_THAT(b.getInput1(), ElementsAre(0, 1));
32 EXPECT_EQ(b.getInput2(), 2);
33 EXPECT_THAT(b.getInput3(), ElementsAre(3, 4));
36 // Has optional arguments.
37 OIListSimple::FoldAdaptor c({}, nullptr);
39 // Optional arguments return the default constructed value if not present.
40 // Using optional instead of plain int here to differentiate absence of
41 // value from the value 0.
42 SmallVector<std::optional<int>> v = {0, 4};
43 OIListSimple::Properties prop;
44 prop.operandSegmentSizes = {1, 0, 1};
45 OIListSimple::GenericAdaptor<ArrayRef<std::optional<int>>> d(v, {}, prop,
46 {});
47 EXPECT_EQ(d.getArg0(), 0);
48 EXPECT_EQ(d.getArg1(), std::nullopt);
49 EXPECT_EQ(d.getArg2(), 4);
51 // Check the property comparison operator.
52 OIListSimple::Properties equivalentProp = {1, 0, 1};
53 OIListSimple::Properties differentProp = {0, 0, 1};
54 EXPECT_EQ(d.getProperties(), equivalentProp);
55 EXPECT_NE(d.getProperties(), differentProp);
58 // Has VariadicOfVariadic arguments.
59 FormatVariadicOfVariadicOperand::FoldAdaptor e({});
61 SmallVector<int> v = {0, 1, 2, 3, 4};
62 FormatVariadicOfVariadicOperand::Properties prop;
63 prop.operand_segments = builder.getDenseI32ArrayAttr({3, 2, 0});
64 FormatVariadicOfVariadicOperand::GenericAdaptor<ArrayRef<int>> f(v, {},
65 prop, {});
66 SmallVector<ArrayRef<int>> operand = f.getOperand();
67 ASSERT_EQ(operand.size(), (std::size_t)3);
68 EXPECT_THAT(operand[0], ElementsAre(0, 1, 2));
69 EXPECT_THAT(operand[1], ElementsAre(3, 4));
70 EXPECT_THAT(operand[2], ElementsAre());