forked from OSchip/llvm-project
[mlir] return the updated symbol table after inserting into SymbolTable
Inserting a symbol into a SymbolTable may lead to the name of the symbol being changed in order to ensure uniqueness of symbol names in the table. Return this new name to spare the caller the need to extract it from the symbol operation. Depends On D112700 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D112886
This commit is contained in:
parent
a39eadcf16
commit
feec2d901c
|
@ -49,8 +49,9 @@ public:
|
|||
/// Insert a new symbol into the table, 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.
|
||||
void insert(Operation *symbol, Block::iterator insertPt = {});
|
||||
/// symbol is not inside another operation. Return the name of the symbol
|
||||
/// after insertion as attribute.
|
||||
StringAttr insert(Operation *symbol, Block::iterator insertPt = {});
|
||||
|
||||
/// Return the name of the attribute used for symbol names.
|
||||
static StringRef getSymbolAttrName() { return "sym_name"; }
|
||||
|
|
|
@ -151,8 +151,9 @@ void SymbolTable::erase(Operation *symbol) {
|
|||
|
||||
// TODO: Consider if this should be renamed to something like insertOrUpdate
|
||||
/// Insert a new symbol into the table and associated operation if not already
|
||||
/// there and rename it as necessary to avoid collisions.
|
||||
void SymbolTable::insert(Operation *symbol, Block::iterator insertPt) {
|
||||
/// there and rename it as necessary to avoid collisions. Return the name of
|
||||
/// the symbol after insertion as attribute.
|
||||
StringAttr SymbolTable::insert(Operation *symbol, Block::iterator insertPt) {
|
||||
// The symbol cannot be the child of another op and must be the child of the
|
||||
// symbolTableOp after this.
|
||||
//
|
||||
|
@ -180,10 +181,10 @@ void SymbolTable::insert(Operation *symbol, Block::iterator insertPt) {
|
|||
// detected.
|
||||
StringAttr name = getSymbolName(symbol);
|
||||
if (symbolTable.insert({name, symbol}).second)
|
||||
return;
|
||||
return name;
|
||||
// If the symbol was already in the table, also return.
|
||||
if (symbolTable.lookup(name) == symbol)
|
||||
return;
|
||||
return name;
|
||||
// If a conflict was detected, then the symbol will not have been added to
|
||||
// the symbol table. Try suffixes until we get to a unique name that works.
|
||||
SmallString<128> nameBuffer(name.getValue());
|
||||
|
@ -199,6 +200,7 @@ void SymbolTable::insert(Operation *symbol, Block::iterator insertPt) {
|
|||
} while (!symbolTable.insert({StringAttr::get(context, nameBuffer), symbol})
|
||||
.second);
|
||||
setSymbolName(symbol, nameBuffer);
|
||||
return getSymbolName(symbol);
|
||||
}
|
||||
|
||||
/// Returns the name of the given symbol operation.
|
||||
|
|
Loading…
Reference in New Issue