Skip to content

Commit 64be856

Browse files
committed
[MLIR] Add setPublic(), setPrivate(), and setNested() to Symbol interface
- Add shorter helper functions to set visibility for Symbols. Differential Revision: https://reviews.llvm.org/D91096
1 parent 8d51969 commit 64be856

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

mlir/examples/toy/Ch4/mlir/MLIRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class MLIRGenImpl {
172172

173173
// If this function isn't main, then set the visibility to private.
174174
if (funcAST.getProto()->getName() != "main")
175-
function.setVisibility(mlir::FuncOp::Visibility::Private);
175+
function.setPrivate();
176176

177177
return function;
178178
}

mlir/examples/toy/Ch5/mlir/MLIRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class MLIRGenImpl {
172172

173173
// If this function isn't main, then set the visibility to private.
174174
if (funcAST.getProto()->getName() != "main")
175-
function.setVisibility(mlir::FuncOp::Visibility::Private);
175+
function.setPrivate();
176176

177177
return function;
178178
}

mlir/examples/toy/Ch6/mlir/MLIRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class MLIRGenImpl {
172172

173173
// If this function isn't main, then set the visibility to private.
174174
if (funcAST.getProto()->getName() != "main")
175-
function.setVisibility(mlir::FuncOp::Visibility::Private);
175+
function.setPrivate();
176176

177177
return function;
178178
}

mlir/examples/toy/Ch7/mlir/MLIRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class MLIRGenImpl {
225225

226226
// If this function isn't main, then set the visibility to private.
227227
if (funcAST.getProto()->getName() != "main")
228-
function.setVisibility(mlir::FuncOp::Visibility::Private);
228+
function.setPrivate();
229229

230230
return function;
231231
}

mlir/include/mlir/IR/SymbolInterfaces.td

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
5353
return mlir::SymbolTable::getSymbolVisibility(this->getOperation());
5454
}]
5555
>,
56-
InterfaceMethod<"Sets the visibility of this symbol.",
57-
"void", "setVisibility", (ins "mlir::SymbolTable::Visibility":$vis), [{}],
58-
/*defaultImplementation=*/[{
59-
mlir::SymbolTable::setSymbolVisibility(this->getOperation(), vis);
60-
}]
61-
>,
6256
InterfaceMethod<"Returns true if this symbol has nested visibility.",
6357
"bool", "isNested", (ins), [{}],
6458
/*defaultImplementation=*/[{
@@ -77,6 +71,30 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
7771
return getVisibility() == mlir::SymbolTable::Visibility::Public;
7872
}]
7973
>,
74+
InterfaceMethod<"Sets the visibility of this symbol.",
75+
"void", "setVisibility", (ins "mlir::SymbolTable::Visibility":$vis), [{}],
76+
/*defaultImplementation=*/[{
77+
mlir::SymbolTable::setSymbolVisibility(this->getOperation(), vis);
78+
}]
79+
>,
80+
InterfaceMethod<"Sets the visibility of this symbol to be nested.",
81+
"void", "setNested", (ins), [{}],
82+
/*defaultImplementation=*/[{
83+
setVisibility(mlir::SymbolTable::Visibility::Nested);
84+
}]
85+
>,
86+
InterfaceMethod<"Sets the visibility of this symbol to be private.",
87+
"void", "setPrivate", (ins), [{}],
88+
/*defaultImplementation=*/[{
89+
setVisibility(mlir::SymbolTable::Visibility::Private);
90+
}]
91+
>,
92+
InterfaceMethod<"Sets the visibility of this symbol to be public.",
93+
"void", "setPublic", (ins), [{}],
94+
/*defaultImplementation=*/[{
95+
setVisibility(mlir::SymbolTable::Visibility::Public);
96+
}]
97+
>,
8098
InterfaceMethod<[{
8199
Get all of the uses of the current symbol that are nested within the
82100
given operation 'from'.

0 commit comments

Comments
 (0)