MLIR 24.0.0git
mlir::SymbolTable Class Reference

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.
Operationlookup (StringRef name) const
 Look up a symbol with the specified name, returning null if no such name exists.
template<typename T>
lookup (StringRef name) const
Operationlookup (StringAttr name) const
 Look up a symbol with the specified name, returning null if no such name exists.
template<typename T>
lookup (StringAttr name) const
void remove (Operation *op)
 Remove the given symbol from the table, without deleting it.
void erase (Operation *symbol)
 Erase the given symbol from the table and delete the operation.
StringAttr insert (Operation *symbol, Block::iterator insertPt={})
 Insert a new symbol into the table, and rename it as necessary to avoid collisions.
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.
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.
FailureOr< StringAttr > renameToUnique (Operation *op, ArrayRef< SymbolTable * > others)
OperationgetOp () const
 Returns the associated operation.

Static Public Member Functions

template<unsigned N, typename UniqueChecker>
static SmallString< N > generateSymbolName (StringRef name, UniqueChecker uniqueChecker, unsigned &uniquingCounter)
 Generate a unique symbol name.
static StringAttr getSymbolName (Operation *symbol)
 Returns the name of the given symbol operation, aborting if no symbol is present.
static StringRef getSymbolAttrName ()
 Compatibility alias for generated interface code that still refers to the symbol name attribute by convention.
static void setSymbolName (Operation *symbol, StringAttr name)
 Sets the name of the given symbol operation.
static void setSymbolName (Operation *symbol, StringRef name)
static Visibility getSymbolVisibility (Operation *symbol)
 Returns the visibility of the given symbol operation, which is required to implement SymbolOpInterface.
static void setSymbolVisibility (Operation *symbol, Visibility vis)
 Sets the visibility of the given symbol operation, which is required to implement SymbolOpInterface.
static OperationgetNearestSymbolTable (Operation *from)
 Returns the nearest symbol table from a 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 OperationlookupSymbolIn (Operation *op, StringAttr symbol)
 Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
static OperationlookupSymbolIn (Operation *op, StringRef symbol)
static OperationlookupSymbolIn (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.
static OperationlookupNearestSymbolFrom (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.
static OperationlookupNearestSymbolFrom (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< UseRangegetSymbolUses (Operation *from)
 Get an iterator range for all of the uses, for any symbol, that are nested within the given operation 'from'.
static std::optional< UseRangegetSymbolUses (Region *from)
static std::optional< UseRangegetSymbolUses (StringAttr symbol, Operation *from)
 Get all of the uses of the given symbol that are nested within the given operation 'from'.
static std::optional< UseRangegetSymbolUses (Operation *symbol, Operation *from)
static std::optional< UseRangegetSymbolUses (StringAttr symbol, Region *from)
static std::optional< UseRangegetSymbolUses (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'.
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'.
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)

Detailed Description

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.

Member Enumeration Documentation

◆ Visibility

enum class mlir::SymbolTable::Visibility
strong

An enumeration detailing the different visibility types that a symbol may have.

Enumerator
Public 

The symbol is public and may be referenced anywhere internal or external to the visible references in the IR.

Private 

The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the current symbol table.

Nested 

The symbol is visible to the current IR, which may include operations in symbol tables above the one that owns the current symbol.

Nested visibility allows for referencing a symbol outside of its current symbol table, while retaining the ability to observe all uses.

Definition at line 84 of file SymbolTable.h.

Constructor & Destructor Documentation

◆ SymbolTable()

SymbolTable::SymbolTable ( Operation * symbolTableOp)

Build a symbol table with the symbols within the given operation.

Definition at line 113 of file SymbolTable.cpp.

References mlir::Region::front(), getNameIfSymbol(), and mlir::Operation::getRegion().

Referenced by renameToUnique().

Member Function Documentation

◆ erase()

void SymbolTable::erase ( Operation * symbol)

Erase the given symbol from the table and delete the operation.

Definition at line 158 of file SymbolTable.cpp.

References mlir::Operation::erase(), and remove().

◆ generateSymbolName()

template<unsigned N, typename UniqueChecker>
SmallString< N > mlir::SymbolTable::generateSymbolName ( StringRef name,
UniqueChecker uniqueChecker,
unsigned & uniquingCounter )
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 104 of file SymbolTable.h.

Referenced by ensureSymbolNameIsUnique(), getDynamicSharedMemorySymbol(), and insert().

◆ getNearestSymbolTable()

◆ getOp()

Operation * mlir::SymbolTable::getOp ( ) const
inline

Returns the associated operation.

Definition at line 76 of file SymbolTable.h.

Referenced by rename(), rename(), and rename().

◆ getSymbolAttrName()

StringRef mlir::SymbolTable::getSymbolAttrName ( )
inlinestatic

Compatibility alias for generated interface code that still refers to the symbol name attribute by convention.

Definition at line 123 of file SymbolTable.h.

◆ getSymbolName()

StringAttr SymbolTable::getSymbolName ( Operation * symbol)
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 288 of file SymbolTable.cpp.

Referenced by collectSymbolScopes(), and insert().

◆ getSymbolUses() [1/6]

auto SymbolTable::getSymbolUses ( Operation * from)
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 773 of file SymbolTable.cpp.

References getSymbolUsesImpl().

Referenced by mlir::SymbolUserMap::SymbolUserMap(), and walkReferencedSymbolNodes().

◆ getSymbolUses() [2/6]

auto SymbolTable::getSymbolUses ( Operation * symbol,
Operation * from )
static

Definition at line 807 of file SymbolTable.cpp.

References getSymbolUsesImpl().

◆ getSymbolUses() [3/6]

auto SymbolTable::getSymbolUses ( Operation * symbol,
Region * from )
static

Definition at line 815 of file SymbolTable.cpp.

References getSymbolUsesImpl().

◆ getSymbolUses() [4/6]

auto SymbolTable::getSymbolUses ( Region * from)
static

Definition at line 776 of file SymbolTable.cpp.

References getSymbolUsesImpl().

◆ getSymbolUses() [5/6]

auto SymbolTable::getSymbolUses ( StringAttr symbol,
Operation * from )
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 803 of file SymbolTable.cpp.

References getSymbolUsesImpl().

◆ getSymbolUses() [6/6]

auto SymbolTable::getSymbolUses ( StringAttr symbol,
Region * from )
static

Definition at line 811 of file SymbolTable.cpp.

References getSymbolUsesImpl().

◆ getSymbolVisibility()

SymbolTable::Visibility SymbolTable::getSymbolVisibility ( Operation * symbol)
static

Returns the visibility of the given symbol operation, which is required to implement SymbolOpInterface.

Returns the visibility of the given symbol operation.

Definition at line 302 of file SymbolTable.cpp.

◆ insert()

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 167 of file SymbolTable.cpp.

References generateSymbolName(), mlir::Operation::getContext(), mlir::Operation::getParentOp(), and getSymbolName().

Referenced by addComdat(), allocLikeToGlobal(), mlir::bufferization::buildDeallocationLibraryFunction(), createAsyncDispatchFunction(), createDecl(), mlir::func::createFnDecl(), createLLVMFuncOp(), createParallelComputeFunction(), mlir::bufferization::getGlobalFor(), mlir::acc::getOrCreateGPUModule(), mlir::bufferization::insertSymbol(), mlir::LLVM::lookupOrCreateFn(), mlir::transform::detail::mergeSymbolsInto(), outlineExecuteOp(), and rename().

◆ lookup() [1/4]

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 142 of file SymbolTable.cpp.

◆ lookup() [2/4]

template<typename T>
T mlir::SymbolTable::lookup ( StringAttr name) const
inline

Definition at line 41 of file SymbolTable.h.

References lookup().

◆ lookup() [3/4]

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 139 of file SymbolTable.cpp.

References lookup().

Referenced by addComdat(), mlir::acc::createRuntimeCall(), mlir::acc::getOrCreateGPUModule(), lookup(), lookup(), mlir::SymbolTableCollection::lookupSymbolIn(), mlir::transform::detail::mergeSymbolsInto(), rename(), rename(), and verifyVariableOpErrorIf().

◆ lookup() [4/4]

template<typename T>
T mlir::SymbolTable::lookup ( StringRef name) const
inline

Definition at line 33 of file SymbolTable.h.

References lookup().

◆ lookupNearestSymbolFrom() [1/4]

◆ lookupNearestSymbolFrom() [2/4]

template<typename T>
T mlir::SymbolTable::lookupNearestSymbolFrom ( Operation * from,
StringAttr symbol )
inlinestatic

Definition at line 173 of file SymbolTable.h.

References lookupNearestSymbolFrom().

◆ lookupNearestSymbolFrom() [3/4]

Operation * SymbolTable::lookupNearestSymbolFrom ( Operation * from,
SymbolRefAttr symbol )
static

Definition at line 433 of file SymbolTable.cpp.

References getNearestSymbolTable(), and lookupSymbolIn().

◆ lookupNearestSymbolFrom() [4/4]

template<typename T>
T mlir::SymbolTable::lookupNearestSymbolFrom ( Operation * from,
SymbolRefAttr symbol )
inlinestatic

Definition at line 177 of file SymbolTable.h.

References lookupNearestSymbolFrom().

◆ lookupSymbolIn() [1/4]

◆ lookupSymbolIn() [2/4]

Operation * mlir::SymbolTable::lookupSymbolIn ( Operation * op,
StringRef symbol )
inlinestatic

Definition at line 155 of file SymbolTable.h.

References mlir::Operation::getContext(), and lookupSymbolIn().

◆ lookupSymbolIn() [3/4]

Operation * SymbolTable::lookupSymbolIn ( Operation * op,
SymbolRefAttr symbol )
static

Definition at line 377 of file SymbolTable.cpp.

References lookupSymbolIn().

◆ lookupSymbolIn() [4/4]

LogicalResult SymbolTable::lookupSymbolIn ( Operation * op,
SymbolRefAttr symbol,
SmallVectorImpl< Operation * > & symbols )
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 417 of file SymbolTable.cpp.

References lookupSymbolIn(), and lookupSymbolInImpl().

◆ remove()

void SymbolTable::remove ( Operation * op)

Remove the given symbol from the table, without deleting it.

Definition at line 146 of file SymbolTable.cpp.

References getNameIfSymbol(), and mlir::Operation::getParentOp().

Referenced by createLLVMFuncOp(), erase(), mlir::transform::detail::mergeSymbolsInto(), mlir::bufferization::removeSymbol(), and rename().

◆ rename() [1/4]

LogicalResult SymbolTable::rename ( Operation * op,
StringAttr to )

◆ rename() [2/4]

LogicalResult SymbolTable::rename ( Operation * op,
StringRef to )

Definition at line 249 of file SymbolTable.cpp.

References getContext(), getOp(), and rename().

◆ rename() [3/4]

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 213 of file SymbolTable.cpp.

References lookup(), and rename().

Referenced by rename(), rename(), rename(), and renameToUnique().

◆ rename() [4/4]

LogicalResult SymbolTable::rename ( StringAttr from,
StringRef to )

Definition at line 244 of file SymbolTable.cpp.

References getContext(), getOp(), and rename().

◆ renameToUnique() [1/2]

FailureOr< StringAttr > SymbolTable::renameToUnique ( Operation * op,
ArrayRef< SymbolTable * > others )

Definition at line 281 of file SymbolTable.cpp.

References getNameIfSymbol(), and renameToUnique().

◆ renameToUnique() [2/2]

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 255 of file SymbolTable.cpp.

References rename(), and SymbolTable().

Referenced by renameToUnique().

◆ replaceAllSymbolUses() [1/4]

LogicalResult SymbolTable::replaceAllSymbolUses ( Operation * oldSymbol,
StringAttr newSymbolName,
Operation * from )
static

Definition at line 922 of file SymbolTable.cpp.

References replaceAllSymbolUsesImpl().

◆ replaceAllSymbolUses() [2/4]

LogicalResult SymbolTable::replaceAllSymbolUses ( Operation * oldSymbol,
StringAttr newSymbolName,
Region * from )
static

Definition at line 932 of file SymbolTable.cpp.

References replaceAllSymbolUsesImpl().

◆ replaceAllSymbolUses() [3/4]

LogicalResult SymbolTable::replaceAllSymbolUses ( StringAttr oldSymbol,
StringAttr newSymbol,
Operation * from )
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 917 of file SymbolTable.cpp.

References replaceAllSymbolUsesImpl().

Referenced by mlir::spirv::combine(), mlir::encodeBindAttribute(), encodeKernelName(), mlirSymbolTableReplaceAllSymbolUses(), rename(), mlir::SymbolUserMap::replaceAllUsesWith(), and updateSymbolAndAllUses().

◆ replaceAllSymbolUses() [4/4]

LogicalResult SymbolTable::replaceAllSymbolUses ( StringAttr oldSymbol,
StringAttr newSymbol,
Region * from )
static

Definition at line 927 of file SymbolTable.cpp.

References replaceAllSymbolUsesImpl().

◆ setSymbolName() [1/2]

void SymbolTable::setSymbolName ( Operation * symbol,
StringAttr name )
static

Sets the name of the given symbol operation.

Definition at line 296 of file SymbolTable.cpp.

Referenced by mlir::encodeBindAttribute(), encodeKernelName(), rename(), setSymbolName(), and updateSymbolAndAllUses().

◆ setSymbolName() [2/2]

void mlir::SymbolTable::setSymbolName ( Operation * symbol,
StringRef name )
inlinestatic

Definition at line 127 of file SymbolTable.h.

References mlir::Operation::getContext(), and setSymbolName().

◆ setSymbolVisibility()

void SymbolTable::setSymbolVisibility ( Operation * symbol,
Visibility vis )
static

Sets the visibility of the given symbol operation, which is required to implement SymbolOpInterface.

Sets the visibility of the given symbol operation.

Definition at line 308 of file SymbolTable.cpp.

Referenced by outlineExecuteOp().

◆ symbolKnownUseEmpty() [1/4]

bool SymbolTable::symbolKnownUseEmpty ( Operation * symbol,
Operation * from )
static

Definition at line 846 of file SymbolTable.cpp.

References symbolKnownUseEmptyImpl().

◆ symbolKnownUseEmpty() [2/4]

bool SymbolTable::symbolKnownUseEmpty ( Operation * symbol,
Region * from )
static

Definition at line 852 of file SymbolTable.cpp.

References symbolKnownUseEmptyImpl().

◆ symbolKnownUseEmpty() [3/4]

bool SymbolTable::symbolKnownUseEmpty ( StringAttr symbol,
Operation * from )
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 843 of file SymbolTable.cpp.

References symbolKnownUseEmptyImpl().

◆ symbolKnownUseEmpty() [4/4]

bool SymbolTable::symbolKnownUseEmpty ( StringAttr symbol,
Region * from )
static

Definition at line 849 of file SymbolTable.cpp.

References symbolKnownUseEmptyImpl().

◆ walkSymbolTables()

void SymbolTable::walkSymbolTables ( Operation * op,
bool allSymUsesVisible,
function_ref< void(Operation *, bool)> callback )
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 336 of file SymbolTable.cpp.

References mlir::Operation::getRegions(), mlir::Operation::hasTrait(), and walkSymbolTables().

Referenced by mlirSymbolTableWalkSymbolTables(), mlir::SymbolUserMap::SymbolUserMap(), and walkSymbolTables().


The documentation for this class was generated from the following files: