diff options
author | Fabian Mora <fmora.dev@gmail.com> | 2023-09-05 09:17:54 -0400 |
---|---|---|
committer | Fabian Mora <fmora.dev@gmail.com> | 2023-09-05 09:55:27 -0400 |
commit | d0e6fd99aa95ff61372ea328e9f89da2ee39c49c (patch) | |
tree | 20444ff01d69ca5060947ee3eb8817c8dba064f5 /mlir/unittests/IR/InterfaceAttachmentTest.cpp | |
parent | 5857fe0647c187fbc43298e2e50ca122993b3351 (diff) | |
download | llvm-d0e6fd99aa95ff61372ea328e9f89da2ee39c49c.zip llvm-d0e6fd99aa95ff61372ea328e9f89da2ee39c49c.tar.gz llvm-d0e6fd99aa95ff61372ea328e9f89da2ee39c49c.tar.bz2 |
[mlir] Extend the promise interface mechanism
This patch pairs a promised interface with the object (Op/Attr/Type/Dialect) requesting the promise, ie:
```
declarePromisedInterface<MyAttr, MyInterface>();
```
Allowing to make fine grained promises. It also adds a mechanism to query if `Op/Attr/Type` has an specific promise returning true if the promise is there or if an implementation has been added. Finally it adds a couple of `Attr|TypeConstraints` that can be used in ODS to query if the promise or an implementation is there.
This patch tries to solve 2 issues:
1. Different entities cannot use the same promise.
```
declarePromisedInterface<MyInterface>();
// Resolves a promise.
MyAttr1::attachInterface<MyInterface>(ctx);
// Doesn't resolves a promise, as the previous attachment removed the promise.
MyAttr2::attachInterface<MyInterface>(ctx);
```
2. Is not possible to query if a promise has been declared.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D158464
Diffstat (limited to 'mlir/unittests/IR/InterfaceAttachmentTest.cpp')
-rw-r--r-- | mlir/unittests/IR/InterfaceAttachmentTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/mlir/unittests/IR/InterfaceAttachmentTest.cpp b/mlir/unittests/IR/InterfaceAttachmentTest.cpp index fe85516..2e1309a 100644 --- a/mlir/unittests/IR/InterfaceAttachmentTest.cpp +++ b/mlir/unittests/IR/InterfaceAttachmentTest.cpp @@ -417,4 +417,30 @@ TEST(InterfaceAttachment, OperationDelayedContextAppend) { EXPECT_FALSE(isa<TestExternalOpInterface>(opI.getOperation())); } +TEST(InterfaceAttachmentTest, PromisedInterfaces) { + // Attribute interfaces use the exact same mechanism as types, so just check + // that the promise mechanism works for attributes. + MLIRContext context; + auto testDialect = context.getOrLoadDialect<test::TestDialect>(); + auto attr = test::SimpleAAttr::get(&context); + + // `SimpleAAttr` doesn't implement nor promises the + // `TestExternalAttrInterface` interface. + EXPECT_FALSE(isa<TestExternalAttrInterface>(attr)); + EXPECT_FALSE( + attr.hasPromiseOrImplementsInterface<TestExternalAttrInterface>()); + + // Add a promise `TestExternalAttrInterface`. + testDialect->declarePromisedInterface<test::SimpleAAttr, + TestExternalAttrInterface>(); + EXPECT_TRUE( + attr.hasPromiseOrImplementsInterface<TestExternalAttrInterface>()); + + // Attach the interface. + test::SimpleAAttr::attachInterface<TestExternalAttrInterface>(context); + EXPECT_TRUE(isa<TestExternalAttrInterface>(attr)); + EXPECT_TRUE( + attr.hasPromiseOrImplementsInterface<TestExternalAttrInterface>()); +} + } // namespace |