MLIR 22.0.0git
SymbolTable.h
Go to the documentation of this file.
1//===- SymbolTable.h - MLIR Symbol Table Class ------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_IR_SYMBOLTABLE_H
10#define MLIR_IR_SYMBOLTABLE_H
11
12#include "mlir/IR/Attributes.h"
14#include "llvm/ADT/SetVector.h"
15#include "llvm/ADT/StringMap.h"
16#include "llvm/Support/RWMutex.h"
17
18namespace mlir {
19
20/// This class allows for representing and managing the symbol table used by
21/// operations with the 'SymbolTable' trait. Inserting into and erasing from
22/// this SymbolTable will also insert and erase from the Operation given to it
23/// at construction.
25public:
26 /// Build a symbol table with the symbols within the given operation.
27 SymbolTable(Operation *symbolTableOp);
28
29 /// Look up a symbol with the specified name, returning null if no such
30 /// name exists. Names never include the @ on them.
31 Operation *lookup(StringRef name) const;
32 template <typename T>
33 T lookup(StringRef name) const {
34 return dyn_cast_or_null<T>(lookup(name));
35 }
36
37 /// Look up a symbol with the specified name, returning null if no such
38 /// name exists. Names never include the @ on them.
39 Operation *lookup(StringAttr name) const;
40 template <typename T>
41 T lookup(StringAttr name) const {
42 return dyn_cast_or_null<T>(lookup(name));
43 }
44
45 /// Remove the given symbol from the table, without deleting it.
46 void remove(Operation *op);
47
48 /// Erase the given symbol from the table and delete the operation.
49 void erase(Operation *symbol);
50
51 /// Insert a new symbol into the table, and rename it as necessary to avoid
52 /// collisions. Also insert at the specified location in the body of the
53 /// associated operation if it is not already there. It is asserted that the
54 /// symbol is not inside another operation. Return the name of the symbol
55 /// after insertion as attribute.
56 StringAttr insert(Operation *symbol, Block::iterator insertPt = {});
57
58 /// Renames the given op or the op refered to by the given name to the given
59 /// new name and updates the symbol table and all usages of the symbol
60 /// accordingly. Fails if the updating of the usages fails.
61 LogicalResult rename(StringAttr from, StringAttr to);
62 LogicalResult rename(Operation *op, StringAttr to);
63 LogicalResult rename(StringAttr from, StringRef to);
64 LogicalResult rename(Operation *op, StringRef to);
65
66 /// Renames the given op or the op refered to by the given name to the a name
67 /// that is unique within this and the provided other symbol tables and
68 /// updates the symbol table and all usages of the symbol accordingly. Returns
69 /// the new name or failure if the renaming fails.
70 FailureOr<StringAttr> renameToUnique(StringAttr from,
71 ArrayRef<SymbolTable *> others);
72 FailureOr<StringAttr> renameToUnique(Operation *op,
73 ArrayRef<SymbolTable *> others);
74
75 /// Return the name of the attribute used for symbol names.
76 static StringRef getSymbolAttrName() { return "sym_name"; }
77
78 /// Returns the associated operation.
79 Operation *getOp() const { return symbolTableOp; }
80
81 /// Return the name of the attribute used for symbol visibility.
82 static StringRef getVisibilityAttrName() { return "sym_visibility"; }
83
84 //===--------------------------------------------------------------------===//
85 // Symbol Utilities
86 //===--------------------------------------------------------------------===//
87
88 /// An enumeration detailing the different visibility types that a symbol may
89 /// have.
90 enum class Visibility {
91 /// The symbol is public and may be referenced anywhere internal or external
92 /// to the visible references in the IR.
94
95 /// The symbol is private and may only be referenced by SymbolRefAttrs local
96 /// to the operations within the current symbol table.
98
99 /// The symbol is visible to the current IR, which may include operations in
100 /// symbol tables above the one that owns the current symbol. `Nested`
101 /// visibility allows for referencing a symbol outside of its current symbol
102 /// table, while retaining the ability to observe all uses.
104 };
105
106 /// Generate a unique symbol name. Iteratively increase uniquingCounter
107 /// and use it as a suffix for symbol names until uniqueChecker does not
108 /// detect any conflict.
109 template <unsigned N, typename UniqueChecker>
110 static SmallString<N> generateSymbolName(StringRef name,
111 UniqueChecker uniqueChecker,
112 unsigned &uniquingCounter) {
113 SmallString<N> nameBuffer(name);
114 unsigned originalLength = nameBuffer.size();
115 do {
116 nameBuffer.resize(originalLength);
117 nameBuffer += '_';
118 nameBuffer += std::to_string(uniquingCounter++);
119 } while (uniqueChecker(nameBuffer));
120
121 return nameBuffer;
122 }
123
124 /// Returns the name of the given symbol operation, aborting if no symbol is
125 /// present.
126 static StringAttr getSymbolName(Operation *symbol);
127
128 /// Sets the name of the given symbol operation.
129 static void setSymbolName(Operation *symbol, StringAttr name);
130 static void setSymbolName(Operation *symbol, StringRef name) {
131 setSymbolName(symbol, StringAttr::get(symbol->getContext(), name));
132 }
133
134 /// Returns the visibility of the given symbol operation.
135 static Visibility getSymbolVisibility(Operation *symbol);
136 /// Sets the visibility of the given symbol operation.
137 static void setSymbolVisibility(Operation *symbol, Visibility vis);
138
139 /// Returns the nearest symbol table from a given operation `from`. Returns
140 /// nullptr if no valid parent symbol table could be found.
142
143 /// Walks all symbol table operations nested within, and including, `op`. For
144 /// each symbol table operation, the provided callback is invoked with the op
145 /// and a boolean signifying if the symbols within that symbol table can be
146 /// treated as if all uses within the IR are visible to the caller.
147 /// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
148 /// within `op` are visible.
149 static void walkSymbolTables(Operation *op, bool allSymUsesVisible,
150 function_ref<void(Operation *, bool)> callback);
151
152 /// Returns the operation registered with the given symbol name with the
153 /// regions of 'symbolTableOp'. 'symbolTableOp' is required to be an operation
154 /// with the 'OpTrait::SymbolTable' trait.
155 static Operation *lookupSymbolIn(Operation *op, StringAttr symbol);
156 static Operation *lookupSymbolIn(Operation *op, StringRef symbol) {
157 return lookupSymbolIn(op, StringAttr::get(op->getContext(), symbol));
158 }
159 static Operation *lookupSymbolIn(Operation *op, SymbolRefAttr symbol);
160 /// A variant of 'lookupSymbolIn' that returns all of the symbols referenced
161 /// by a given SymbolRefAttr. Returns failure if any of the nested references
162 /// could not be resolved.
163 static LogicalResult lookupSymbolIn(Operation *op, SymbolRefAttr symbol,
165
166 /// Returns the operation registered with the given symbol name within the
167 /// closest parent operation of, or including, 'from' with the
168 /// 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol was
169 /// found.
170 static Operation *lookupNearestSymbolFrom(Operation *from, StringAttr symbol);
172 SymbolRefAttr symbol);
173 template <typename T>
174 static T lookupNearestSymbolFrom(Operation *from, StringAttr symbol) {
175 return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
176 }
177 template <typename T>
178 static T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol) {
179 return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
180 }
181
182 /// This class represents a specific symbol use.
183 class SymbolUse {
184 public:
185 SymbolUse(Operation *op, SymbolRefAttr symbolRef)
186 : owner(op), symbolRef(symbolRef) {}
187
188 /// Return the operation user of this symbol reference.
189 Operation *getUser() const { return owner; }
190
191 /// Return the symbol reference that this use represents.
192 SymbolRefAttr getSymbolRef() const { return symbolRef; }
193
194 private:
195 /// The operation that this access is held by.
196 Operation *owner;
197
198 /// The symbol reference that this use represents.
199 SymbolRefAttr symbolRef;
200 };
201
202 /// This class implements a range of SymbolRef uses.
203 class UseRange {
204 public:
205 UseRange(std::vector<SymbolUse> &&uses) : uses(std::move(uses)) {}
206
207 using iterator = std::vector<SymbolUse>::const_iterator;
208 iterator begin() const { return uses.begin(); }
209 iterator end() const { return uses.end(); }
210 bool empty() const { return uses.empty(); }
211
212 private:
213 std::vector<SymbolUse> uses;
214 };
215
216 /// Get an iterator range for all of the uses, for any symbol, that are nested
217 /// within the given operation 'from'. This does not traverse into any nested
218 /// symbol tables. This function returns std::nullopt if there are any unknown
219 /// operations that may potentially be symbol tables.
220 static std::optional<UseRange> getSymbolUses(Operation *from);
221 static std::optional<UseRange> getSymbolUses(Region *from);
222
223 /// Get all of the uses of the given symbol that are nested within the given
224 /// operation 'from'. This does not traverse into any nested symbol tables.
225 /// This function returns std::nullopt if there are any unknown operations
226 /// that may potentially be symbol tables.
227 static std::optional<UseRange> getSymbolUses(StringAttr symbol,
228 Operation *from);
229 static std::optional<UseRange> getSymbolUses(Operation *symbol,
230 Operation *from);
231 static std::optional<UseRange> getSymbolUses(StringAttr symbol, Region *from);
232 static std::optional<UseRange> getSymbolUses(Operation *symbol, Region *from);
233
234 /// Return if the given symbol is known to have no uses that are nested
235 /// within the given operation 'from'. This does not traverse into any nested
236 /// symbol tables. This function will also return false if there are any
237 /// unknown operations that may potentially be symbol tables. This doesn't
238 /// necessarily mean that there are no uses, we just can't conservatively
239 /// prove it.
240 static bool symbolKnownUseEmpty(StringAttr symbol, Operation *from);
241 static bool symbolKnownUseEmpty(Operation *symbol, Operation *from);
242 static bool symbolKnownUseEmpty(StringAttr symbol, Region *from);
243 static bool symbolKnownUseEmpty(Operation *symbol, Region *from);
244
245 /// Attempt to replace all uses of the given symbol 'oldSymbol' with the
246 /// provided symbol 'newSymbol' that are nested within the given operation
247 /// 'from'. This does not traverse into any nested symbol tables. If there are
248 /// any unknown operations that may potentially be symbol tables, no uses are
249 /// replaced and failure is returned.
250 static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol,
251 StringAttr newSymbol,
252 Operation *from);
253 static LogicalResult replaceAllSymbolUses(Operation *oldSymbol,
254 StringAttr newSymbolName,
255 Operation *from);
256 static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol,
257 StringAttr newSymbol, Region *from);
258 static LogicalResult replaceAllSymbolUses(Operation *oldSymbol,
259 StringAttr newSymbolName,
260 Region *from);
261
262private:
263 Operation *symbolTableOp;
264
265 /// This is a mapping from a name to the symbol with that name. They key is
266 /// always known to be a StringAttr.
268
269 /// This is used when name conflicts are detected.
270 unsigned uniquingCounter = 0;
271};
272
274
275//===----------------------------------------------------------------------===//
276// SymbolTableCollection
277//===----------------------------------------------------------------------===//
278
279/// This class represents a collection of `SymbolTable`s. This simplifies
280/// certain algorithms that run recursively on nested symbol tables. Symbol
281/// tables are constructed lazily to reduce the upfront cost of constructing
282/// unnecessary tables.
284public:
285 virtual ~SymbolTableCollection() = default;
286
287 /// Look up a symbol with the specified name within the specified symbol table
288 /// operation, returning null if no such name exists.
289 virtual Operation *lookupSymbolIn(Operation *symbolTableOp,
290 StringAttr symbol);
291 virtual Operation *lookupSymbolIn(Operation *symbolTableOp,
292 SymbolRefAttr name);
293 template <typename T, typename NameT>
294 T lookupSymbolIn(Operation *symbolTableOp, NameT &&name) {
295 return dyn_cast_or_null<T>(
296 lookupSymbolIn(symbolTableOp, std::forward<NameT>(name)));
297 }
298 /// A variant of 'lookupSymbolIn' that returns all of the symbols referenced
299 /// by a given SymbolRefAttr when resolved within the provided symbol table
300 /// operation. Returns failure if any of the nested references could not be
301 /// resolved.
302 virtual LogicalResult lookupSymbolIn(Operation *symbolTableOp,
303 SymbolRefAttr name,
305
306 /// Returns the operation registered with the given symbol name within the
307 /// closest parent operation of, or including, 'from' with the
308 /// 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol was
309 /// found.
311 StringAttr symbol);
313 SymbolRefAttr symbol);
314 template <typename T>
315 T lookupNearestSymbolFrom(Operation *from, StringAttr symbol) {
316 return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
317 }
318 template <typename T>
319 T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol) {
320 return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
321 }
322
323 /// Lookup, or create, a symbol table for an operation.
325
326 /// Invalidate the cached symbol table for an operation.
327 /// This is important when doing IR modifications that erase and also create
328 /// operations having the 'OpTrait::SymbolTable' trait. If a symbol table of
329 /// an erased operation is not invalidated, a new operation sharing the same
330 /// address would be associated with outdated, and wrong, information.
331 virtual void invalidateSymbolTable(Operation *op);
332
333private:
335
336 /// The constructed symbol tables nested within this table.
338};
339
340//===----------------------------------------------------------------------===//
341// LockedSymbolTableCollection
342//===----------------------------------------------------------------------===//
343
344/// This class implements a lock-based shared wrapper around a symbol table
345/// collection that allows shared access to the collection of symbol tables.
346/// This class does not protect shared access to individual symbol tables.
347/// `SymbolTableCollection` lazily instantiates `SymbolTable` instances for
348/// symbol table operations, making read operations not thread-safe. This class
349/// provides a thread-safe `lookupSymbolIn` implementation by synchronizing the
350/// lazy `SymbolTable` lookup.
352public:
354 : collection(collection) {}
355
356 /// Look up a symbol with the specified name within the specified symbol table
357 /// operation, returning null if no such name exists.
358 Operation *lookupSymbolIn(Operation *symbolTableOp,
359 StringAttr symbol) override;
360 /// Look up a symbol with the specified name within the specified symbol table
361 /// operation, returning null if no such name exists.
362 Operation *lookupSymbolIn(Operation *symbolTableOp, FlatSymbolRefAttr symbol);
363 /// Look up a potentially nested symbol within the specified symbol table
364 /// operation, returning null if no such symbol exists.
365 Operation *lookupSymbolIn(Operation *symbolTableOp,
366 SymbolRefAttr name) override;
367
368 /// Lookup a symbol of a particular kind within the specified symbol table,
369 /// returning null if the symbol was not found.
370 template <typename T, typename NameT>
371 T lookupSymbolIn(Operation *symbolTableOp, NameT &&name) {
372 return dyn_cast_or_null<T>(
373 lookupSymbolIn(symbolTableOp, std::forward<NameT>(name)));
374 }
375
376 /// A variant of 'lookupSymbolIn' that returns all of the symbols referenced
377 /// by a given SymbolRefAttr when resolved within the provided symbol table
378 /// operation. Returns failure if any of the nested references could not be
379 /// resolved.
380 LogicalResult lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name,
381 SmallVectorImpl<Operation *> &symbols) override;
382
383private:
384 /// Get the symbol table for the symbol table operation, constructing if it
385 /// does not exist. This function provides thread safety over `collection`
386 /// by locking when performing the lookup and when inserting
387 /// lazily-constructed symbol tables.
388 SymbolTable &getSymbolTable(Operation *symbolTableOp) override;
389
390 /// The symbol tables to manage.
391 SymbolTableCollection &collection;
392 /// The mutex protecting access to the symbol table collection.
393 llvm::sys::SmartRWMutex<true> mutex;
394};
395
396//===----------------------------------------------------------------------===//
397// SymbolUserMap
398//===----------------------------------------------------------------------===//
399
400/// This class represents a map of symbols to users, and provides efficient
401/// implementations of symbol queries related to users; such as collecting the
402/// users of a symbol, replacing all uses, etc.
404public:
405 /// Build a user map for all of the symbols defined in regions nested under
406 /// 'symbolTableOp'. A reference to the provided symbol table collection is
407 /// kept by the user map to ensure efficient lookups, thus the lifetime should
408 /// extend beyond that of this map.
409 SymbolUserMap(SymbolTableCollection &symbolTable, Operation *symbolTableOp);
410
411 /// Return the users of the provided symbol operation.
413 auto it = symbolToUsers.find(symbol);
414 return it != symbolToUsers.end() ? it->second.getArrayRef()
416 }
417
418 /// Return true if the given symbol has no uses.
419 bool useEmpty(Operation *symbol) const {
420 return !symbolToUsers.count(symbol);
421 }
422
423 /// Replace all of the uses of the given symbol with `newSymbolName`.
424 void replaceAllUsesWith(Operation *symbol, StringAttr newSymbolName);
425
426private:
427 /// A reference to the symbol table used to construct this map.
428 SymbolTableCollection &symbolTable;
429
430 /// A map of symbol operations to symbol users.
432};
433
434//===----------------------------------------------------------------------===//
435// SymbolTable Trait Types
436//===----------------------------------------------------------------------===//
437
438namespace detail {
439LogicalResult verifySymbolTable(Operation *op);
440LogicalResult verifySymbol(Operation *op);
441} // namespace detail
442
443namespace OpTrait {
444/// A trait used to provide symbol table functionalities to a region operation.
445/// This operation must hold exactly 1 region. Once attached, all operations
446/// that are directly within the region, i.e not including those within child
447/// regions, that contain a 'SymbolTable::getSymbolAttrName()' StringAttr will
448/// be verified to ensure that the names are uniqued. These operations must also
449/// adhere to the constraints defined by the `Symbol` trait, even if they do not
450/// inherit from it.
451template <typename ConcreteType>
452class SymbolTable : public TraitBase<ConcreteType, SymbolTable> {
453public:
454 static LogicalResult verifyRegionTrait(Operation *op) {
455 return ::mlir::detail::verifySymbolTable(op);
456 }
457
458 /// Look up a symbol with the specified name, returning null if no such
459 /// name exists. Symbol names never include the @ on them. Note: This
460 /// performs a linear scan of held symbols.
461 Operation *lookupSymbol(StringAttr name) {
463 }
464 template <typename T>
465 T lookupSymbol(StringAttr name) {
466 return dyn_cast_or_null<T>(lookupSymbol(name));
467 }
468 Operation *lookupSymbol(SymbolRefAttr symbol) {
469 return mlir::SymbolTable::lookupSymbolIn(this->getOperation(), symbol);
470 }
471 template <typename T>
472 T lookupSymbol(SymbolRefAttr symbol) {
473 return dyn_cast_or_null<T>(lookupSymbol(symbol));
474 }
475
476 Operation *lookupSymbol(StringRef name) {
478 }
479 template <typename T>
480 T lookupSymbol(StringRef name) {
481 return dyn_cast_or_null<T>(lookupSymbol(name));
482 }
483};
484
485} // namespace OpTrait
486
487//===----------------------------------------------------------------------===//
488// Visibility parsing implementation.
489//===----------------------------------------------------------------------===//
490
491namespace impl {
492/// Parse an optional visibility attribute keyword (i.e., public, private, or
493/// nested) without quotes in a string attribute named 'attrName'.
494ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser,
495 NamedAttrList &attrs);
496} // namespace impl
497
498} // namespace mlir
499
500/// Include the generated symbol interfaces.
501#include "mlir/IR/SymbolInterfaces.h.inc"
502
503#endif // MLIR_IR_SYMBOLTABLE_H
OpListType::iterator iterator
Definition Block.h:140
A symbol reference with a reference path containing a single element.
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name)
Lookup a symbol of a particular kind within the specified symbol table, returning null if the symbol ...
LockedSymbolTableCollection(SymbolTableCollection &collection)
Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol) override
Look up a symbol with the specified name within the specified symbol table operation,...
A trait used to provide symbol table functionalities to a region operation.
Operation * lookupSymbol(SymbolRefAttr symbol)
Operation * lookupSymbol(StringRef name)
T lookupSymbol(SymbolRefAttr symbol)
Operation * lookupSymbol(StringAttr name)
Look up a symbol with the specified name, returning null if no such name exists.
T lookupSymbol(StringAttr name)
T lookupSymbol(StringRef name)
static LogicalResult verifyRegionTrait(Operation *op)
Helper class for implementing traits.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
MLIRContext * getContext()
Return the context this operation is associated with.
Definition Operation.h:216
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
This class represents a collection of SymbolTables.
T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
virtual ~SymbolTableCollection()=default
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name)
virtual Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol)
virtual Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
Look up a symbol with the specified name within the specified symbol table operation,...
friend class LockedSymbolTableCollection
virtual void invalidateSymbolTable(Operation *op)
Invalidate the cached symbol table for an operation.
virtual SymbolTable & getSymbolTable(Operation *op)
Lookup, or create, a symbol table for an operation.
SymbolUse(Operation *op, SymbolRefAttr symbolRef)
Operation * getUser() const
Return the operation user of this symbol reference.
SymbolRefAttr getSymbolRef() const
Return the symbol reference that this use represents.
UseRange(std::vector< SymbolUse > &&uses)
std::vector< SymbolUse >::const_iterator iterator
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Definition SymbolTable.h:24
static SmallString< N > generateSymbolName(StringRef name, UniqueChecker uniqueChecker, unsigned &uniquingCounter)
Generate a unique symbol name.
static Visibility getSymbolVisibility(Operation *symbol)
Returns the visibility of the given symbol operation.
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
Definition SymbolTable.h:76
static void setSymbolVisibility(Operation *symbol, Visibility vis)
Sets the visibility of the given symbol operation.
static T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol)
static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol, StringAttr newSymbol, Operation *from)
Attempt to replace all uses of the given symbol 'oldSymbol' with the provided symbol 'newSymbol' that...
Visibility
An enumeration detailing the different visibility types that a symbol may have.
Definition SymbolTable.h:90
@ Nested
The symbol is visible to the current IR, which may include operations in symbol tables above the one ...
@ Public
The symbol is public and may be referenced anywhere internal or external to the visible references in...
Definition SymbolTable.h:93
@ Private
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the...
Definition SymbolTable.h:97
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
Definition SymbolTable.h:82
static T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
LogicalResult rename(StringAttr from, StringAttr to)
Renames the given op or the op refered to by the given name to the given new name and updates the sym...
void erase(Operation *symbol)
Erase the given symbol from the table and delete the operation.
Operation * getOp() const
Returns the associated operation.
Definition SymbolTable.h:79
static void setSymbolName(Operation *symbol, StringRef name)
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
Operation * lookup(StringRef name) const
Look up a symbol with the specified name, returning null if no such name exists.
T lookup(StringRef name) const
Definition SymbolTable.h:33
SymbolTable(Operation *symbolTableOp)
Build a symbol table with the symbols within the given operation.
static Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
static void setSymbolName(Operation *symbol, StringAttr name)
Sets the name of the given symbol operation.
static bool symbolKnownUseEmpty(StringAttr symbol, Operation *from)
Return if the given symbol is known to have no uses that are nested within the given operation 'from'...
FailureOr< StringAttr > renameToUnique(StringAttr from, ArrayRef< SymbolTable * > others)
Renames the given op or the op refered to by the given name to the a name that is unique within this ...
static Operation * lookupSymbolIn(Operation *op, StringRef symbol)
static void walkSymbolTables(Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback)
Walks all symbol table operations nested within, and including, op.
static StringAttr getSymbolName(Operation *symbol)
Returns the name of the given symbol operation, aborting if no symbol is present.
static std::optional< UseRange > getSymbolUses(Operation *from)
Get an iterator range for all of the uses, for any symbol, that are nested within the given operation...
T lookup(StringAttr name) const
Definition SymbolTable.h:41
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
void remove(Operation *op)
Remove the given symbol from the table, without deleting it.
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
bool useEmpty(Operation *symbol) const
Return true if the given symbol has no uses.
ArrayRef< Operation * > getUsers(Operation *symbol) const
Return the users of the provided symbol operation.
void replaceAllUsesWith(Operation *symbol, StringAttr newSymbolName)
Replace all of the uses of the given symbol with newSymbolName.
SymbolUserMap(SymbolTableCollection &symbolTable, Operation *symbolTableOp)
Build a user map for all of the symbols defined in regions nested under 'symbolTableOp'.
LogicalResult verifySymbol(Operation *op)
LogicalResult verifySymbolTable(Operation *op)
ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser, NamedAttrList &attrs)
Parse an optional visibility attribute keyword (i.e., public, private, or nested) without quotes in a...
Include the generated interface declarations.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
Definition LLVM.h:126
llvm::function_ref< Fn > function_ref
Definition LLVM.h:152