Skip to content

Commit 2e4c4d5

Browse files
mscuttarirorth
authored andcommitted
[MLIR] Make SymbolTableCollection methods virtual (llvm#141760)
The `LockedSymbolTable` class not only encapsulate a `SymbolTableCollection`, but also extends it. However, the methods of `SymbolTableCollection` are not marked as `virtual`, and therefore methods receiving a `SymbolTableCollection` would always call the base methods even if the object was a subclass. The proposed changes consist in marking the base methods as `virtual`.
1 parent a51db1b commit 2e4c4d5

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

mlir/include/mlir/IR/SymbolTable.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,14 @@ raw_ostream &operator<<(raw_ostream &os, SymbolTable::Visibility visibility);
282282
/// unnecessary tables.
283283
class SymbolTableCollection {
284284
public:
285+
virtual ~SymbolTableCollection() = default;
286+
285287
/// Look up a symbol with the specified name within the specified symbol table
286288
/// operation, returning null if no such name exists.
287-
Operation *lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol);
288-
Operation *lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name);
289+
virtual Operation *lookupSymbolIn(Operation *symbolTableOp,
290+
StringAttr symbol);
291+
virtual Operation *lookupSymbolIn(Operation *symbolTableOp,
292+
SymbolRefAttr name);
289293
template <typename T, typename NameT>
290294
T lookupSymbolIn(Operation *symbolTableOp, NameT &&name) {
291295
return dyn_cast_or_null<T>(
@@ -295,15 +299,18 @@ class SymbolTableCollection {
295299
/// by a given SymbolRefAttr when resolved within the provided symbol table
296300
/// operation. Returns failure if any of the nested references could not be
297301
/// resolved.
298-
LogicalResult lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name,
299-
SmallVectorImpl<Operation *> &symbols);
302+
virtual LogicalResult lookupSymbolIn(Operation *symbolTableOp,
303+
SymbolRefAttr name,
304+
SmallVectorImpl<Operation *> &symbols);
300305

301306
/// Returns the operation registered with the given symbol name within the
302307
/// closest parent operation of, or including, 'from' with the
303308
/// 'OpTrait::SymbolTable' trait. Returns nullptr if no valid symbol was
304309
/// found.
305-
Operation *lookupNearestSymbolFrom(Operation *from, StringAttr symbol);
306-
Operation *lookupNearestSymbolFrom(Operation *from, SymbolRefAttr symbol);
310+
virtual Operation *lookupNearestSymbolFrom(Operation *from,
311+
StringAttr symbol);
312+
virtual Operation *lookupNearestSymbolFrom(Operation *from,
313+
SymbolRefAttr symbol);
307314
template <typename T>
308315
T lookupNearestSymbolFrom(Operation *from, StringAttr symbol) {
309316
return dyn_cast_or_null<T>(lookupNearestSymbolFrom(from, symbol));
@@ -314,14 +321,14 @@ class SymbolTableCollection {
314321
}
315322

316323
/// Lookup, or create, a symbol table for an operation.
317-
SymbolTable &getSymbolTable(Operation *op);
324+
virtual SymbolTable &getSymbolTable(Operation *op);
318325

319326
/// Invalidate the cached symbol table for an operation.
320327
/// This is important when doing IR modifications that erase and also create
321328
/// operations having the 'OpTrait::SymbolTable' trait. If a symbol table of
322329
/// an erased operation is not invalidated, a new operation sharing the same
323330
/// address would be associated with outdated, and wrong, information.
324-
void invalidateSymbolTable(Operation *op);
331+
virtual void invalidateSymbolTable(Operation *op);
325332

326333
private:
327334
friend class LockedSymbolTableCollection;
@@ -348,13 +355,15 @@ class LockedSymbolTableCollection : public SymbolTableCollection {
348355

349356
/// Look up a symbol with the specified name within the specified symbol table
350357
/// operation, returning null if no such name exists.
351-
Operation *lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol);
358+
Operation *lookupSymbolIn(Operation *symbolTableOp,
359+
StringAttr symbol) override;
352360
/// Look up a symbol with the specified name within the specified symbol table
353361
/// operation, returning null if no such name exists.
354362
Operation *lookupSymbolIn(Operation *symbolTableOp, FlatSymbolRefAttr symbol);
355363
/// Look up a potentially nested symbol within the specified symbol table
356364
/// operation, returning null if no such symbol exists.
357-
Operation *lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name);
365+
Operation *lookupSymbolIn(Operation *symbolTableOp,
366+
SymbolRefAttr name) override;
358367

359368
/// Lookup a symbol of a particular kind within the specified symbol table,
360369
/// returning null if the symbol was not found.
@@ -369,14 +378,14 @@ class LockedSymbolTableCollection : public SymbolTableCollection {
369378
/// operation. Returns failure if any of the nested references could not be
370379
/// resolved.
371380
LogicalResult lookupSymbolIn(Operation *symbolTableOp, SymbolRefAttr name,
372-
SmallVectorImpl<Operation *> &symbols);
381+
SmallVectorImpl<Operation *> &symbols) override;
373382

374383
private:
375384
/// Get the symbol table for the symbol table operation, constructing if it
376385
/// does not exist. This function provides thread safety over `collection`
377386
/// by locking when performing the lookup and when inserting
378387
/// lazily-constructed symbol tables.
379-
SymbolTable &getSymbolTable(Operation *symbolTableOp);
388+
SymbolTable &getSymbolTable(Operation *symbolTableOp) override;
380389

381390
/// The symbol tables to manage.
382391
SymbolTableCollection &collection;

0 commit comments

Comments
 (0)