/// Sets the visibility of the given symbol operation.
static void setSymbolVisibility(Operation *symbol, Visibility vis);
+ /// Returns the nearest symbol table from a given operation `from`. Returns
+ /// nullptr if no valid parent symbol table could be found.
+ static Operation *getNearestSymbolTable(Operation *from);
+
/// Returns the operation registered with the given symbol name with the
/// regions of 'symbolTableOp'. 'symbolTableOp' is required to be an operation
/// with the 'OpTrait::SymbolTable' trait.
return !op->getDialect() && op->getNumRegions() == 1;
}
-/// Returns the nearest symbol table from a given operation `from`. Returns
-/// nullptr if no valid parent symbol table could be found.
-static Operation *getNearestSymbolTable(Operation *from) {
- assert(from && "expected valid operation");
- if (isPotentiallyUnknownSymbolTable(from))
- return nullptr;
-
- while (!from->hasTrait<OpTrait::SymbolTable>()) {
- from = from->getParentOp();
-
- // Check that this is a valid op and isn't an unknown symbol table.
- if (!from || isPotentiallyUnknownSymbolTable(from))
- return nullptr;
- }
- return from;
-}
-
/// Returns the string name of the given symbol, or None if this is not a
/// symbol.
static Optional<StringRef> getNameIfSymbol(Operation *symbol) {
symbol->setAttr(getVisibilityAttrName(), StringAttr::get(visName, ctx));
}
+/// Returns the nearest symbol table from a given operation `from`. Returns
+/// nullptr if no valid parent symbol table could be found.
+Operation *SymbolTable::getNearestSymbolTable(Operation *from) {
+ assert(from && "expected valid operation");
+ if (isPotentiallyUnknownSymbolTable(from))
+ return nullptr;
+
+ while (!from->hasTrait<OpTrait::SymbolTable>()) {
+ from = from->getParentOp();
+
+ // Check that this is a valid op and isn't an unknown symbol table.
+ if (!from || isPotentiallyUnknownSymbolTable(from))
+ return nullptr;
+ }
+ return from;
+}
+
/// Returns the operation registered with the given symbol name with the
/// regions of 'symbolTableOp'. 'symbolTableOp' is required to be an operation
/// with the 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol
if (limitAncestor == symbol) {
// Check that the nearest symbol table is 'symbol's parent. SymbolRefAttr
// doesn't support parent references.
- if (getNearestSymbolTable(limit) != symbol->getParentOp())
+ if (SymbolTable::getNearestSymbolTable(limit) != symbol->getParentOp())
return WalkResult::advance();
return callback(SymbolRefAttr::get(symbolName, symbol->getContext()),
limit);