9 #ifndef MLIR_IR_SYMBOLTABLE_H
10 #define MLIR_IR_SYMBOLTABLE_H
14 #include "llvm/ADT/SetVector.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/Support/RWMutex.h"
34 return dyn_cast_or_null<T>(
lookup(name));
42 return dyn_cast_or_null<T>(
lookup(name));
137 SymbolRefAttr symbol);
138 template <
typename T>
142 template <
typename T>
151 : owner(op), symbolRef(symbolRef) {}
164 SymbolRefAttr symbolRef;
170 UseRange(std::vector<SymbolUse> &&uses) : uses(std::move(uses)) {}
172 using iterator = std::vector<SymbolUse>::const_iterator;
175 bool empty()
const {
return uses.empty(); }
178 std::vector<SymbolUse> uses;
192 static std::optional<UseRange>
getSymbolUses(StringAttr symbol,
216 StringAttr newSymbol,
219 StringAttr newSymbolName,
222 StringAttr newSymbol,
Region *from);
224 StringAttr newSymbolName,
235 unsigned uniquingCounter = 0;
254 template <
typename T,
typename NameT>
256 return dyn_cast_or_null<T>(
272 template <
typename T>
276 template <
typename T>
305 : collection(collection) {}
319 template <
typename T,
typename NameT>
321 return dyn_cast_or_null<T>(
342 llvm::sys::SmartRWMutex<true> mutex;
362 auto it = symbolToUsers.find(symbol);
363 return it != symbolToUsers.end() ? it->second.getArrayRef() : std::nullopt;
368 return !symbolToUsers.count(symbol);
399 template <
typename ConcreteType>
412 template <
typename T>
419 template <
typename T>
427 template <
typename T>
443 NamedAttrList &attrs);
449 #include "mlir/IR/SymbolInterfaces.h.inc"
OpListType::iterator iterator
A symbol reference with a reference path containing a single element.
This class implements a lock-based shared wrapper around a symbol table collection that allows shared...
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name)
Lookup a symbol of a particular kind within the specified symbol table, returning null if the symbol ...
LockedSymbolTableCollection(SymbolTableCollection &collection)
Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
Look up a symbol with the specified name within the specified symbol table operation,...
A trait used to provide symbol table functionalities to a region operation.
Operation * lookupSymbol(SymbolRefAttr symbol)
Operation * lookupSymbol(StringRef name)
T lookupSymbol(SymbolRefAttr symbol)
T lookupSymbol(StringAttr name)
T lookupSymbol(StringRef name)
Operation * lookupSymbol(StringAttr name)
Look up a symbol with the specified name, returning null if no such name exists.
static LogicalResult verifyRegionTrait(Operation *op)
Helper class for implementing traits.
Operation * getOperation()
Return the ultimate Operation being worked on.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class represents a collection of SymbolTables.
T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name)
Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol)
Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
Look up a symbol with the specified name within the specified symbol table operation,...
SymbolTable & getSymbolTable(Operation *op)
Lookup, or create, a symbol table for an operation.
This class represents a specific symbol use.
SymbolUse(Operation *op, SymbolRefAttr symbolRef)
SymbolRefAttr getSymbolRef() const
Return the symbol reference that this use represents.
Operation * getUser() const
Return the operation user of this symbol reference.
This class implements a range of SymbolRef uses.
UseRange(std::vector< SymbolUse > &&uses)
std::vector< SymbolUse >::const_iterator iterator
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
static Visibility getSymbolVisibility(Operation *symbol)
Returns the visibility of the given symbol operation.
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
static void setSymbolVisibility(Operation *symbol, Visibility vis)
Sets the visibility of the given symbol operation.
Operation * getOp() const
Returns the associated operation.
static T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol)
static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol, StringAttr newSymbol, Operation *from)
Attempt to replace all uses of the given symbol 'oldSymbol' with the provided symbol 'newSymbol' that...
Visibility
An enumeration detailing the different visibility types that a symbol may have.
@ Nested
The symbol is visible to the current IR, which may include operations in symbol tables above the one ...
@ Public
The symbol is public and may be referenced anywhere internal or external to the visible references in...
@ Private
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the...
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
static T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
void erase(Operation *symbol)
Erase the given symbol from the table and delete the operation.
static void setSymbolName(Operation *symbol, StringRef name)
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
Operation * lookup(StringRef name) const
Look up a symbol with the specified name, returning null if no such name exists.
T lookup(StringRef name) const
SymbolTable(Operation *symbolTableOp)
Build a symbol table with the symbols within the given operation.
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
static Operation * lookupSymbolIn(Operation *op, StringRef symbol)
static void setSymbolName(Operation *symbol, StringAttr name)
Sets the name of the given symbol operation.
static bool symbolKnownUseEmpty(StringAttr symbol, Operation *from)
Return if the given symbol is known to have no uses that are nested within the given operation 'from'...
static void walkSymbolTables(Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback)
Walks all symbol table operations nested within, and including, op.
static StringAttr getSymbolName(Operation *symbol)
Returns the name of the given symbol operation, aborting if no symbol is present.
static std::optional< UseRange > getSymbolUses(Operation *from)
Get an iterator range for all of the uses, for any symbol, that are nested within the given operation...
T lookup(StringAttr name) const
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
void remove(Operation *op)
Remove the given symbol from the table, without deleting it.
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
This class represents a map of symbols to users, and provides efficient implementations of symbol que...
bool useEmpty(Operation *symbol) const
Return true if the given symbol has no uses.
void replaceAllUsesWith(Operation *symbol, StringAttr newSymbolName)
Replace all of the uses of the given symbol with newSymbolName.
ArrayRef< Operation * > getUsers(Operation *symbol) const
Return the users of the provided symbol operation.
SymbolUserMap(SymbolTableCollection &symbolTable, Operation *symbolTableOp)
Build a user map for all of the symbols defined in regions nested under 'symbolTableOp'.
LogicalResult verifySymbol(Operation *op)
LogicalResult verifySymbolTable(Operation *op)
ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser, NamedAttrList &attrs)
Parse an optional visibility attribute keyword (i.e., public, private, or nested) without quotes in a...
This header declares functions that assist transformations in the MemRef dialect.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
This class represents an efficient way to signal success or failure.