Skip to content

Commit ab9e559

Browse files
committed
[mlir] Refactor the implementation of Symbol use lists.
Summary: This revision refactors the implementation of the symbol use-list functionality to be a bit cleaner, as well as easier to reason about. Aside from code cleanup, this revision updates the user contract to never recurse into operations if they define a symbol table. The current functionality, which does recurse, makes it difficult to examine the uses held by a symbol table itself. Moving forward users may provide a specific region to examine for uses instead. Differential Revision: https://reviews.llvm.org/D73427
1 parent aff4ed7 commit ab9e559

File tree

3 files changed

+205
-135
lines changed

3 files changed

+205
-135
lines changed

mlir/include/mlir/IR/SymbolTable.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,47 +137,47 @@ class SymbolTable {
137137

138138
/// Get an iterator range for all of the uses, for any symbol, that are nested
139139
/// within the given operation 'from'. This does not traverse into any nested
140-
/// symbol tables, and will also only return uses on 'from' if it does not
141-
/// also define a symbol table. This is because we treat the region as the
142-
/// boundary of the symbol table, and not the op itself. This function returns
143-
/// None if there are any unknown operations that may potentially be symbol
144-
/// tables.
140+
/// symbol tables. This function returns None if there are any unknown
141+
/// operations that may potentially be symbol tables.
145142
static Optional<UseRange> getSymbolUses(Operation *from);
143+
static Optional<UseRange> getSymbolUses(Region *from);
146144

147145
/// Get all of the uses of the given symbol that are nested within the given
148-
/// operation 'from'. This does not traverse into any nested symbol tables,
149-
/// and will also only return uses on 'from' if it does not also define a
150-
/// symbol table. This is because we treat the region as the boundary of the
151-
/// symbol table, and not the op itself. This function returns None if there
152-
/// are any unknown operations that may potentially be symbol tables.
146+
/// operation 'from'. This does not traverse into any nested symbol tables.
147+
/// This function returns None if there are any unknown operations that may
148+
/// potentially be symbol tables.
153149
static Optional<UseRange> getSymbolUses(StringRef symbol, Operation *from);
154150
static Optional<UseRange> getSymbolUses(Operation *symbol, Operation *from);
151+
static Optional<UseRange> getSymbolUses(StringRef symbol, Region *from);
152+
static Optional<UseRange> getSymbolUses(Operation *symbol, Region *from);
155153

156154
/// Return if the given symbol is known to have no uses that are nested
157155
/// within the given operation 'from'. This does not traverse into any nested
158-
/// symbol tables, and will also only count uses on 'from' if it does not also
159-
/// define a symbol table. This is because we treat the region as the boundary
160-
/// of the symbol table, and not the op itself. This function will also return
161-
/// false if there are any unknown operations that may potentially be symbol
162-
/// tables. This doesn't necessarily mean that there are no uses, we just
163-
/// can't conservatively prove it.
156+
/// symbol tables. This function will also return false if there are any
157+
/// unknown operations that may potentially be symbol tables. This doesn't
158+
/// necessarily mean that there are no uses, we just can't conservatively
159+
/// prove it.
164160
static bool symbolKnownUseEmpty(StringRef symbol, Operation *from);
165161
static bool symbolKnownUseEmpty(Operation *symbol, Operation *from);
162+
static bool symbolKnownUseEmpty(StringRef symbol, Region *from);
163+
static bool symbolKnownUseEmpty(Operation *symbol, Region *from);
166164

167165
/// Attempt to replace all uses of the given symbol 'oldSymbol' with the
168166
/// provided symbol 'newSymbol' that are nested within the given operation
169-
/// 'from'. This does not traverse into any nested symbol tables, and will
170-
/// also only replace uses on 'from' if it does not also define a symbol
171-
/// table. This is because we treat the region as the boundary of the symbol
172-
/// table, and not the op itself. If there are any unknown operations that may
173-
/// potentially be symbol tables, no uses are replaced and failure is
174-
/// returned.
167+
/// 'from'. This does not traverse into any nested symbol tables. If there are
168+
/// any unknown operations that may potentially be symbol tables, no uses are
169+
/// replaced and failure is returned.
175170
LLVM_NODISCARD static LogicalResult replaceAllSymbolUses(StringRef oldSymbol,
176171
StringRef newSymbol,
177172
Operation *from);
178173
LLVM_NODISCARD static LogicalResult
179174
replaceAllSymbolUses(Operation *oldSymbol, StringRef newSymbolName,
180175
Operation *from);
176+
LLVM_NODISCARD static LogicalResult
177+
replaceAllSymbolUses(StringRef oldSymbol, StringRef newSymbol, Region *from);
178+
LLVM_NODISCARD static LogicalResult
179+
replaceAllSymbolUses(Operation *oldSymbol, StringRef newSymbolName,
180+
Region *from);
181181

182182
private:
183183
Operation *symbolTableOp;

0 commit comments

Comments
 (0)