[MLIR] Add setPublic(), setPrivate(), and setNested() to Symbol interface
authorRahul Joshi <jurahul@google.com>
Mon, 9 Nov 2020 19:43:45 +0000 (11:43 -0800)
committerRahul Joshi <jurahul@google.com>
Mon, 9 Nov 2020 21:56:38 +0000 (13:56 -0800)
- Add shorter helper functions to set visibility for Symbols.

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

mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
mlir/examples/toy/Ch6/mlir/MLIRGen.cpp
mlir/examples/toy/Ch7/mlir/MLIRGen.cpp
mlir/include/mlir/IR/SymbolInterfaces.td

index 7839978..4a8115b 100644 (file)
@@ -172,7 +172,7 @@ private:
 
     // If this function isn't main, then set the visibility to private.
     if (funcAST.getProto()->getName() != "main")
-      function.setVisibility(mlir::FuncOp::Visibility::Private);
+      function.setPrivate();
 
     return function;
   }
index 7839978..4a8115b 100644 (file)
@@ -172,7 +172,7 @@ private:
 
     // If this function isn't main, then set the visibility to private.
     if (funcAST.getProto()->getName() != "main")
-      function.setVisibility(mlir::FuncOp::Visibility::Private);
+      function.setPrivate();
 
     return function;
   }
index 7839978..4a8115b 100644 (file)
@@ -172,7 +172,7 @@ private:
 
     // If this function isn't main, then set the visibility to private.
     if (funcAST.getProto()->getName() != "main")
-      function.setVisibility(mlir::FuncOp::Visibility::Private);
+      function.setPrivate();
 
     return function;
   }
index 58a153b..a6690b7 100644 (file)
@@ -225,7 +225,7 @@ private:
 
     // If this function isn't main, then set the visibility to private.
     if (funcAST.getProto()->getName() != "main")
-      function.setVisibility(mlir::FuncOp::Visibility::Private);
+      function.setPrivate();
 
     return function;
   }
index c5f2bb8..a997ace 100644 (file)
@@ -53,12 +53,6 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
         return mlir::SymbolTable::getSymbolVisibility(this->getOperation());
       }]
     >,
-    InterfaceMethod<"Sets the visibility of this symbol.",
-      "void", "setVisibility", (ins "mlir::SymbolTable::Visibility":$vis), [{}],
-      /*defaultImplementation=*/[{
-        mlir::SymbolTable::setSymbolVisibility(this->getOperation(), vis);
-      }]
-    >,
     InterfaceMethod<"Returns true if this symbol has nested visibility.",
       "bool", "isNested", (ins),  [{}],
       /*defaultImplementation=*/[{
@@ -77,6 +71,30 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
         return getVisibility() == mlir::SymbolTable::Visibility::Public;
       }]
     >,
+    InterfaceMethod<"Sets the visibility of this symbol.",
+      "void", "setVisibility", (ins "mlir::SymbolTable::Visibility":$vis), [{}],
+      /*defaultImplementation=*/[{
+        mlir::SymbolTable::setSymbolVisibility(this->getOperation(), vis);
+      }]
+    >,
+    InterfaceMethod<"Sets the visibility of this symbol to be nested.",
+      "void", "setNested", (ins),  [{}],
+      /*defaultImplementation=*/[{
+        setVisibility(mlir::SymbolTable::Visibility::Nested);
+      }]
+    >,
+    InterfaceMethod<"Sets the visibility of this symbol to be private.",
+      "void", "setPrivate", (ins),  [{}],
+      /*defaultImplementation=*/[{
+        setVisibility(mlir::SymbolTable::Visibility::Private);
+      }]
+    >,
+    InterfaceMethod<"Sets the visibility of this symbol to be public.",
+      "void", "setPublic", (ins),  [{}],
+      /*defaultImplementation=*/[{
+        setVisibility(mlir::SymbolTable::Visibility::Public);
+      }]
+    >,
     InterfaceMethod<[{
         Get all of the uses of the current symbol that are nested within the
         given operation 'from'.