MLIR  18.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"
13 #include "mlir/IR/OpDefinition.h"
14 #include "llvm/ADT/SetVector.h"
15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/Support/RWMutex.h"
17 
18 namespace 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.
24 class SymbolTable {
25 public:
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  /// Return the name of the attribute used for symbol names.
59  static StringRef getSymbolAttrName() { return "sym_name"; }
60 
61  /// Returns the associated operation.
62  Operation *getOp() const { return symbolTableOp; }
63 
64  /// Return the name of the attribute used for symbol visibility.
65  static StringRef getVisibilityAttrName() { return "sym_visibility"; }
66 
67  //===--------------------------------------------------------------------===//
68  // Symbol Utilities
69  //===--------------------------------------------------------------------===//
70 
71  /// An enumeration detailing the different visibility types that a symbol may
72  /// have.
73  enum class Visibility {
74  /// The symbol is public and may be referenced anywhere internal or external
75  /// to the visible references in the IR.
76  Public,
77 
78  /// The symbol is private and may only be referenced by SymbolRefAttrs local
79  /// to the operations within the current symbol table.
80  Private,
81 
82  /// The symbol is visible to the current IR, which may include operations in
83  /// symbol tables above the one that owns the current symbol. `Nested`
84  /// visibility allows for referencing a symbol outside of its current symbol
85  /// table, while retaining the ability to observe all uses.
86  Nested,
87  };
88 
89  /// Returns the name of the given symbol operation, aborting if no symbol is
90  /// present.
91  static StringAttr getSymbolName(Operation *symbol);
92 
93  /// Sets the name of the given symbol operation.
94  static void setSymbolName(Operation *symbol, StringAttr name);
95  static void setSymbolName(Operation *symbol, StringRef name) {
96  setSymbolName(symbol, StringAttr::get(symbol->getContext(), name));
97  }
98 
99  /// Returns the visibility of the given symbol operation.
100  static Visibility getSymbolVisibility(Operation *symbol);
101  /// Sets the visibility of the given symbol operation.
102  static void setSymbolVisibility(Operation *symbol, Visibility vis);
103 
104  /// Returns the nearest symbol table from a given operation `from`. Returns
105  /// nullptr if no valid parent symbol table could be found.
107 
108  /// Walks all symbol table operations nested within, and including, `op`. For
109  /// each symbol table operation, the provided callback is invoked with the op
110  /// and a boolean signifying if the symbols within that symbol table can be
111  /// treated as if all uses within the IR are visible to the caller.
112  /// `allSymUsesVisible` identifies whether all of the symbol uses of symbols
113  /// within `op` are visible.
114  static void walkSymbolTables(Operation *op, bool allSymUsesVisible,
115  function_ref<void(Operation *, bool)> callback);
116 
117  /// Returns the operation registered with the given symbol name with the
118  /// regions of 'symbolTableOp'. 'symbolTableOp' is required to be an operation
119  /// with the 'OpTrait::SymbolTable' trait.
120  static Operation *lookupSymbolIn(Operation *op, StringAttr symbol);
121  static Operation *lookupSymbolIn(Operation *op, StringRef symbol) {
122  return lookupSymbolIn(op, StringAttr::get(op->getContext(), symbol));
123  }
124  static Operation *lookupSymbolIn(Operation *op, SymbolRefAttr symbol);
125  /// A variant of 'lookupSymbolIn' that returns all of the symbols referenced
126  /// by a given SymbolRefAttr. Returns failure if any of the nested references
127  /// could not be resolved.
128  static LogicalResult lookupSymbolIn(Operation *op, SymbolRefAttr symbol,
130 
131  /// Returns the operation registered with the given symbol name within the
132  /// closest parent operation of, or including, 'from' with the
133  /// 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol was
134  /// found.
135  static Operation *lookupNearestSymbolFrom(Operation *from, StringAttr symbol);
137  SymbolRefAttr symbol);
138  template <typename T>
139  static T lookupNearestSymbolFrom(Operation *from, StringAttr symbol) {
140  return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
141  }
142  template <typename T>
143  static T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol) {
144  return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
145  }
146 
147  /// This class represents a specific symbol use.
148  class SymbolUse {
149  public:
150  SymbolUse(Operation *op, SymbolRefAttr symbolRef)
151  : owner(op), symbolRef(symbolRef) {}
152 
153  /// Return the operation user of this symbol reference.
154  Operation *getUser() const { return owner; }
155 
156  /// Return the symbol reference that this use represents.
157  SymbolRefAttr getSymbolRef() const { return symbolRef; }
158 
159  private:
160  /// The operation that this access is held by.
161  Operation *owner;
162 
163  /// The symbol reference that this use represents.
164  SymbolRefAttr symbolRef;
165  };
166 
167  /// This class implements a range of SymbolRef uses.
168  class UseRange {
169  public:
170  UseRange(std::vector<SymbolUse> &&uses) : uses(std::move(uses)) {}
171 
172  using iterator = std::vector<SymbolUse>::const_iterator;
173  iterator begin() const { return uses.begin(); }
174  iterator end() const { return uses.end(); }
175  bool empty() const { return uses.empty(); }
176 
177  private:
178  std::vector<SymbolUse> uses;
179  };
180 
181  /// Get an iterator range for all of the uses, for any symbol, that are nested
182  /// within the given operation 'from'. This does not traverse into any nested
183  /// symbol tables. This function returns std::nullopt if there are any unknown
184  /// operations that may potentially be symbol tables.
185  static std::optional<UseRange> getSymbolUses(Operation *from);
186  static std::optional<UseRange> getSymbolUses(Region *from);
187 
188  /// Get all of the uses of the given symbol that are nested within the given
189  /// operation 'from'. This does not traverse into any nested symbol tables.
190  /// This function returns std::nullopt if there are any unknown operations
191  /// that may potentially be symbol tables.
192  static std::optional<UseRange> getSymbolUses(StringAttr symbol,
193  Operation *from);
194  static std::optional<UseRange> getSymbolUses(Operation *symbol,
195  Operation *from);
196  static std::optional<UseRange> getSymbolUses(StringAttr symbol, Region *from);
197  static std::optional<UseRange> getSymbolUses(Operation *symbol, Region *from);
198 
199  /// Return if the given symbol is known to have no uses that are nested
200  /// within the given operation 'from'. This does not traverse into any nested
201  /// symbol tables. This function will also return false if there are any
202  /// unknown operations that may potentially be symbol tables. This doesn't
203  /// necessarily mean that there are no uses, we just can't conservatively
204  /// prove it.
205  static bool symbolKnownUseEmpty(StringAttr symbol, Operation *from);
206  static bool symbolKnownUseEmpty(Operation *symbol, Operation *from);
207  static bool symbolKnownUseEmpty(StringAttr symbol, Region *from);
208  static bool symbolKnownUseEmpty(Operation *symbol, Region *from);
209 
210  /// Attempt to replace all uses of the given symbol 'oldSymbol' with the
211  /// provided symbol 'newSymbol' that are nested within the given operation
212  /// 'from'. This does not traverse into any nested symbol tables. If there are
213  /// any unknown operations that may potentially be symbol tables, no uses are
214  /// replaced and failure is returned.
215  static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol,
216  StringAttr newSymbol,
217  Operation *from);
218  static LogicalResult replaceAllSymbolUses(Operation *oldSymbol,
219  StringAttr newSymbolName,
220  Operation *from);
221  static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol,
222  StringAttr newSymbol, Region *from);
223  static LogicalResult replaceAllSymbolUses(Operation *oldSymbol,
224  StringAttr newSymbolName,
225  Region *from);
226 
227 private:
228  Operation *symbolTableOp;
229 
230  /// This is a mapping from a name to the symbol with that name. They key is
231  /// always known to be a StringAttr.
233 
234  /// This is used when name conflicts are detected.
235  unsigned uniquingCounter = 0;
236 };
237 
238 raw_ostream &operator<<(raw_ostream &os, SymbolTable::Visibility visibility);
239 
240 //===----------------------------------------------------------------------===//
241 // SymbolTableCollection
242 //===----------------------------------------------------------------------===//
243 
244 /// This class represents a collection of `SymbolTable`s. This simplifies
245 /// certain algorithms that run recursively on nested symbol tables. Symbol
246 /// tables are constructed lazily to reduce the upfront cost of constructing
247 /// unnecessary tables.
249 public:
250  /// Look up a symbol with the specified name within the specified symbol table
251  /// operation, returning null if no such name exists.
252  Operation *lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol);
253  Operation *lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name);
254  template <typename T, typename NameT>
255  T lookupSymbolIn(Operation *symbolTableOp, NameT &&name) {
256  return dyn_cast_or_null<T>(
257  lookupSymbolIn(symbolTableOp, std::forward<NameT>(name)));
258  }
259  /// A variant of 'lookupSymbolIn' that returns all of the symbols referenced
260  /// by a given SymbolRefAttr when resolved within the provided symbol table
261  /// operation. Returns failure if any of the nested references could not be
262  /// resolved.
263  LogicalResult lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name,
265 
266  /// Returns the operation registered with the given symbol name within the
267  /// closest parent operation of, or including, 'from' with the
268  /// 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol was
269  /// found.
270  Operation *lookupNearestSymbolFrom(Operation *from, StringAttr symbol);
271  Operation *lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol);
272  template <typename T>
273  T lookupNearestSymbolFrom(Operation *from, StringAttr symbol) {
274  return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
275  }
276  template <typename T>
277  T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol) {
278  return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
279  }
280 
281  /// Lookup, or create, a symbol table for an operation.
283 
284 private:
286 
287  /// The constructed symbol tables nested within this table.
289 };
290 
291 //===----------------------------------------------------------------------===//
292 // LockedSymbolTableCollection
293 //===----------------------------------------------------------------------===//
294 
295 /// This class implements a lock-based shared wrapper around a symbol table
296 /// collection that allows shared access to the collection of symbol tables.
297 /// This class does not protect shared access to individual symbol tables.
298 /// `SymbolTableCollection` lazily instantiates `SymbolTable` instances for
299 /// symbol table operations, making read operations not thread-safe. This class
300 /// provides a thread-safe `lookupSymbolIn` implementation by synchronizing the
301 /// lazy `SymbolTable` lookup.
303 public:
305  : collection(collection) {}
306 
307  /// Look up a symbol with the specified name within the specified symbol table
308  /// operation, returning null if no such name exists.
309  Operation *lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol);
310  /// Look up a symbol with the specified name within the specified symbol table
311  /// operation, returning null if no such name exists.
312  Operation *lookupSymbolIn(Operation *symbolTableOp, FlatSymbolRefAttr symbol);
313  /// Look up a potentially nested symbol within the specified symbol table
314  /// operation, returning null if no such symbol exists.
315  Operation *lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name);
316 
317  /// Lookup a symbol of a particular kind within the specified symbol table,
318  /// returning null if the symbol was not found.
319  template <typename T, typename NameT>
320  T lookupSymbolIn(Operation *symbolTableOp, NameT &&name) {
321  return dyn_cast_or_null<T>(
322  lookupSymbolIn(symbolTableOp, std::forward<NameT>(name)));
323  }
324 
325  /// A variant of 'lookupSymbolIn' that returns all of the symbols referenced
326  /// by a given SymbolRefAttr when resolved within the provided symbol table
327  /// operation. Returns failure if any of the nested references could not be
328  /// resolved.
329  LogicalResult lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name,
331 
332 private:
333  /// Get the symbol table for the symbol table operation, constructing if it
334  /// does not exist. This function provides thread safety over `collection`
335  /// by locking when performing the lookup and when inserting
336  /// lazily-constructed symbol tables.
337  SymbolTable &getSymbolTable(Operation *symbolTableOp);
338 
339  /// The symbol tables to manage.
340  SymbolTableCollection &collection;
341  /// The mutex protecting access to the symbol table collection.
342  llvm::sys::SmartRWMutex<true> mutex;
343 };
344 
345 //===----------------------------------------------------------------------===//
346 // SymbolUserMap
347 //===----------------------------------------------------------------------===//
348 
349 /// This class represents a map of symbols to users, and provides efficient
350 /// implementations of symbol queries related to users; such as collecting the
351 /// users of a symbol, replacing all uses, etc.
353 public:
354  /// Build a user map for all of the symbols defined in regions nested under
355  /// 'symbolTableOp'. A reference to the provided symbol table collection is
356  /// kept by the user map to ensure efficient lookups, thus the lifetime should
357  /// extend beyond that of this map.
358  SymbolUserMap(SymbolTableCollection &symbolTable, Operation *symbolTableOp);
359 
360  /// Return the users of the provided symbol operation.
362  auto it = symbolToUsers.find(symbol);
363  return it != symbolToUsers.end() ? it->second.getArrayRef() : std::nullopt;
364  }
365 
366  /// Return true if the given symbol has no uses.
367  bool useEmpty(Operation *symbol) const {
368  return !symbolToUsers.count(symbol);
369  }
370 
371  /// Replace all of the uses of the given symbol with `newSymbolName`.
372  void replaceAllUsesWith(Operation *symbol, StringAttr newSymbolName);
373 
374 private:
375  /// A reference to the symbol table used to construct this map.
376  SymbolTableCollection &symbolTable;
377 
378  /// A map of symbol operations to symbol users.
380 };
381 
382 //===----------------------------------------------------------------------===//
383 // SymbolTable Trait Types
384 //===----------------------------------------------------------------------===//
385 
386 namespace detail {
387 LogicalResult verifySymbolTable(Operation *op);
388 LogicalResult verifySymbol(Operation *op);
389 } // namespace detail
390 
391 namespace OpTrait {
392 /// A trait used to provide symbol table functionalities to a region operation.
393 /// This operation must hold exactly 1 region. Once attached, all operations
394 /// that are directly within the region, i.e not including those within child
395 /// regions, that contain a 'SymbolTable::getSymbolAttrName()' StringAttr will
396 /// be verified to ensure that the names are uniqued. These operations must also
397 /// adhere to the constraints defined by the `Symbol` trait, even if they do not
398 /// inherit from it.
399 template <typename ConcreteType>
400 class SymbolTable : public TraitBase<ConcreteType, SymbolTable> {
401 public:
404  }
405 
406  /// Look up a symbol with the specified name, returning null if no such
407  /// name exists. Symbol names never include the @ on them. Note: This
408  /// performs a linear scan of held symbols.
409  Operation *lookupSymbol(StringAttr name) {
410  return mlir::SymbolTable::lookupSymbolIn(this->getOperation(), name);
411  }
412  template <typename T>
413  T lookupSymbol(StringAttr name) {
414  return dyn_cast_or_null<T>(lookupSymbol(name));
415  }
416  Operation *lookupSymbol(SymbolRefAttr symbol) {
417  return mlir::SymbolTable::lookupSymbolIn(this->getOperation(), symbol);
418  }
419  template <typename T>
420  T lookupSymbol(SymbolRefAttr symbol) {
421  return dyn_cast_or_null<T>(lookupSymbol(symbol));
422  }
423 
424  Operation *lookupSymbol(StringRef name) {
425  return mlir::SymbolTable::lookupSymbolIn(this->getOperation(), name);
426  }
427  template <typename T>
428  T lookupSymbol(StringRef name) {
429  return dyn_cast_or_null<T>(lookupSymbol(name));
430  }
431 };
432 
433 } // namespace OpTrait
434 
435 //===----------------------------------------------------------------------===//
436 // Visibility parsing implementation.
437 //===----------------------------------------------------------------------===//
438 
439 namespace impl {
440 /// Parse an optional visibility attribute keyword (i.e., public, private, or
441 /// nested) without quotes in a string attribute named 'attrName'.
442 ParseResult parseOptionalVisibilityKeyword(OpAsmParser &parser,
443  NamedAttrList &attrs);
444 } // namespace impl
445 
446 } // namespace mlir
447 
448 /// Include the generated symbol interfaces.
449 #include "mlir/IR/SymbolInterfaces.h.inc"
450 
451 #endif // MLIR_IR_SYMBOLTABLE_H
OpListType::iterator iterator
Definition: Block.h:133
A symbol reference with a reference path containing a single element.
This class implements a lock-based shared wrapper around a symbol table collection that allows shared...
Definition: SymbolTable.h:302
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name)
Lookup a symbol of a particular kind within the specified symbol table, returning null if the symbol ...
Definition: SymbolTable.h:320
LockedSymbolTableCollection(SymbolTableCollection &collection)
Definition: SymbolTable.h:304
Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
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.
Definition: SymbolTable.h:400
Operation * lookupSymbol(SymbolRefAttr symbol)
Definition: SymbolTable.h:416
Operation * lookupSymbol(StringRef name)
Definition: SymbolTable.h:424
T lookupSymbol(SymbolRefAttr symbol)
Definition: SymbolTable.h:420
T lookupSymbol(StringAttr name)
Definition: SymbolTable.h:413
T lookupSymbol(StringRef name)
Definition: SymbolTable.h:428
Operation * lookupSymbol(StringAttr name)
Look up a symbol with the specified name, returning null if no such name exists.
Definition: SymbolTable.h:409
static LogicalResult verifyRegionTrait(Operation *op)
Definition: SymbolTable.h:402
Helper class for implementing traits.
Definition: OpDefinition.h:366
Operation * getOperation()
Return the ultimate Operation being worked on.
Definition: OpDefinition.h:369
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.
Definition: SymbolTable.h:248
T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Definition: SymbolTable.h:273
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name)
Definition: SymbolTable.h:255
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)
Definition: SymbolTable.h:277
Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
Look up a symbol with the specified name within the specified symbol table operation,...
SymbolTable & getSymbolTable(Operation *op)
Lookup, or create, a symbol table for an operation.
This class represents a specific symbol use.
Definition: SymbolTable.h:148
SymbolUse(Operation *op, SymbolRefAttr symbolRef)
Definition: SymbolTable.h:150
SymbolRefAttr getSymbolRef() const
Return the symbol reference that this use represents.
Definition: SymbolTable.h:157
Operation * getUser() const
Return the operation user of this symbol reference.
Definition: SymbolTable.h:154
This class implements a range of SymbolRef uses.
Definition: SymbolTable.h:168
UseRange(std::vector< SymbolUse > &&uses)
Definition: SymbolTable.h:170
iterator begin() const
Definition: SymbolTable.h:173
std::vector< SymbolUse >::const_iterator iterator
Definition: SymbolTable.h:172
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
Definition: SymbolTable.h:24
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:59
static void setSymbolVisibility(Operation *symbol, Visibility vis)
Sets the visibility of the given symbol operation.
Operation * getOp() const
Returns the associated operation.
Definition: SymbolTable.h:62
static T lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol)
Definition: SymbolTable.h:143
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:73
@ 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...
@ Private
The symbol is private and may only be referenced by SymbolRefAttrs local to the operations within the...
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
Definition: SymbolTable.h:65
static T lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Definition: SymbolTable.h:139
void erase(Operation *symbol)
Erase the given symbol from the table and delete the operation.
static void setSymbolName(Operation *symbol, StringRef name)
Definition: SymbolTable.h:95
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 Operation * lookupSymbolIn(Operation *op, StringRef symbol)
Definition: SymbolTable.h:121
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'...
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.
This class represents a map of symbols to users, and provides efficient implementations of symbol que...
Definition: SymbolTable.h:352
bool useEmpty(Operation *symbol) const
Return true if the given symbol has no uses.
Definition: SymbolTable.h:367
void replaceAllUsesWith(Operation *symbol, StringAttr newSymbolName)
Replace all of the uses of the given symbol with newSymbolName.
ArrayRef< Operation * > getUsers(Operation *symbol) const
Return the users of the provided symbol operation.
Definition: SymbolTable.h:361
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...
This header declares functions that assist transformations in the MemRef dialect.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
Definition: AliasAnalysis.h:78
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26