9 #ifndef MLIR_IR_SYMBOLTABLE_H 10 #define MLIR_IR_SYMBOLTABLE_H 14 #include "llvm/ADT/SetVector.h" 15 #include "llvm/ADT/StringMap.h" 33 return dyn_cast_or_null<T>(
lookup(name));
41 return dyn_cast_or_null<T>(
lookup(name));
133 SymbolRefAttr symbol);
134 template <
typename T>
138 template <
typename T>
147 : owner(op), symbolRef(symbolRef) {}
160 SymbolRefAttr symbolRef;
166 UseRange(std::vector<SymbolUse> &&uses) : uses(std::move(uses)) {}
168 using iterator = std::vector<SymbolUse>::const_iterator;
171 bool empty()
const {
return uses.empty(); }
174 std::vector<SymbolUse> uses;
210 StringAttr newSymbol,
213 StringAttr newSymbolName,
216 StringAttr newSymbol,
Region *from);
218 StringAttr newSymbolName,
229 unsigned uniquingCounter = 0;
248 template <
typename T,
typename NameT>
250 return dyn_cast_or_null<T>(
266 template <
typename T>
270 template <
typename T>
300 auto it = symbolToUsers.find(symbol);
301 return it != symbolToUsers.end() ? it->second.getArrayRef() : llvm::None;
306 return !symbolToUsers.count(symbol);
310 void replaceAllUsesWith(
Operation *symbol, StringAttr newSymbolName);
337 template <
typename ConcreteType>
350 template <
typename T>
352 return dyn_cast_or_null<T>(lookupSymbol(name));
357 template <
typename T>
359 return dyn_cast_or_null<T>(lookupSymbol(symbol));
365 template <
typename T>
367 return dyn_cast_or_null<T>(lookupSymbol(name));
387 #include "mlir/IR/SymbolInterfaces.h.inc" 389 #endif // MLIR_IR_SYMBOLTABLE_H TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
static StringAttr getSymbolName(Operation *symbol)
Returns the name of the given symbol operation, aborting if no symbol is present. ...
This class contains a list of basic blocks and a link to the parent operation it is attached to...
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name) const
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
Operation * getUser() const
Return the operation user of this symbol reference.
SymbolUse(Operation *op, SymbolRefAttr symbolRef)
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
Operation is a basic unit of execution within MLIR.
T lookupSymbol(SymbolRefAttr symbol)
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
static Visibility getSymbolVisibility(Operation *symbol)
Returns the visibility of the given symbol operation.
static 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(StringRef name) const
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
Operation * lookupSymbol(SymbolRefAttr symbol)
The symbol is public and may be referenced anywhere internal or external to the visible references in...
The OpAsmParser has methods for interacting with the asm parser: parsing things from it...
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
void erase(Operation *symbol)
Erase the given symbol from the table.
This class implements a range of SymbolRef uses.
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
MLIRContext * getContext()
Return the context this operation is associated with.
static T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol)
Operation * lookupSymbol(StringRef name)
static T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
The symbol is visible to the current IR, which may include operations in symbol tables above the one ...
Visibility
An enumeration detailing the different visibility types that a symbol may have.
static void setSymbolName(Operation *symbol, StringAttr name)
Sets the name of the given symbol operation.
This class represents an efficient way to signal success or failure.
This class represents a collection of SymbolTables.
OpListType::iterator iterator
Operation * getOp() const
Returns the associated 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'...
T lookupSymbol(StringAttr name)
static LogicalResult verifyRegionTrait(Operation *op)
UseRange(std::vector< SymbolUse > &&uses)
A trait used to provide symbol table functionalities to a region operation.
SymbolRefAttr getSymbolRef() const
Return the symbol reference that this use represents.
static void walkSymbolTables(Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback)
Walks all symbol table operations nested within, and including, op.
ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser, NamedAttrList &attrs)
Parse an optional visibility attribute keyword (i.e., public, private, or nested) without quotes in a...
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the...
This class represents a map of symbols to users, and provides efficient implementations of symbol que...
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of...
ArrayRef< Operation * > getUsers(Operation *symbol) const
Return the users of the provided symbol operation.
T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
LogicalResult verifySymbolTable(Operation *op)
Helper class for implementing traits.
static void setSymbolVisibility(Operation *symbol, Visibility vis)
Sets the visibility of the given symbol operation.
Operation * lookup(StringRef name) const
Look up a symbol with the specified name, returning null if no such name exists.
LogicalResult verifySymbol(Operation *op)
bool useEmpty(Operation *symbol) const
Return true if the given symbol has no uses.
static void setSymbolName(Operation *symbol, StringRef name)
SymbolTable(Operation *symbolTableOp)
Build a symbol table with the symbols within the given operation.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
T lookup(StringAttr name) const
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...
static Operation * lookupSymbolIn(Operation *op, StringRef symbol)
This class represents success/failure for parsing-like operations that find it important to chain tog...
This class represents a specific symbol use.
std::vector< SymbolUse >::const_iterator iterator
Operation * lookupSymbol(StringAttr name)
Look up a symbol with the specified name, returning null if no such name exists.
T lookupSymbol(StringRef name)