Commit ab9e5598 authored by River Riddle's avatar River Riddle
Browse files

[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
parent aff4ed73
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -137,47 +137,47 @@ public:

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

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

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

  /// Attempt to replace all uses of the given symbol 'oldSymbol' with the
  /// provided symbol 'newSymbol' that are nested within the given operation
  /// 'from'. This does not traverse into any nested symbol tables, and will
  /// also only replace uses on 'from' if it does not also define a symbol
  /// table. This is because we treat the region as the boundary of the symbol
  /// table, and not the op itself. If there are any unknown operations that may
  /// potentially be symbol tables, no uses are replaced and failure is
  /// returned.
  /// 'from'. This does not traverse into any nested symbol tables. If there are
  /// any unknown operations that may potentially be symbol tables, no uses are
  /// replaced and failure is returned.
  LLVM_NODISCARD static LogicalResult replaceAllSymbolUses(StringRef oldSymbol,
                                                           StringRef newSymbol,
                                                           Operation *from);
  LLVM_NODISCARD static LogicalResult
  replaceAllSymbolUses(Operation *oldSymbol, StringRef newSymbolName,
                       Operation *from);
  LLVM_NODISCARD static LogicalResult
  replaceAllSymbolUses(StringRef oldSymbol, StringRef newSymbol, Region *from);
  LLVM_NODISCARD static LogicalResult
  replaceAllSymbolUses(Operation *oldSymbol, StringRef newSymbolName,
                       Region *from);

private:
  Operation *symbolTableOp;
+178 −108

File changed.

Preview size limit exceeded, changes collapsed.

+5 −5

File changed.

Preview size limit exceeded, changes collapsed.