Skip to content

Commit 7ec1e0f

Browse files
authored
[MLIR] Add method to invalidate cached symbol table (#138014)
This PR adds a method to the `SymbolTableCollection` class to invalidate the cached symbol table for an operation. This is important when doing IR modifications that erase and also create operations having the `OpTrait::SymbolTable` trait. If a symbol table of an erased operation is not invalidated, a new operation sharing the same address would be associated with outdated, and wrong, information.
1 parent ac9e1df commit 7ec1e0f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

mlir/include/mlir/IR/SymbolTable.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ class SymbolTableCollection {
316316
/// Lookup, or create, a symbol table for an operation.
317317
SymbolTable &getSymbolTable(Operation *op);
318318

319+
/// Invalidate the cached symbol table for an operation.
320+
/// This is important when doing IR modifications that erase and also create
321+
/// operations having the 'OpTrait::SymbolTable' trait. If a symbol table of
322+
/// an erased operation is not invalidated, a new operation sharing the same
323+
/// address would be associated with outdated, and wrong, information.
324+
void invalidateSymbolTable(Operation *op);
325+
319326
private:
320327
friend class LockedSymbolTableCollection;
321328

mlir/lib/IR/SymbolTable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,10 @@ SymbolTable &SymbolTableCollection::getSymbolTable(Operation *op) {
998998
return *it.first->second;
999999
}
10001000

1001+
void SymbolTableCollection::invalidateSymbolTable(Operation *op) {
1002+
symbolTables.erase(op);
1003+
}
1004+
10011005
//===----------------------------------------------------------------------===//
10021006
// LockedSymbolTableCollection
10031007
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)