MLIR  19.0.0git
Functions
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/SmallPtrSet.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. More...
 
static StringAttr getNameIfSymbol (Operation *op)
 Returns the string name of the given symbol, or null if this is not a symbol. More...
 
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'. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static SmallVector< SymbolScope, 2 > collectSymbolScopes (Operation *symbol, Operation *limit)
 Collect all of the symbol scopes from 'symbol' to (inclusive) 'limit'. More...
 
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. More...
 
template<typename FromT >
static std::optional< SymbolTable::UseRangegetSymbolUsesImpl (FromT from)
 The implementation of SymbolTable::getSymbolUses below. More...
 
template<typename SymbolT , typename IRUnitT >
static std::optional< SymbolTable::UseRangegetSymbolUsesImpl (SymbolT symbol, IRUnitT *limit)
 The implementation of SymbolTable::getSymbolUses below. More...
 
template<typename SymbolT , typename IRUnitT >
static bool symbolKnownUseEmptyImpl (SymbolT symbol, IRUnitT *limit)
 The implementation of SymbolTable::symbolKnownUseEmpty below. More...
 
static SymbolRefAttr generateNewRefAttr (SymbolRefAttr oldAttr, FlatSymbolRefAttr newLeafAttr)
 Generates a new symbol reference attribute with a new leaf reference. More...
 
template<typename SymbolT , typename IRUnitT >
static LogicalResult replaceAllSymbolUsesImpl (SymbolT symbol, StringAttr newSymbol, IRUnitT *limit)
 The implementation of SymbolTable::replaceAllSymbolUses below. More...
 

Function Documentation

◆ collectSymbolScopes() [1/4]

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

◆ collectSymbolScopes() [2/4]

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

Definition at line 718 of file SymbolTable.cpp.

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

◆ collectSymbolScopes() [3/4]

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

Definition at line 733 of file SymbolTable.cpp.

References mlir::get(), and mlir::Operation::getRegions().

◆ collectSymbolScopes() [4/4]

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

Definition at line 728 of file SymbolTable.cpp.

References mlir::get().

◆ collectValidReferencesFor()

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

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

Referenced by collectSymbolScopes().

◆ generateNewRefAttr()

static SymbolRefAttr generateNewRefAttr ( SymbolRefAttr  oldAttr,
FlatSymbolRefAttr  newLeafAttr 
)
static

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

Definition at line 868 of file SymbolTable.cpp.

References mlir::get().

Referenced by replaceAllSymbolUsesImpl().

◆ getNameIfSymbol() [1/2]

static StringAttr getNameIfSymbol ( Operation op)
static

Returns the string name of the given symbol, or null if this is not a symbol.

Definition at line 28 of file SymbolTable.cpp.

Referenced by collectValidReferencesFor(), and mlir::SymbolTable::getSymbolName().

◆ getNameIfSymbol() [2/2]

static StringAttr getNameIfSymbol ( Operation op,
StringAttr  symbolAttrNameId 
)
static

Definition at line 31 of file SymbolTable.cpp.

◆ getSymbolUsesImpl() [1/2]

template<typename FromT >
static std::optional<SymbolTable::UseRange> getSymbolUsesImpl ( FromT  from)
static

The implementation of SymbolTable::getSymbolUses below.

Definition at line 765 of file SymbolTable.cpp.

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

Referenced by mlir::SymbolTable::getSymbolUses().

◆ getSymbolUsesImpl() [2/2]

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

The implementation of SymbolTable::getSymbolUses below.

Definition at line 795 of file SymbolTable.cpp.

References collectSymbolScopes().

◆ isPotentiallyUnknownSymbolTable()

static bool isPotentiallyUnknownSymbolTable ( Operation op)
static

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

Definition at line 22 of file SymbolTable.cpp.

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

◆ isReferencePrefixOf()

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

Referenced by replaceAllSymbolUsesImpl().

◆ lookupSymbolInImpl()

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

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

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

◆ replaceAllSymbolUsesImpl()

template<typename SymbolT , typename IRUnitT >
static LogicalResult replaceAllSymbolUsesImpl ( SymbolT  symbol,
StringAttr  newSymbol,
IRUnitT *  limit 
)
static

◆ symbolKnownUseEmptyImpl()

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

The implementation of SymbolTable::symbolKnownUseEmpty below.

Definition at line 834 of file SymbolTable.cpp.

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

Referenced by mlir::SymbolTable::symbolKnownUseEmpty().

◆ walkSymbolRefs()

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

Referenced by walkSymbolUses().

◆ walkSymbolTable() [1/2]

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

Referenced by walkSymbolUses().

◆ walkSymbolTable() [2/2]

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

◆ walkSymbolUses() [1/2]

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

References walkSymbolTable().

Referenced by getSymbolUsesImpl(), and walkSymbolUses().

◆ walkSymbolUses() [2/2]

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

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