diff options
Diffstat (limited to 'mlir/unittests/IR')
-rw-r--r-- | mlir/unittests/IR/AttributeTest.cpp | 31 | ||||
-rw-r--r-- | mlir/unittests/IR/IRMapping.cpp | 8 | ||||
-rw-r--r-- | mlir/unittests/IR/InterfaceAttachmentTest.cpp | 18 | ||||
-rw-r--r-- | mlir/unittests/IR/InterfaceTest.cpp | 16 | ||||
-rw-r--r-- | mlir/unittests/IR/OperationSupportTest.cpp | 12 | ||||
-rw-r--r-- | mlir/unittests/IR/SymbolTableTest.cpp | 34 |
6 files changed, 87 insertions, 32 deletions
diff --git a/mlir/unittests/IR/AttributeTest.cpp b/mlir/unittests/IR/AttributeTest.cpp index a55592d..fd40404 100644 --- a/mlir/unittests/IR/AttributeTest.cpp +++ b/mlir/unittests/IR/AttributeTest.cpp @@ -477,8 +477,9 @@ TEST(SubElementTest, Nested) { {strAttr, trueAttr, falseAttr, boolArrayAttr, dictAttr})); } -// Test how many times we call copy-ctor when building an attribute. -TEST(CopyCountAttr, CopyCount) { +// Test how many times we call copy-ctor when building an attribute with the +// 'get' method. +TEST(CopyCountAttr, CopyCountGet) { MLIRContext context; context.loadDialect<test::TestDialect>(); @@ -489,15 +490,35 @@ TEST(CopyCountAttr, CopyCount) { test::CopyCount::counter = 0; test::TestCopyCountAttr::get(&context, std::move(copyCount)); #ifndef NDEBUG - // One verification enabled only in assert-mode requires a copy. - EXPECT_EQ(counter1, 1); - EXPECT_EQ(test::CopyCount::counter, 1); + // One verification enabled only in assert-mode requires two copies: one for + // calling 'verifyInvariants' and one for calling 'verify' inside + // 'verifyInvariants'. + EXPECT_EQ(counter1, 2); + EXPECT_EQ(test::CopyCount::counter, 2); #else EXPECT_EQ(counter1, 0); EXPECT_EQ(test::CopyCount::counter, 0); #endif } +// Test how many times we call copy-ctor when building an attribute with the +// 'getChecked' method. +TEST(CopyCountAttr, CopyCountGetChecked) { + MLIRContext context; + context.loadDialect<test::TestDialect>(); + test::CopyCount::counter = 0; + test::CopyCount copyCount("hello"); + auto loc = UnknownLoc::get(&context); + test::TestCopyCountAttr::getChecked(loc, &context, std::move(copyCount)); + int counter1 = test::CopyCount::counter; + test::CopyCount::counter = 0; + test::TestCopyCountAttr::getChecked(loc, &context, std::move(copyCount)); + // The verifiers require two copies: one for calling 'verifyInvariants' and + // one for calling 'verify' inside 'verifyInvariants'. + EXPECT_EQ(counter1, 2); + EXPECT_EQ(test::CopyCount::counter, 2); +} + // Test stripped printing using test dialect attribute. TEST(CopyCountAttr, PrintStripped) { MLIRContext context; diff --git a/mlir/unittests/IR/IRMapping.cpp b/mlir/unittests/IR/IRMapping.cpp index b88009d..983c41a 100644 --- a/mlir/unittests/IR/IRMapping.cpp +++ b/mlir/unittests/IR/IRMapping.cpp @@ -26,10 +26,10 @@ TEST(IRMapping, TypedValue) { Block block; builder.setInsertionPointToEnd(&block); - Value i64Val = builder.create<test::TestOpConstant>( - loc, builder.getI64Type(), builder.getI64IntegerAttr(0)); - Value f64Val = builder.create<test::TestOpConstant>( - loc, builder.getF64Type(), builder.getF64FloatAttr(0.0)); + Value i64Val = test::TestOpConstant::create( + builder, loc, builder.getI64Type(), builder.getI64IntegerAttr(0)); + Value f64Val = test::TestOpConstant::create( + builder, loc, builder.getF64Type(), builder.getF64FloatAttr(0.0)); IRMapping mapping; mapping.map(i64Val, f64Val); diff --git a/mlir/unittests/IR/InterfaceAttachmentTest.cpp b/mlir/unittests/IR/InterfaceAttachmentTest.cpp index 1b5d3b8..e1e65da 100644 --- a/mlir/unittests/IR/InterfaceAttachmentTest.cpp +++ b/mlir/unittests/IR/InterfaceAttachmentTest.cpp @@ -303,7 +303,7 @@ TEST(InterfaceAttachment, Operation) { // Initially, the operation doesn't have the interface. OwningOpRef<ModuleOp> moduleOp = - builder.create<ModuleOp>(UnknownLoc::get(&context)); + ModuleOp::create(builder, UnknownLoc::get(&context)); ASSERT_FALSE(isa<TestExternalOpInterface>(moduleOp->getOperation())); // We can attach an external interface and now the operaiton has it. @@ -317,8 +317,8 @@ TEST(InterfaceAttachment, Operation) { // Default implementation can be overridden. OwningOpRef<UnrealizedConversionCastOp> castOp = - builder.create<UnrealizedConversionCastOp>(UnknownLoc::get(&context), - TypeRange(), ValueRange()); + UnrealizedConversionCastOp::create(builder, UnknownLoc::get(&context), + TypeRange(), ValueRange()); ASSERT_FALSE(isa<TestExternalOpInterface>(castOp->getOperation())); UnrealizedConversionCastOp::attachInterface<TestExternalOpOverridingModel>( context); @@ -368,11 +368,11 @@ TEST(InterfaceAttachment, OperationDelayedContextConstruct) { OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context)); OpBuilder builder(module->getBody(), module->getBody()->begin()); auto opJ = - builder.create<test::OpJ>(builder.getUnknownLoc(), builder.getI32Type()); + test::OpJ::create(builder, builder.getUnknownLoc(), builder.getI32Type()); auto opH = - builder.create<test::OpH>(builder.getUnknownLoc(), opJ.getResult()); + test::OpH::create(builder, builder.getUnknownLoc(), opJ.getResult()); auto opI = - builder.create<test::OpI>(builder.getUnknownLoc(), opJ.getResult()); + test::OpI::create(builder, builder.getUnknownLoc(), opJ.getResult()); EXPECT_TRUE(isa<TestExternalOpInterface>(module->getOperation())); EXPECT_TRUE(isa<TestExternalOpInterface>(opJ.getOperation())); @@ -399,11 +399,11 @@ TEST(InterfaceAttachment, OperationDelayedContextAppend) { OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context)); OpBuilder builder(module->getBody(), module->getBody()->begin()); auto opJ = - builder.create<test::OpJ>(builder.getUnknownLoc(), builder.getI32Type()); + test::OpJ::create(builder, builder.getUnknownLoc(), builder.getI32Type()); auto opH = - builder.create<test::OpH>(builder.getUnknownLoc(), opJ.getResult()); + test::OpH::create(builder, builder.getUnknownLoc(), opJ.getResult()); auto opI = - builder.create<test::OpI>(builder.getUnknownLoc(), opJ.getResult()); + test::OpI::create(builder, builder.getUnknownLoc(), opJ.getResult()); EXPECT_FALSE(isa<TestExternalOpInterface>(module->getOperation())); EXPECT_FALSE(isa<TestExternalOpInterface>(opJ.getOperation())); diff --git a/mlir/unittests/IR/InterfaceTest.cpp b/mlir/unittests/IR/InterfaceTest.cpp index 42196b0..235163c 100644 --- a/mlir/unittests/IR/InterfaceTest.cpp +++ b/mlir/unittests/IR/InterfaceTest.cpp @@ -27,12 +27,12 @@ TEST(InterfaceTest, OpInterfaceDenseMapKey) { OwningOpRef<ModuleOp> module = ModuleOp::create(UnknownLoc::get(&context)); OpBuilder builder(module->getBody(), module->getBody()->begin()); - auto op1 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(), - builder.getI32Type()); - auto op2 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(), - builder.getI32Type()); - auto op3 = builder.create<test::SideEffectOp>(builder.getUnknownLoc(), - builder.getI32Type()); + auto op1 = test::SideEffectOp::create(builder, builder.getUnknownLoc(), + builder.getI32Type()); + auto op2 = test::SideEffectOp::create(builder, builder.getUnknownLoc(), + builder.getI32Type()); + auto op3 = test::SideEffectOp::create(builder, builder.getUnknownLoc(), + builder.getI32Type()); DenseSet<MemoryEffectOpInterface> opSet; opSet.insert(op1); opSet.insert(op2); @@ -64,8 +64,8 @@ TEST(InterfaceTest, TestCustomClassOf) { context.loadDialect<test::TestDialect>(); OpBuilder builder(&context); - auto op = builder.create<TestOpOptionallyImplementingInterface>( - builder.getUnknownLoc(), /*implementsInterface=*/true); + auto op = TestOpOptionallyImplementingInterface::create( + builder, builder.getUnknownLoc(), /*implementsInterface=*/true); EXPECT_TRUE(isa<TestOptionallyImplementedOpInterface>(*op)); op.setImplementsInterface(false); EXPECT_FALSE(isa<TestOptionallyImplementedOpInterface>(*op)); diff --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp index 7bc1a04..9f3e7ed 100644 --- a/mlir/unittests/IR/OperationSupportTest.cpp +++ b/mlir/unittests/IR/OperationSupportTest.cpp @@ -302,8 +302,8 @@ TEST(OperandStorageTest, PopulateDefaultAttrs) { auto req1 = b.getI32IntegerAttr(10); auto req2 = b.getI32IntegerAttr(60); // Verify default attributes populated post op creation. - Operation *op = b.create<test::OpAttrMatch1>(b.getUnknownLoc(), req1, nullptr, - nullptr, req2); + Operation *op = test::OpAttrMatch1::create(b, b.getUnknownLoc(), req1, + nullptr, nullptr, req2); auto opt = op->getInherentAttr("default_valued_attr"); EXPECT_NE(opt, nullptr) << *op; @@ -343,11 +343,11 @@ TEST(OperationEquivalenceTest, HashWorksWithFlags) { // Check ignore properties. auto req1 = b.getI32IntegerAttr(10); - Operation *opWithProperty1 = b.create<test::OpAttrMatch1>( - b.getUnknownLoc(), req1, nullptr, nullptr, req1); + Operation *opWithProperty1 = test::OpAttrMatch1::create( + b, b.getUnknownLoc(), req1, nullptr, nullptr, req1); auto req2 = b.getI32IntegerAttr(60); - Operation *opWithProperty2 = b.create<test::OpAttrMatch1>( - b.getUnknownLoc(), req2, nullptr, nullptr, req2); + Operation *opWithProperty2 = test::OpAttrMatch1::create( + b, b.getUnknownLoc(), req2, nullptr, nullptr, req2); EXPECT_EQ(getHash(opWithProperty1, OperationEquivalence::IgnoreProperties), getHash(opWithProperty2, OperationEquivalence::IgnoreProperties)); EXPECT_NE(getHash(opWithProperty1, OperationEquivalence::None), diff --git a/mlir/unittests/IR/SymbolTableTest.cpp b/mlir/unittests/IR/SymbolTableTest.cpp index cfc3fe0..4b3545b 100644 --- a/mlir/unittests/IR/SymbolTableTest.cpp +++ b/mlir/unittests/IR/SymbolTableTest.cpp @@ -132,4 +132,38 @@ TEST_F(ReplaceAllSymbolUsesTest, StringAttrInFuncOp) { }); } +TEST(SymbolOpInterface, Visibility) { + DialectRegistry registry; + ::test::registerTestDialect(registry); + MLIRContext context(registry); + + constexpr static StringLiteral kInput = R"MLIR( + "test.overridden_symbol_visibility"() {sym_name = "symbol_name"} : () -> () + )MLIR"; + OwningOpRef<ModuleOp> module = parseSourceString<ModuleOp>(kInput, &context); + auto symOp = cast<SymbolOpInterface>(module->getBody()->front()); + + ASSERT_TRUE(symOp.isPrivate()); + ASSERT_FALSE(symOp.isPublic()); + ASSERT_FALSE(symOp.isNested()); + ASSERT_TRUE(symOp.canDiscardOnUseEmpty()); + + std::string diagStr; + context.getDiagEngine().registerHandler( + [&](Diagnostic &diag) { diagStr += diag.str(); }); + + std::string expectedDiag; + symOp.setPublic(); + expectedDiag += "'test.overridden_symbol_visibility' op cannot change " + "visibility of symbol to public"; + symOp.setNested(); + expectedDiag += "'test.overridden_symbol_visibility' op cannot change " + "visibility of symbol to nested"; + symOp.setPrivate(); + expectedDiag += "'test.overridden_symbol_visibility' op cannot change " + "visibility of symbol to private"; + + ASSERT_EQ(diagStr, expectedDiag); +} + } // namespace |