diff options
author | River Riddle <riddleriver@gmail.com> | 2023-01-12 13:35:15 -0800 |
---|---|---|
committer | River Riddle <riddleriver@gmail.com> | 2023-01-18 19:16:30 -0800 |
commit | 83a635c0d4759bd77bbbb21ff8d202cb8c3ea57b (patch) | |
tree | f112422f41b764dbe94b9c8e73e469542406ad84 /mlir/lib/Support | |
parent | 5cdc2bbc7588e7b046ac5c7f79a84ef18978a83a (diff) | |
download | llvm-83a635c0d4759bd77bbbb21ff8d202cb8c3ea57b.tar.gz |
[mlir] Add support for interface inheritance
This allows for interfaces to define a set of "base classes",
which are interfaces whose methods/extra class decls/etc.
should be inherited by the derived interface. This more
easily enables combining interfaces and their dependencies,
without lots of awkard casting. Additional implicit conversion
operators also greatly simplify the conversion process.
One other aspect of this "inheritance" is that we also implicitly
add the base interfaces to the attr/op/type. The user can still
add them manually if desired, but this should help remove some
of the boiler plate when an interface has dependencies.
See https://discourse.llvm.org/t/interface-inheritance-and-dependencies-interface-method-visibility-interface-composition
Differential Revision: https://reviews.llvm.org/D140198
Diffstat (limited to 'mlir/lib/Support')
-rw-r--r-- | mlir/lib/Support/InterfaceSupport.cpp | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/mlir/lib/Support/InterfaceSupport.cpp b/mlir/lib/Support/InterfaceSupport.cpp index 4b8dd58801e2..d813046eca7f 100644 --- a/mlir/lib/Support/InterfaceSupport.cpp +++ b/mlir/lib/Support/InterfaceSupport.cpp @@ -18,27 +18,16 @@ using namespace mlir; -detail::InterfaceMap::InterfaceMap( - MutableArrayRef<std::pair<TypeID, void *>> elements) - : interfaces(elements.begin(), elements.end()) { - llvm::sort(interfaces, [](const auto &lhs, const auto &rhs) { - return compare(lhs.first, rhs.first); - }); -} - -void detail::InterfaceMap::insert( - ArrayRef<std::pair<TypeID, void *>> elements) { +void detail::InterfaceMap::insert(TypeID interfaceId, void *conceptImpl) { // Insert directly into the right position to keep the interfaces sorted. - for (auto &element : elements) { - TypeID id = element.first; - auto *it = llvm::lower_bound(interfaces, id, [](const auto &it, TypeID id) { - return compare(it.first, id); - }); - if (it != interfaces.end() && it->first == id) { - LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration"); - free(element.second); - continue; - } - interfaces.insert(it, element); + auto *it = + llvm::lower_bound(interfaces, interfaceId, [](const auto &it, TypeID id) { + return compare(it.first, id); + }); + if (it != interfaces.end() && it->first == interfaceId) { + LLVM_DEBUG(llvm::dbgs() << "Ignoring repeated interface registration"); + free(conceptImpl); + return; } + interfaces.insert(it, {interfaceId, conceptImpl}); } |