[MLIR] Move SymbolOpInterface::isPublic() and friends to SymbolOpInterface Trait.

- This will allow calling these functions from Op's that support this interface (like FuncOp) directly:

```
FuncOp func = ...
 func.isPrivate()
```

Differential Revision: https://reviews.llvm.org/D82060
This commit is contained in:
Rahul Joshi 2020-06-17 15:51:49 -07:00
parent f7453a97ce
commit 3d316eb06d
1 changed files with 18 additions and 9 deletions

View File

@ -58,6 +58,24 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
mlir::SymbolTable::setSymbolVisibility(this->getOperation(), vis);
}]
>,
InterfaceMethod<"Returns true if this symbol has nested visibility.",
"bool", "isNested", (ins), [{}],
/*defaultImplementation=*/[{
return getVisibility() == mlir::SymbolTable::Visibility::Nested;
}]
>,
InterfaceMethod<"Returns true if this symbol has private visibility.",
"bool", "isPrivate", (ins), [{}],
/*defaultImplementation=*/[{
return getVisibility() == mlir::SymbolTable::Visibility::Private;
}]
>,
InterfaceMethod<"Returns true if this symbol has public visibility.",
"bool", "isPublic", (ins), [{}],
/*defaultImplementation=*/[{
return getVisibility() == mlir::SymbolTable::Visibility::Public;
}]
>,
InterfaceMethod<[{
Get all of the uses of the current symbol that are nested within the
given operation 'from'.
@ -124,20 +142,11 @@ def Symbol : OpInterface<"SymbolOpInterface"> {
}];
let extraClassDeclaration = [{
using Visibility = mlir::SymbolTable::Visibility;
/// Custom classof that handles the case where the symbol is optional.
static bool classof(Operation *op) {
return Base::classof(op)
&& op->getAttr(::mlir::SymbolTable::getSymbolAttrName());
}
/// Returns true if this symbol has nested visibility.
bool isNested() { return getVisibility() == Visibility::Nested; }
/// Returns true if this symbol has private visibility.
bool isPrivate() { return getVisibility() == Visibility::Private; }
/// Returns true if this symbol has public visibility.
bool isPublic() { return getVisibility() == Visibility::Public; }
}];
let extraTraitClassDeclaration = [{