[PATCH] D74438: [mlir] Allow adding extra class declarations to interfaces.
River Riddle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 13:18:48 PST 2020
rriddle created this revision.
rriddle added a reviewer: jpienaar.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, mehdi_amini.
Herald added a reviewer: antiagainst.
Herald added a project: LLVM.
rriddle added a child revision: D74439: [mlir][SideEffects] Define a set of interfaces and traits for defining side effects.
This matches the similar feature on operation definitions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74438
Files:
mlir/include/mlir/IR/OpBase.td
mlir/include/mlir/TableGen/OpInterfaces.h
mlir/lib/TableGen/OpInterfaces.cpp
mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
Index: mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -205,6 +205,11 @@
emitMethodNameAndArgs(method, os, /*addOperationArg=*/false);
os << ";\n";
}
+
+ // Emit any extra declarations.
+ if (Optional<StringRef> extraDecls = interface.getExtraClassDeclaration())
+ os << *extraDecls << "\n";
+
os << "};\n";
}
Index: mlir/lib/TableGen/OpInterfaces.cpp
===================================================================
--- mlir/lib/TableGen/OpInterfaces.cpp
+++ mlir/lib/TableGen/OpInterfaces.cpp
@@ -86,6 +86,12 @@
return value.empty() ? llvm::Optional<StringRef>() : value;
}
+// Return the interfaces extra class declaration code.
+llvm::Optional<StringRef> OpInterface::getExtraClassDeclaration() const {
+ auto value = def->getValueAsString("extraClassDeclaration");
+ return value.empty() ? llvm::Optional<StringRef>() : value;
+}
+
// Return the body for this method if it has one.
llvm::Optional<StringRef> OpInterface::getVerify() const {
auto value = def->getValueAsString("verify");
Index: mlir/include/mlir/TableGen/OpInterfaces.h
===================================================================
--- mlir/include/mlir/TableGen/OpInterfaces.h
+++ mlir/include/mlir/TableGen/OpInterfaces.h
@@ -86,6 +86,9 @@
// Return the description of this method if it has one.
llvm::Optional<StringRef> getDescription() const;
+ // Return the interfaces extra class declaration code.
+ llvm::Optional<StringRef> getExtraClassDeclaration() const;
+
// Return the verify method body if it has one.
llvm::Optional<StringRef> getVerify() const;
Index: mlir/include/mlir/IR/OpBase.td
===================================================================
--- mlir/include/mlir/IR/OpBase.td
+++ mlir/include/mlir/IR/OpBase.td
@@ -1479,6 +1479,10 @@
// The list of methods defined by this interface.
list<InterfaceMethod> methods = [];
+
+ // An optional code block containing extra declarations to place in the
+ // interface declaration.
+ code extraClassDeclaration = "";
}
// Whether to declare the op interface methods in the op's header. This class
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74438.243970.patch
Type: text/x-patch
Size: 2276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200211/b68a25ca/attachment.bin>
More information about the llvm-commits
mailing list