These interfaces allow for a composite attribute or type to opaquely provide access to any held attributes or types. There are several intended use cases for this interface. The first of which is to allow the printer to create aliases for non-builtin dialect attributes and types. In the future, this interface will also be extended to allow for SymbolRefAttr to be placed on other entities aside from just DictionaryAttr and ArrayAttr. To limit potential test breakages, this revision only adds the new interfaces to the builtin attributes/types that are currently hardcoded during AsmPrinter alias generation. In a followup the remaining builtin attributes/types, and non-builtin attributes/types can be extended to support it. Differential Revision: https://reviews.llvm.org/D102945
36 lines
1.2 KiB
C++
36 lines
1.2 KiB
C++
//===- SubElementInterfaceTest.cpp - SubElementInterface unit tests -------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/IR/Builders.h"
|
|
#include "mlir/IR/BuiltinAttributes.h"
|
|
#include "mlir/IR/SubElementInterfaces.h"
|
|
#include "gtest/gtest.h"
|
|
#include <cstdint>
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::detail;
|
|
|
|
namespace {
|
|
TEST(SubElementInterfaceTest, Nested) {
|
|
MLIRContext context;
|
|
Builder builder(&context);
|
|
|
|
BoolAttr trueAttr = builder.getBoolAttr(true);
|
|
BoolAttr falseAttr = builder.getBoolAttr(false);
|
|
ArrayAttr boolArrayAttr = builder.getArrayAttr({trueAttr, falseAttr});
|
|
DictionaryAttr dictAttr =
|
|
builder.getDictionaryAttr(builder.getNamedAttr("array", boolArrayAttr));
|
|
|
|
SmallVector<Attribute> subAttrs;
|
|
dictAttr.walkSubAttrs([&](Attribute attr) { subAttrs.push_back(attr); });
|
|
EXPECT_EQ(llvm::makeArrayRef(subAttrs),
|
|
ArrayRef<Attribute>({trueAttr, falseAttr, boolArrayAttr}));
|
|
}
|
|
|
|
} // end namespace
|