llvm-project
72 строки · 2.7 Кб
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//===----------------------------------------------------------------------===//
8
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"14
15using namespace llvm;16using namespace mlir;17using namespace test;18
19using testing::ElementsAre;20
21TEST(Adaptor, GenericAdaptorsOperandAccess) {22MLIRContext context;23context.loadDialect<test::TestDialect>();24Builder builder(&context);25
26// Has normal and Variadic arguments.27MixedNormalVariadicOperandOp::FoldAdaptor a({});28{29SmallVector<int> v = {0, 1, 2, 3, 4};30MixedNormalVariadicOperandOp::GenericAdaptor<ArrayRef<int>> b(v);31EXPECT_THAT(b.getInput1(), ElementsAre(0, 1));32EXPECT_EQ(b.getInput2(), 2);33EXPECT_THAT(b.getInput3(), ElementsAre(3, 4));34}35
36// Has optional arguments.37OIListSimple::FoldAdaptor c({}, nullptr);38{39// Optional arguments return the default constructed value if not present.40// Using optional instead of plain int here to differentiate absence of41// value from the value 0.42SmallVector<std::optional<int>> v = {0, 4};43OIListSimple::Properties prop;44prop.operandSegmentSizes = {1, 0, 1};45OIListSimple::GenericAdaptor<ArrayRef<std::optional<int>>> d(v, {}, prop,46{});47EXPECT_EQ(d.getArg0(), 0);48EXPECT_EQ(d.getArg1(), std::nullopt);49EXPECT_EQ(d.getArg2(), 4);50
51// Check the property comparison operator.52OIListSimple::Properties equivalentProp = {1, 0, 1};53OIListSimple::Properties differentProp = {0, 0, 1};54EXPECT_EQ(d.getProperties(), equivalentProp);55EXPECT_NE(d.getProperties(), differentProp);56}57
58// Has VariadicOfVariadic arguments.59FormatVariadicOfVariadicOperand::FoldAdaptor e({});60{61SmallVector<int> v = {0, 1, 2, 3, 4};62FormatVariadicOfVariadicOperand::Properties prop;63prop.operand_segments = builder.getDenseI32ArrayAttr({3, 2, 0});64FormatVariadicOfVariadicOperand::GenericAdaptor<ArrayRef<int>> f(v, {},65prop, {});66SmallVector<ArrayRef<int>> operand = f.getOperand();67ASSERT_EQ(operand.size(), (std::size_t)3);68EXPECT_THAT(operand[0], ElementsAre(0, 1, 2));69EXPECT_THAT(operand[1], ElementsAre(3, 4));70EXPECT_THAT(operand[2], ElementsAre());71}72}
73