Mercurial > hg > CbC > CbC_llvm
diff mlir/unittests/TableGen/StructsGenTest.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 0572611fdcc8 |
children |
line wrap: on
line diff
--- a/mlir/unittests/TableGen/StructsGenTest.cpp Tue Jun 15 19:13:43 2021 +0900 +++ b/mlir/unittests/TableGen/StructsGenTest.cpp Tue Jun 15 19:15:29 2021 +0900 @@ -7,8 +7,9 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/Attributes.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Identifier.h" -#include "mlir/IR/StandardTypes.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" @@ -17,14 +18,14 @@ namespace mlir { -// Pull in generated enum utility declarations +/// Pull in generated enum utility declarations and definitions. #include "StructAttrGenTest.h.inc" -// And definitions #include "StructAttrGenTest.cpp.inc" -// Helper that returns an example test::TestStruct for testing its -// implementation. + +/// Helper that returns an example test::TestStruct for testing its +/// implementation. static test::TestStruct getTestStruct(mlir::MLIRContext *context) { - auto integerType = mlir::IntegerType::get(32, context); + auto integerType = mlir::IntegerType::get(context, 32); auto integerAttr = mlir::IntegerAttr::get(integerType, 127); auto floatType = mlir::FloatType::getF32(context); @@ -34,21 +35,22 @@ auto elementsAttr = mlir::DenseIntElementsAttr::get(elementsType, {1, 2, 3, 4, 5, 6}); auto optionalAttr = nullptr; + auto defaultValuedAttr = nullptr; return test::TestStruct::get(integerAttr, floatAttr, elementsAttr, - optionalAttr, context); + optionalAttr, defaultValuedAttr, context); } -// Validates that test::TestStruct::classof correctly identifies a valid -// test::TestStruct. +/// Validates that test::TestStruct::classof correctly identifies a valid +/// test::TestStruct. TEST(StructsGenTest, ClassofTrue) { mlir::MLIRContext context; auto structAttr = getTestStruct(&context); ASSERT_TRUE(test::TestStruct::classof(structAttr)); } -// Validates that test::TestStruct::classof fails when an extra attribute is in -// the class. +/// Validates that test::TestStruct::classof fails when an extra attribute is in +/// the class. TEST(StructsGenTest, ClassofExtraFalse) { mlir::MLIRContext context; mlir::DictionaryAttr structAttr = getTestStruct(&context); @@ -65,12 +67,12 @@ newValues.push_back(wrongAttr); // Make a new DictionaryAttr and validate. - auto badDictionary = mlir::DictionaryAttr::get(newValues, &context); + auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); ASSERT_FALSE(test::TestStruct::classof(badDictionary)); } -// Validates that test::TestStruct::classof fails when a NamedAttribute has an -// incorrect name. +/// Validates that test::TestStruct::classof fails when a NamedAttribute has an +/// incorrect name. TEST(StructsGenTest, ClassofBadNameFalse) { mlir::MLIRContext context; mlir::DictionaryAttr structAttr = getTestStruct(&context); @@ -86,12 +88,12 @@ auto wrongAttr = mlir::NamedAttribute(wrongId, expectedValues[0].second); newValues.push_back(wrongAttr); - auto badDictionary = mlir::DictionaryAttr::get(newValues, &context); + auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); ASSERT_FALSE(test::TestStruct::classof(badDictionary)); } -// Validates that test::TestStruct::classof fails when a NamedAttribute has an -// incorrect type. +/// Validates that test::TestStruct::classof fails when a NamedAttribute has an +/// incorrect type. TEST(StructsGenTest, ClassofBadTypeFalse) { mlir::MLIRContext context; mlir::DictionaryAttr structAttr = getTestStruct(&context); @@ -103,7 +105,7 @@ expectedValues.begin(), expectedValues.end() - 1); // Add a copy of the last attribute with the wrong type. - auto i64Type = mlir::IntegerType::get(64, &context); + auto i64Type = mlir::IntegerType::get(&context, 64); auto elementsType = mlir::RankedTensorType::get({3}, i64Type); auto elementsAttr = mlir::DenseIntElementsAttr::get(elementsType, ArrayRef<int64_t>{1, 2, 3}); @@ -111,12 +113,12 @@ auto wrongAttr = mlir::NamedAttribute(id, elementsAttr); newValues.push_back(wrongAttr); - auto badDictionary = mlir::DictionaryAttr::get(newValues, &context); + auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); ASSERT_FALSE(test::TestStruct::classof(badDictionary)); } -// Validates that test::TestStruct::classof fails when a NamedAttribute is -// missing. +/// Validates that test::TestStruct::classof fails when a NamedAttribute is +/// missing. TEST(StructsGenTest, ClassofMissingFalse) { mlir::MLIRContext context; mlir::DictionaryAttr structAttr = getTestStruct(&context); @@ -128,11 +130,11 @@ expectedValues.begin() + 1, expectedValues.end()); // Make a new DictionaryAttr and validate it is not a validate TestStruct. - auto badDictionary = mlir::DictionaryAttr::get(newValues, &context); + auto badDictionary = mlir::DictionaryAttr::get(&context, newValues); ASSERT_FALSE(test::TestStruct::classof(badDictionary)); } -// Validate the accessor for the FloatAttr value. +/// Validate the accessor for the FloatAttr value. TEST(StructsGenTest, GetFloat) { mlir::MLIRContext context; auto structAttr = getTestStruct(&context); @@ -140,7 +142,7 @@ EXPECT_EQ(returnedAttr.getValueAsDouble(), 0.25); } -// Validate the accessor for the IntegerAttr value. +/// Validate the accessor for the IntegerAttr value. TEST(StructsGenTest, GetInteger) { mlir::MLIRContext context; auto structAttr = getTestStruct(&context); @@ -148,7 +150,7 @@ EXPECT_EQ(returnedAttr.getInt(), 127); } -// Validate the accessor for the ElementsAttr value. +/// Validate the accessor for the ElementsAttr value. TEST(StructsGenTest, GetElements) { mlir::MLIRContext context; auto structAttr = getTestStruct(&context); @@ -167,4 +169,12 @@ EXPECT_EQ(structAttr.sample_optional_integer(), nullptr); } +TEST(StructsGenTest, GetDefaultValuedAttr) { + mlir::MLIRContext context; + mlir::Builder builder(&context); + auto structAttr = getTestStruct(&context); + EXPECT_EQ(structAttr.sample_default_valued_integer(), + builder.getI32IntegerAttr(42)); +} + } // namespace mlir