MLIR 22.0.0git
SymbolTable.cpp File Reference
#include "mlir/IR/SymbolTable.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/OpImplementation.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include <optional>
#include "mlir/IR/SymbolInterfaces.cpp.inc"

Go to the source code of this file.

Functions

static bool isPotentiallyUnknownSymbolTable (Operation *op)
 Return true if the given operation is unknown and may potentially define a symbol table.
static StringAttr getNameIfSymbol (Operation *op)
 Returns the string name of the given symbol, or null if this is not a symbol.
static StringAttr getNameIfSymbol (Operation *op, StringAttr symbolAttrNameId)
static LogicalResult collectValidReferencesFor (Operation *symbol, StringAttr symbolName, Operation *within, SmallVectorImpl< SymbolRefAttr > &results)
 Computes the nested symbol reference attribute for the symbol 'symbolName' that are usable within the symbol table operations from 'symbol' as far up to the given operation 'within', where 'within' is an ancestor of 'symbol'.
static std::optional< WalkResultwalkSymbolTable (MutableArrayRef< Region > regions, function_ref< std::optional< WalkResult >(Operation *)> callback)
 Walk all of the operations within the given set of regions, without traversing into any nested symbol tables.
static std::optional< WalkResultwalkSymbolTable (Operation *op, function_ref< std::optional< WalkResult >(Operation *)> callback)
 Walk all of the operations nested under, and including, the given operation, without traversing into any nested symbol tables.
static LogicalResult lookupSymbolInImpl (Operation *symbolTableOp, SymbolRefAttr symbol, SmallVectorImpl< Operation * > &symbols, function_ref< Operation *(Operation *, StringAttr)> lookupSymbolFn)
 Internal implementation of lookupSymbolIn that allows for specialized implementations of the lookup function.
static WalkResult walkSymbolRefs (Operation *op, function_ref< WalkResult(SymbolTable::SymbolUse)> callback)
 Walk all of the symbol references within the given operation, invoking the provided callback for each found use.
static std::optional< WalkResultwalkSymbolUses (MutableArrayRef< Region > regions, function_ref< WalkResult(SymbolTable::SymbolUse)> callback)
 Walk all of the uses, for any symbol, that are nested within the given regions, invoking the provided callback for each.
static std::optional< WalkResultwalkSymbolUses (Operation *from, function_ref< WalkResult(SymbolTable::SymbolUse)> callback)
 Walk all of the uses, for any symbol, that are nested within the given operation 'from', invoking the provided callback for each.
static SmallVector< SymbolScope, 2 > collectSymbolScopes (Operation *symbol, Operation *limit)
 Collect all of the symbol scopes from 'symbol' to (inclusive) 'limit'.
static SmallVector< SymbolScope, 2 > collectSymbolScopes (Operation *symbol, Region *limit)
static SmallVector< SymbolScope, 1 > collectSymbolScopes (StringAttr symbol, Region *limit)
static SmallVector< SymbolScope, 1 > collectSymbolScopes (StringAttr symbol, Operation *limit)
static bool isReferencePrefixOf (SymbolRefAttr subRef, SymbolRefAttr ref)
 Returns true if the given reference 'SubRef' is a sub reference of the reference 'ref', i.e.
template<typename FromT>
static std::optional< SymbolTable::UseRangegetSymbolUsesImpl (FromT from)
 The implementation of SymbolTable::getSymbolUses below.
template<typename SymbolT, typename IRUnitT>
static std::optional< SymbolTable::UseRangegetSymbolUsesImpl (SymbolT symbol, IRUnitT *limit)
 The implementation of SymbolTable::getSymbolUses below.
template<typename SymbolT, typename IRUnitT>
static bool symbolKnownUseEmptyImpl (SymbolT symbol, IRUnitT *limit)
 The implementation of SymbolTable::symbolKnownUseEmpty below.
static SymbolRefAttr generateNewRefAttr (SymbolRefAttr oldAttr, FlatSymbolRefAttr newLeafAttr)
 Generates a new symbol reference attribute with a new leaf reference.
template<typename SymbolT, typename IRUnitT>
static LogicalResult replaceAllSymbolUsesImpl (SymbolT symbol, StringAttr newSymbol, IRUnitT *limit)
 The implementation of SymbolTable::replaceAllSymbolUses below.

Function Documentation

◆ collectSymbolScopes() [1/4]

SmallVector< SymbolScope, 2 > collectSymbolScopes ( Operation * symbol,
Operation * limit )
static

◆ collectSymbolScopes() [2/4]

SmallVector< SymbolScope, 2 > collectSymbolScopes ( Operation * symbol,
Region * limit )
static

Definition at line 717 of file SymbolTable.cpp.

References collectSymbolScopes(), and mlir::Region::getParentOp().

◆ collectSymbolScopes() [3/4]

SmallVector< SymbolScope, 1 > collectSymbolScopes ( StringAttr symbol,
Operation * limit )
static

Definition at line 732 of file SymbolTable.cpp.

References mlir::Operation::getRegions().

◆ collectSymbolScopes() [4/4]

SmallVector< SymbolScope, 1 > collectSymbolScopes ( StringAttr symbol,
Region * limit )
static

Definition at line 727 of file SymbolTable.cpp.

◆ collectValidReferencesFor()

LogicalResult collectValidReferencesFor ( Operation * symbol,
StringAttr symbolName,
Operation * within,
SmallVectorImpl< SymbolRefAttr > & results )
static

Computes the nested symbol reference attribute for the symbol 'symbolName' that are usable within the symbol table operations from 'symbol' as far up to the given operation 'within', where 'within' is an ancestor of 'symbol'.

Returns success if all references up to 'within' could be computed.

Definition at line 39 of file SymbolTable.cpp.

References mlir::FlatSymbolRefAttr::get(), mlir::Operation::getContext(), getNameIfSymbol(), mlir::Operation::getParentOp(), mlir::SymbolTable::getSymbolAttrName(), mlir::Operation::hasTrait(), mlir::Operation::isAncestor(), and success().

Referenced by collectSymbolScopes().

◆ generateNewRefAttr()

SymbolRefAttr generateNewRefAttr ( SymbolRefAttr oldAttr,
FlatSymbolRefAttr newLeafAttr )
static

Generates a new symbol reference attribute with a new leaf reference.

Definition at line 871 of file SymbolTable.cpp.

Referenced by replaceAllSymbolUsesImpl().

◆ getNameIfSymbol() [1/2]

◆ getNameIfSymbol() [2/2]

StringAttr getNameIfSymbol ( Operation * op,
StringAttr symbolAttrNameId )
static

Definition at line 30 of file SymbolTable.cpp.

References mlir::Operation::getAttrOfType().

◆ getSymbolUsesImpl() [1/2]

◆ getSymbolUsesImpl() [2/2]

template<typename SymbolT, typename IRUnitT>
std::optional< SymbolTable::UseRange > getSymbolUsesImpl ( SymbolT symbol,
IRUnitT * limit )
static

The implementation of SymbolTable::getSymbolUses below.

Definition at line 796 of file SymbolTable.cpp.

References collectSymbolScopes().

◆ isPotentiallyUnknownSymbolTable()

bool isPotentiallyUnknownSymbolTable ( Operation * op)
static

Return true if the given operation is unknown and may potentially define a symbol table.

Definition at line 21 of file SymbolTable.cpp.

References mlir::Operation::getDialect(), and mlir::Operation::getNumRegions().

Referenced by mlir::SymbolTable::getNearestSymbolTable(), walkSymbolUses(), and walkSymbolUses().

◆ isReferencePrefixOf()

bool isReferencePrefixOf ( SymbolRefAttr subRef,
SymbolRefAttr ref )
static

Returns true if the given reference 'SubRef' is a sub reference of the reference 'ref', i.e.

'ref' is a further qualified reference.

Definition at line 743 of file SymbolTable.cpp.

Referenced by replaceAllSymbolUsesImpl().

◆ lookupSymbolInImpl()

LogicalResult lookupSymbolInImpl ( Operation * symbolTableOp,
SymbolRefAttr symbol,
SmallVectorImpl< Operation * > & symbols,
function_ref< Operation *(Operation *, StringAttr)> lookupSymbolFn )
static

Internal implementation of lookupSymbolIn that allows for specialized implementations of the lookup function.

Definition at line 409 of file SymbolTable.cpp.

References mlir::Operation::getAttr(), mlir::Operation::hasTrait(), and success().

Referenced by mlir::LockedSymbolTableCollection::lookupSymbolIn(), mlir::SymbolTable::lookupSymbolIn(), and mlir::SymbolTableCollection::lookupSymbolIn().

◆ replaceAllSymbolUsesImpl()

◆ symbolKnownUseEmptyImpl()

template<typename SymbolT, typename IRUnitT>
bool symbolKnownUseEmptyImpl ( SymbolT symbol,
IRUnitT * limit )
static

◆ walkSymbolRefs()

WalkResult walkSymbolRefs ( Operation * op,
function_ref< WalkResult(SymbolTable::SymbolUse)> callback )
static

Walk all of the symbol references within the given operation, invoking the provided callback for each found use.

The callbacks takes the use of the symbol.

Definition at line 555 of file SymbolTable.cpp.

References mlir::Operation::getAttrDictionary(), mlir::WalkResult::interrupt(), mlir::PreOrder, and mlir::WalkResult::skip().

Referenced by walkSymbolUses(), and walkSymbolUses().

◆ walkSymbolTable() [1/2]

std::optional< WalkResult > walkSymbolTable ( MutableArrayRef< Region > regions,
function_ref< std::optional< WalkResult >(Operation *)> callback )
static

Walk all of the operations within the given set of regions, without traversing into any nested symbol tables.

Stops walking if the result of the callback is anything other than WalkResult::advance.

Definition at line 80 of file SymbolTable.cpp.

References mlir::WalkResult::advance(), and result.

Referenced by mlir::detail::verifySymbolTable(), walkSymbolTable(), and walkSymbolUses().

◆ walkSymbolTable() [2/2]

std::optional< WalkResult > walkSymbolTable ( Operation * op,
function_ref< std::optional< WalkResult >(Operation *)> callback )
static

Walk all of the operations nested under, and including, the given operation, without traversing into any nested symbol tables.

Stops walking if the result of the callback is anything other than WalkResult::advance.

Definition at line 104 of file SymbolTable.cpp.

References mlir::WalkResult::advance(), mlir::Operation::getRegions(), mlir::Operation::hasTrait(), result, and walkSymbolTable().

◆ walkSymbolUses() [1/2]

std::optional< WalkResult > walkSymbolUses ( MutableArrayRef< Region > regions,
function_ref< WalkResult(SymbolTable::SymbolUse)> callback )
static

Walk all of the uses, for any symbol, that are nested within the given regions, invoking the provided callback for each.

This does not traverse into any nested symbol tables.

Definition at line 571 of file SymbolTable.cpp.

References isPotentiallyUnknownSymbolTable(), walkSymbolRefs(), and walkSymbolTable().

Referenced by getSymbolUsesImpl(), and walkSymbolUses().

◆ walkSymbolUses() [2/2]

std::optional< WalkResult > walkSymbolUses ( Operation * from,
function_ref< WalkResult(SymbolTable::SymbolUse)> callback )
static

Walk all of the uses, for any symbol, that are nested within the given operation 'from', invoking the provided callback for each.

This does not traverse into any nested symbol tables.

Definition at line 587 of file SymbolTable.cpp.

References mlir::WalkResult::advance(), mlir::Operation::getRegions(), mlir::Operation::hasTrait(), mlir::WalkResult::interrupt(), isPotentiallyUnknownSymbolTable(), walkSymbolRefs(), and walkSymbolUses().