[Mlir-commits] [mlir] 857b655 - [mlir] Allow adding extra class declarations to interfaces.

River Riddle llvmlistbot at llvm.org
Sat Feb 15 23:57:47 PST 2020


Author: riverriddle at google.com
Date: 2020-02-15T23:54:42-08:00
New Revision: 857b655d7aac50462ffd0154b9d6c4f18119ddfb

URL: https://github.com/llvm/llvm-project/commit/857b655d7aac50462ffd0154b9d6c4f18119ddfb
DIFF: https://github.com/llvm/llvm-project/commit/857b655d7aac50462ffd0154b9d6c4f18119ddfb.diff

LOG: [mlir] Allow adding extra class declarations to interfaces.

Summary: This matches the similar feature on operation definitions.

Reviewers: jpienaar, antiagainst

Reviewed By: jpienaar, antiagainst

Subscribers: mehdi_amini, burmako, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74438

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpBase.td
    mlir/include/mlir/TableGen/OpInterfaces.h
    mlir/lib/TableGen/OpInterfaces.cpp
    mlir/tools/mlir-tblgen/OpInterfacesGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 1ccf9aee6a72..88240aed1949 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -1503,6 +1503,10 @@ class OpInterface<string name> : OpInterfaceTrait<name> {
 
   // 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

diff  --git a/mlir/include/mlir/TableGen/OpInterfaces.h b/mlir/include/mlir/TableGen/OpInterfaces.h
index b35b804d34e3..2e1a63cf6636 100644
--- a/mlir/include/mlir/TableGen/OpInterfaces.h
+++ b/mlir/include/mlir/TableGen/OpInterfaces.h
@@ -86,6 +86,9 @@ class OpInterface {
   // 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;
 

diff  --git a/mlir/lib/TableGen/OpInterfaces.cpp b/mlir/lib/TableGen/OpInterfaces.cpp
index 1839daeb5f42..c565547b2e09 100644
--- a/mlir/lib/TableGen/OpInterfaces.cpp
+++ b/mlir/lib/TableGen/OpInterfaces.cpp
@@ -86,6 +86,12 @@ llvm::Optional<StringRef> OpInterface::getDescription() const {
   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");

diff  --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
index 938c1c26d66d..0ca00eaf190e 100644
--- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -205,6 +205,11 @@ static void emitInterfaceDecl(OpInterface &interface, raw_ostream &os) {
     emitMethodNameAndArgs(method, os, /*addOperationArg=*/false);
     os << ";\n";
   }
+
+  // Emit any extra declarations.
+  if (Optional<StringRef> extraDecls = interface.getExtraClassDeclaration())
+    os << *extraDecls << "\n";
+
   os << "};\n";
 }
 


        


More information about the Mlir-commits mailing list