MLIR
22.0.0git
|
This class allows for representing and managing the symbol table used by operations with the 'SymbolTable' trait. More...
#include "mlir/IR/SymbolTable.h"
Classes | |
class | SymbolUse |
This class represents a specific symbol use. More... | |
class | UseRange |
This class implements a range of SymbolRef uses. More... | |
Public Types | |
enum class | Visibility { Public , Private , Nested } |
An enumeration detailing the different visibility types that a symbol may have. More... | |
Public Member Functions | |
SymbolTable (Operation *symbolTableOp) | |
Build a symbol table with the symbols within the given operation. More... | |
Operation * | lookup (StringRef name) const |
Look up a symbol with the specified name, returning null if no such name exists. More... | |
template<typename T > | |
T | lookup (StringRef name) const |
Operation * | lookup (StringAttr name) const |
Look up a symbol with the specified name, returning null if no such name exists. More... | |
template<typename T > | |
T | lookup (StringAttr name) const |
void | remove (Operation *op) |
Remove the given symbol from the table, without deleting it. More... | |
void | erase (Operation *symbol) |
Erase the given symbol from the table and delete the operation. More... | |
StringAttr | insert (Operation *symbol, Block::iterator insertPt={}) |
Insert a new symbol into the table, and rename it as necessary to avoid collisions. More... | |
LogicalResult | rename (StringAttr from, StringAttr to) |
Renames the given op or the op refered to by the given name to the given new name and updates the symbol table and all usages of the symbol accordingly. More... | |
LogicalResult | rename (Operation *op, StringAttr to) |
LogicalResult | rename (StringAttr from, StringRef to) |
LogicalResult | rename (Operation *op, StringRef to) |
FailureOr< StringAttr > | renameToUnique (StringAttr from, ArrayRef< SymbolTable * > others) |
Renames the given op or the op refered to by the given name to the a name that is unique within this and the provided other symbol tables and updates the symbol table and all usages of the symbol accordingly. More... | |
FailureOr< StringAttr > | renameToUnique (Operation *op, ArrayRef< SymbolTable * > others) |
Operation * | getOp () const |
Returns the associated operation. More... | |
Static Public Member Functions | |
static StringRef | getSymbolAttrName () |
Return the name of the attribute used for symbol names. More... | |
static StringRef | getVisibilityAttrName () |
Return the name of the attribute used for symbol visibility. More... | |
template<unsigned N, typename UniqueChecker > | |
static SmallString< N > | generateSymbolName (StringRef name, UniqueChecker uniqueChecker, unsigned &uniquingCounter) |
Generate a unique symbol name. More... | |
static StringAttr | getSymbolName (Operation *symbol) |
Returns the name of the given symbol operation, aborting if no symbol is present. More... | |
static void | setSymbolName (Operation *symbol, StringAttr name) |
Sets the name of the given symbol operation. More... | |
static void | setSymbolName (Operation *symbol, StringRef name) |
static Visibility | getSymbolVisibility (Operation *symbol) |
Returns the visibility of the given symbol operation. More... | |
static void | setSymbolVisibility (Operation *symbol, Visibility vis) |
Sets the visibility of the given symbol operation. More... | |
static Operation * | getNearestSymbolTable (Operation *from) |
Returns the nearest symbol table from a given operation from . More... | |
static void | walkSymbolTables (Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback) |
Walks all symbol table operations nested within, and including, op . More... | |
static Operation * | lookupSymbolIn (Operation *op, StringAttr symbol) |
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'. More... | |
static Operation * | lookupSymbolIn (Operation *op, StringRef symbol) |
static Operation * | lookupSymbolIn (Operation *op, SymbolRefAttr symbol) |
static LogicalResult | lookupSymbolIn (Operation *op, SymbolRefAttr symbol, SmallVectorImpl< Operation * > &symbols) |
A variant of 'lookupSymbolIn' that returns all of the symbols referenced by a given SymbolRefAttr. More... | |
static Operation * | lookupNearestSymbolFrom (Operation *from, StringAttr symbol) |
Returns the operation registered with the given symbol name within the closest parent operation of, or including, 'from' with the 'OpTrait::SymbolTable' trait. More... | |
static Operation * | lookupNearestSymbolFrom (Operation *from, SymbolRefAttr symbol) |
template<typename T > | |
static T | lookupNearestSymbolFrom (Operation *from, StringAttr symbol) |
template<typename T > | |
static T | lookupNearestSymbolFrom (Operation *from, SymbolRefAttr symbol) |
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 'from'. More... | |
static std::optional< UseRange > | getSymbolUses (Region *from) |
static std::optional< UseRange > | getSymbolUses (StringAttr symbol, Operation *from) |
Get all of the uses of the given symbol that are nested within the given operation 'from'. More... | |
static std::optional< UseRange > | getSymbolUses (Operation *symbol, Operation *from) |
static std::optional< UseRange > | getSymbolUses (StringAttr symbol, Region *from) |
static std::optional< UseRange > | getSymbolUses (Operation *symbol, Region *from) |
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'. More... | |
static bool | symbolKnownUseEmpty (Operation *symbol, Operation *from) |
static bool | symbolKnownUseEmpty (StringAttr symbol, Region *from) |
static bool | symbolKnownUseEmpty (Operation *symbol, Region *from) |
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 are nested within the given operation 'from'. More... | |
static LogicalResult | replaceAllSymbolUses (Operation *oldSymbol, StringAttr newSymbolName, Operation *from) |
static LogicalResult | replaceAllSymbolUses (StringAttr oldSymbol, StringAttr newSymbol, Region *from) |
static LogicalResult | replaceAllSymbolUses (Operation *oldSymbol, StringAttr newSymbolName, Region *from) |
This class allows for representing and managing the symbol table used by operations with the 'SymbolTable' trait.
Inserting into and erasing from this SymbolTable will also insert and erase from the Operation given to it at construction.
Definition at line 24 of file SymbolTable.h.
|
strong |
An enumeration detailing the different visibility types that a symbol may have.
Definition at line 90 of file SymbolTable.h.
SymbolTable::SymbolTable | ( | Operation * | symbolTableOp | ) |
Build a symbol table with the symbols within the given operation.
Definition at line 117 of file SymbolTable.cpp.
References mlir::Region::front(), mlir::get(), mlir::Operation::getContext(), getNameIfSymbol(), mlir::Operation::getNumRegions(), mlir::Operation::getRegion(), getSymbolAttrName(), mlir::Region::hasOneBlock(), and mlir::Operation::hasTrait().
void SymbolTable::erase | ( | Operation * | symbol | ) |
Erase the given symbol from the table and delete the operation.
Definition at line 161 of file SymbolTable.cpp.
References mlir::Operation::erase(), and remove().
|
inlinestatic |
Generate a unique symbol name.
Iteratively increase uniquingCounter and use it as a suffix for symbol names until uniqueChecker does not detect any conflict.
Definition at line 110 of file SymbolTable.h.
Referenced by ensureSymbolNameIsUnique().
Returns the nearest symbol table from a given operation from
.
Returns nullptr if no valid parent symbol table could be found.
Definition at line 336 of file SymbolTable.cpp.
References mlir::Operation::getParentOp(), mlir::Operation::hasTrait(), and isPotentiallyUnknownSymbolTable().
Referenced by mlir::transform::applyTransformNamedSequence(), collectSymbolScopes(), declareReduction(), mlir::spirv::getPushConstantValue(), lookupNearestSymbolFrom(), mlir::SymbolTableCollection::lookupNearestSymbolFrom(), and mlir::spirv::lookupTargetEnv().
|
inline |
Returns the associated operation.
Definition at line 79 of file SymbolTable.h.
Referenced by mlir::SymbolTableAnalysis::getTopLevelOp(), and rename().
|
inlinestatic |
Return the name of the attribute used for symbol names.
Definition at line 76 of file SymbolTable.h.
Referenced by mlir::Namespace::add(), collectValidReferencesFor(), getNameIfSymbol(), getOpAndSymbolNames(), lookupSymbolIn(), lowerAsEntryFunction(), mlir::GPUFuncOpLowering::matchAndRewrite(), mlirSymbolTableGetSymbolAttributeName(), mlir::function_interface_impl::parseFunctionOp(), mlir::function_interface_impl::printFunctionAttributes(), mlir::function_interface_impl::printFunctionOp(), printIR(), setSymbolName(), SymbolTable(), mlir::detail::verifySymbol(), and mlir::detail::verifySymbolTable().
|
static |
Returns the name of the given symbol operation, aborting if no symbol is present.
Returns the name of the given symbol operation.
Definition at line 291 of file SymbolTable.cpp.
References getNameIfSymbol().
Referenced by collectSymbolScopes(), and insert().
|
static |
Get an iterator range for all of the uses, for any symbol, that are nested within the given operation 'from'.
This does not traverse into any nested symbol tables. This function returns std::nullopt if there are any unknown operations that may potentially be symbol tables.
This does not traverse into any nested symbol tables, and will also only return uses on 'from' if it does not also define a symbol table. This is because we treat the region as the boundary of the symbol table, and not the op itself. This function returns std::nullopt if there are any unknown operations that may potentially be symbol tables.
Definition at line 783 of file SymbolTable.cpp.
References getSymbolUsesImpl().
Referenced by mlir::SymbolUserMap::SymbolUserMap(), and walkReferencedSymbolNodes().
Definition at line 817 of file SymbolTable.cpp.
References getSymbolUsesImpl().
Definition at line 825 of file SymbolTable.cpp.
References getSymbolUsesImpl().
|
static |
Definition at line 786 of file SymbolTable.cpp.
References getSymbolUsesImpl().
|
static |
Get all of the uses of the given symbol that are nested within the given operation 'from'.
This does not traverse into any nested symbol tables. This function returns std::nullopt if there are any unknown operations that may potentially be symbol tables.
Definition at line 813 of file SymbolTable.cpp.
References getSymbolUsesImpl().
|
static |
Definition at line 821 of file SymbolTable.cpp.
References getSymbolUsesImpl().
|
static |
Returns the visibility of the given symbol operation.
Definition at line 303 of file SymbolTable.cpp.
References mlir::Operation::getAttrOfType(), getVisibilityAttrName(), Nested, Private, and Public.
|
inlinestatic |
Return the name of the attribute used for symbol visibility.
Definition at line 82 of file SymbolTable.h.
Referenced by getSymbolVisibility(), mlirSymbolTableGetVisibilityAttributeName(), mlir::function_interface_impl::parseFunctionOp(), mlir::impl::parseOptionalVisibilityKeyword(), mlir::function_interface_impl::printFunctionOp(), setSymbolVisibility(), and mlir::detail::verifySymbol().
StringAttr SymbolTable::insert | ( | Operation * | symbol, |
Block::iterator | insertPt = {} |
||
) |
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
Insert a new symbol into the table and associated operation if not already there and rename it as necessary to avoid collisions.
Also insert at the specified location in the body of the associated operation if it is not already there. It is asserted that the symbol is not inside another operation. Return the name of the symbol after insertion as attribute.
Return the name of the symbol after insertion as attribute.
Definition at line 170 of file SymbolTable.cpp.
References mlir::Region::front(), mlir::Operation::getContext(), mlir::Operation::getParentOp(), mlir::Operation::getRegion(), and getSymbolName().
Referenced by addComdat(), mlir::bufferization::buildDeallocationLibraryFunction(), mlir::convertFuncOpToLLVMFuncOp(), createAsyncDispatchFunction(), createDecl(), createParallelComputeFunction(), mlir::bufferization::getGlobalFor(), mlir::LLVM::lookupOrCreateFn(), mlir::transform::detail::mergeSymbolsInto(), outlineExecuteOp(), and rename().
Operation * SymbolTable::lookup | ( | StringAttr | name | ) | const |
Look up a symbol with the specified name, returning null if no such name exists.
Names never include the @ on them.
Definition at line 145 of file SymbolTable.cpp.
|
inline |
Definition at line 41 of file SymbolTable.h.
References lookup().
Operation * SymbolTable::lookup | ( | StringRef | name | ) | const |
Look up a symbol with the specified name, returning null if no such name exists.
Names never include the @ on them.
Definition at line 142 of file SymbolTable.cpp.
References mlir::get(), and mlir::Operation::getContext().
Referenced by addComdat(), lookup(), mlir::SymbolTableCollection::lookupSymbolIn(), mlir::LockedSymbolTableCollection::lookupSymbolIn(), mlir::transform::detail::mergeSymbolsInto(), rename(), and updateCalls().
|
inline |
Definition at line 33 of file SymbolTable.h.
References lookup().
Returns the operation registered with the given symbol name within the closest parent operation of, or including, 'from' with the 'OpTrait::SymbolTable' trait.
Returns the operation registered with the given symbol name within the closes parent operation with the 'OpTrait::SymbolTable' trait.
Returns nullptr if no valid symbol was found.
Definition at line 454 of file SymbolTable.cpp.
References getNearestSymbolTable(), and lookupSymbolIn().
Referenced by getCalledFunction(), lookupNearestSymbolFrom(), mlir::irdl::lookupSymbolNearDialect(), and verifyComdat().
|
inlinestatic |
Definition at line 174 of file SymbolTable.h.
References lookupNearestSymbolFrom().
Definition at line 459 of file SymbolTable.cpp.
References getNearestSymbolTable(), and lookupSymbolIn().
|
inlinestatic |
Definition at line 178 of file SymbolTable.h.
References lookupNearestSymbolFrom().
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.
'symbolTableOp' is required to be an operation with the 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol was found.
Definition at line 384 of file SymbolTable.cpp.
References mlir::Region::empty(), mlir::Region::front(), mlir::get(), mlir::Operation::getContext(), getNameIfSymbol(), mlir::Operation::getRegion(), getSymbolAttrName(), and mlir::Operation::hasTrait().
Referenced by compileAndExecuteSingleReturnFunction(), compileAndExecuteVoidFunction(), ensureSymbolNameIsUnique(), lookupNearestSymbolFrom(), lookupOrCreateSPIRVFn(), mlir::OpTrait::SymbolTable< ConcreteType >::lookupSymbol(), lookupSymbolIn(), renameSymbol(), and updateSymbolAndAllUses().
|
inlinestatic |
Definition at line 156 of file SymbolTable.h.
References mlir::get(), mlir::Operation::getContext(), and lookupSymbolIn().
Definition at line 399 of file SymbolTable.cpp.
References lookupSymbolIn().
|
static |
A variant of 'lookupSymbolIn' that returns all of the symbols referenced by a given SymbolRefAttr.
Returns failure if any of the nested references could not be resolved.
Definition at line 443 of file SymbolTable.cpp.
References lookupSymbolIn(), and lookupSymbolInImpl().
void SymbolTable::remove | ( | Operation * | op | ) |
Remove the given symbol from the table, without deleting it.
Definition at line 149 of file SymbolTable.cpp.
References getNameIfSymbol(), and mlir::Operation::getParentOp().
Referenced by mlir::convertFuncOpToLLVMFuncOp(), erase(), mlir::transform::detail::mergeSymbolsInto(), and rename().
LogicalResult SymbolTable::rename | ( | Operation * | op, |
StringAttr | to | ||
) |
Definition at line 221 of file SymbolTable.cpp.
References getNameIfSymbol(), getOp(), mlir::Operation::getParentOp(), insert(), lookup(), remove(), replaceAllSymbolUses(), and setSymbolName().
LogicalResult SymbolTable::rename | ( | Operation * | op, |
StringRef | to | ||
) |
Definition at line 252 of file SymbolTable.cpp.
References mlir::get(), getContext(), getOp(), and rename().
LogicalResult SymbolTable::rename | ( | StringAttr | from, |
StringAttr | to | ||
) |
Renames the given op or the op refered to by the given name to the given new name and updates the symbol table and all usages of the symbol accordingly.
Fails if the updating of the usages fails.
Definition at line 216 of file SymbolTable.cpp.
References lookup().
Referenced by rename(), and renameToUnique().
LogicalResult SymbolTable::rename | ( | StringAttr | from, |
StringRef | to | ||
) |
Definition at line 247 of file SymbolTable.cpp.
References mlir::get(), getContext(), getOp(), and rename().
FailureOr< StringAttr > SymbolTable::renameToUnique | ( | Operation * | op, |
ArrayRef< SymbolTable * > | others | ||
) |
Definition at line 284 of file SymbolTable.cpp.
References getNameIfSymbol(), and renameToUnique().
FailureOr< StringAttr > SymbolTable::renameToUnique | ( | StringAttr | from, |
ArrayRef< SymbolTable * > | others | ||
) |
Renames the given op or the op refered to by the given name to the a name that is unique within this and the provided other symbol tables and updates the symbol table and all usages of the symbol accordingly.
Returns the new name or failure if the renaming fails.
Definition at line 258 of file SymbolTable.cpp.
References mlir::get(), and rename().
Referenced by renameToUnique().
|
static |
Definition at line 932 of file SymbolTable.cpp.
References replaceAllSymbolUsesImpl().
|
static |
Definition at line 942 of file SymbolTable.cpp.
References replaceAllSymbolUsesImpl().
|
static |
Attempt to replace all uses of the given symbol 'oldSymbol' with the provided symbol 'newSymbol' that are nested within the given operation 'from'.
This does not traverse into any nested symbol tables. If there are any unknown operations that may potentially be symbol tables, no uses are replaced and failure is returned.
Definition at line 927 of file SymbolTable.cpp.
References replaceAllSymbolUsesImpl().
Referenced by mlir::spirv::combine(), mlir::encodeBindAttribute(), encodeKernelName(), mlirSymbolTableReplaceAllSymbolUses(), rename(), mlir::SymbolUserMap::replaceAllUsesWith(), and updateSymbolAndAllUses().
|
static |
Definition at line 937 of file SymbolTable.cpp.
References replaceAllSymbolUsesImpl().
|
static |
Sets the name of the given symbol operation.
Definition at line 298 of file SymbolTable.cpp.
References getSymbolAttrName(), and mlir::Operation::setAttr().
Referenced by mlir::encodeBindAttribute(), encodeKernelName(), rename(), setSymbolName(), and updateSymbolAndAllUses().
|
inlinestatic |
Definition at line 130 of file SymbolTable.h.
References mlir::get(), mlir::Operation::getContext(), and setSymbolName().
|
static |
Sets the visibility of the given symbol operation.
Definition at line 316 of file SymbolTable.cpp.
References mlir::get(), mlir::Operation::getContext(), getVisibilityAttrName(), Nested, Private, Public, mlir::Operation::removeAttr(), and mlir::Operation::setAttr().
Referenced by outlineExecuteOp().
Definition at line 856 of file SymbolTable.cpp.
References symbolKnownUseEmptyImpl().
Definition at line 862 of file SymbolTable.cpp.
References symbolKnownUseEmptyImpl().
|
static |
Return if the given symbol is known to have no uses that are nested within the given operation 'from'.
This does not traverse into any nested symbol tables. This function will also return false if there are any unknown operations that may potentially be symbol tables. This doesn't necessarily mean that there are no uses, we just can't conservatively prove it.
This does not traverse into any nested symbol tables. This function will also return false if there are any unknown operations that may potentially be symbol tables.
Definition at line 853 of file SymbolTable.cpp.
References symbolKnownUseEmptyImpl().
|
static |
Definition at line 859 of file SymbolTable.cpp.
References symbolKnownUseEmptyImpl().
|
static |
Walks all symbol table operations nested within, and including, op
.
For each symbol table operation, the provided callback is invoked with the op and a boolean signifying if the symbols within that symbol table can be treated as if all uses within the IR are visible to the caller. allSymUsesVisible
identifies whether all of the symbol uses of symbols within op
are visible.
For each symbol table operation, the provided callback is invoked with the op and a boolean signifying if the symbols within that symbol table can be treated as if all uses are visible. allSymUsesVisible
identifies whether all of the symbol uses of symbols within op
are visible.
Definition at line 356 of file SymbolTable.cpp.
References mlir::Operation::getRegions(), and mlir::Operation::hasTrait().
Referenced by mlirSymbolTableWalkSymbolTables(), and mlir::SymbolUserMap::SymbolUserMap().