--- /dev/null
+// RUN: mlir-tblgen -gen-op-interface-decls -I %S/../../include %s | FileCheck %s --check-prefix=DECL --dump-input-on-failure
+
+include "mlir/IR/OpBase.td"
+
+def TestOpInterface : OpInterface<"TestOpInterface"> {
+ let description = [{some op interface description}];
+
+ let methods = [
+ InterfaceMethod<
+ /*desc=*/[{some function comment}],
+ /*retTy=*/"int",
+ /*methodName=*/"foo",
+ /*args=*/(ins "int":$input)
+ >,
+ ];
+}
+
+// Define Ops with TestOpInterface and
+// DeclareOpInterfaceMethods<TestOpInterface> traits to check that there
+// are not duplicated C++ classes generated.
+def TestDialect : Dialect {
+ let name = "test";
+}
+
+def OpInterfaceOp : Op<TestDialect, "op_interface_op", [TestOpInterface]>;
+
+def DeclareMethodsOp : Op<TestDialect, "declare_methods_op",
+ [DeclareOpInterfaceMethods<TestOpInterface>]>;
+
+// DECL-LABEL: TestOpInterfaceInterfaceTraits
+// DECL: class TestOpInterface : public OpInterface<TestOpInterface, detail::TestOpInterfaceInterfaceTraits>
+// DECL: int foo(int input);
+
+// DECL-NOT: TestOpInterface
os << ')';
}
+// Get an array of all OpInterface definitions but exclude those subclassing
+// "DeclareOpInterfaceMethods".
+static std::vector<Record *>
+getAllOpInterfaceDefinitions(const RecordKeeper &recordKeeper) {
+ std::vector<Record *> defs =
+ recordKeeper.getAllDerivedDefinitions("OpInterface");
+
+ llvm::erase_if(defs, [](const Record *def) {
+ return def->isSubClassOf("DeclareOpInterfaceMethods");
+ });
+ return defs;
+}
+
//===----------------------------------------------------------------------===//
// GEN: Interface definitions
//===----------------------------------------------------------------------===//
raw_ostream &os) {
llvm::emitSourceFileHeader("Operation Interface Definitions", os);
- auto defs = recordKeeper.getAllDerivedDefinitions("OpInterface");
- for (const auto *def : defs) {
+ for (const auto *def : getAllOpInterfaceDefinitions(recordKeeper)) {
OpInterface interface(def);
emitInterfaceDef(interface, os);
}
raw_ostream &os) {
llvm::emitSourceFileHeader("Operation Interface Declarations", os);
- auto defs = recordKeeper.getAllDerivedDefinitions("OpInterface");
- for (const auto *def : defs) {
+ for (const auto *def : getAllOpInterfaceDefinitions(recordKeeper)) {
OpInterface interface(def);
emitInterfaceDecl(interface, os);
}
os << "<!-- Autogenerated by mlir-tblgen; don't manually edit -->\n";
os << "# Operation Interface definition\n";
- auto defs = recordKeeper.getAllDerivedDefinitions("OpInterface");
- for (const auto *def : defs)
+ for (const auto *def : getAllOpInterfaceDefinitions(recordKeeper))
emitInterfaceDoc(*def, os);
return false;
}