[Mlir-commits] [mlir] feec2d9 - [mlir] return the updated symbol table after inserting into SymbolTable
Alex Zinenko
llvmlistbot at llvm.org
Tue Nov 2 06:23:06 PDT 2021
Author: Alex Zinenko
Date: 2021-11-02T14:22:57+01:00
New Revision: feec2d901c17a08c358fa379e722cbe84248ed02
URL: https://github.com/llvm/llvm-project/commit/feec2d901c17a08c358fa379e722cbe84248ed02
DIFF: https://github.com/llvm/llvm-project/commit/feec2d901c17a08c358fa379e722cbe84248ed02.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/IR/SymbolTable.h
mlir/lib/IR/SymbolTable.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/SymbolTable.h b/mlir/include/mlir/IR/SymbolTable.h
index 07a8f3fbb2dbf..3950fee156abd 100644
--- a/mlir/include/mlir/IR/SymbolTable.h
+++ b/mlir/include/mlir/IR/SymbolTable.h
@@ -49,8 +49,9 @@ class SymbolTable {
/// 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"; }
diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp
index 6634eab4150eb..93d605ff1e845 100644
--- a/mlir/lib/IR/SymbolTable.cpp
+++ b/mlir/lib/IR/SymbolTable.cpp
@@ -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.
More information about the Mlir-commits
mailing list