[Mlir-commits] [mlir] d5c2204 - [TableGen] OpInterface inheritance duplicates bases
Andrew Lenharth
llvmlistbot at llvm.org
Thu Aug 3 13:11:00 PDT 2023
Author: Andrew Lenharth
Date: 2023-08-03T15:09:03-05:00
New Revision: d5c2204cfc9b48fc59d765422c33f98350f79dcf
URL: https://github.com/llvm/llvm-project/commit/d5c2204cfc9b48fc59d765422c33f98350f79dcf
DIFF: https://github.com/llvm/llvm-project/commit/d5c2204cfc9b48fc59d765422c33f98350f79dcf.diff
LOG: [TableGen] OpInterface inheritance duplicates bases
OpInterface inheritance will duplicate base interfaces, causing compilation failure. Unique the set of base interfaces.
Reviewed By: rriddle, jdd
Differential Revision: https://reviews.llvm.org/D156964
Added:
Modified:
mlir/lib/TableGen/Interfaces.cpp
mlir/test/mlir-tblgen/op-interface.td
Removed:
################################################################################
diff --git a/mlir/lib/TableGen/Interfaces.cpp b/mlir/lib/TableGen/Interfaces.cpp
index c1d1ba0540c329..a209b003b0f3bb 100644
--- a/mlir/lib/TableGen/Interfaces.cpp
+++ b/mlir/lib/TableGen/Interfaces.cpp
@@ -9,6 +9,7 @@
#include "mlir/TableGen/Interfaces.h"
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
@@ -83,6 +84,8 @@ Interface::Interface(const llvm::Record *def) : def(def) {
// Initialize the interface base classes.
auto *basesInit =
dyn_cast<llvm::ListInit>(def->getValueInit("baseInterfaces"));
+ // Chained inheritance will produce duplicates in the base interface set.
+ StringSet<> basesAdded;
llvm::unique_function<void(Interface)> addBaseInterfaceFn =
[&](const Interface &baseInterface) {
// Inherit any base interfaces.
@@ -90,7 +93,10 @@ Interface::Interface(const llvm::Record *def) : def(def) {
addBaseInterfaceFn(baseBaseInterface);
// Add the base interface.
+ if (basesAdded.contains(baseInterface.getName()))
+ return;
baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
+ basesAdded.insert(baseInterface.getName());
};
for (llvm::Init *init : basesInit->getValues())
addBaseInterfaceFn(Interface(cast<llvm::DefInit>(init)->getDef()));
diff --git a/mlir/test/mlir-tblgen/op-interface.td b/mlir/test/mlir-tblgen/op-interface.td
index 76467f50152cbb..feffe2097dbdaa 100644
--- a/mlir/test/mlir-tblgen/op-interface.td
+++ b/mlir/test/mlir-tblgen/op-interface.td
@@ -34,7 +34,18 @@ def ExtraShardDeclsInterface : OpInterface<"ExtraShardDeclsInterface"> {
// DECL-NEXT: return (*static_cast<ConcreteOp *>(this)).someOtherMethod();
// DECL-NEXT: }
-def TestInheritanceBaseInterface : OpInterface<"TestInheritanceBaseInterface"> {
+def TestInheritanceMultiBaseInterface : OpInterface<"TestInheritanceMultiBaseInterface"> {
+ let methods = [
+ InterfaceMethod<
+ /*desc=*/[{some function comment}],
+ /*retTy=*/"int",
+ /*methodName=*/"baz",
+ /*args=*/(ins "int":$input)
+ >
+ ];
+}
+
+def TestInheritanceBaseInterface : OpInterface<"TestInheritanceBaseInterface", [TestInheritanceMultiBaseInterface]> {
let methods = [
InterfaceMethod<
/*desc=*/[{some function comment}],
@@ -60,6 +71,8 @@ def TestInheritanceZDerivedInterface
// DECL: class TestInheritanceZDerivedInterface
// DECL: struct Concept {
+// DECL: const TestInheritanceMultiBaseInterface::Concept *implTestInheritanceMultiBaseInterface = nullptr;
+// DECL-NOT: const TestInheritanceMultiBaseInterface::Concept
// DECL: const TestInheritanceBaseInterface::Concept *implTestInheritanceBaseInterface = nullptr;
// DECL: const TestInheritanceMiddleBaseInterface::Concept *implTestInheritanceMiddleBaseInterface = nullptr;
More information about the Mlir-commits
mailing list