[Mlir-commits] [mlir] [mlir][SymbolTable] Handle unknown symbol users in SymbolUserMap (PR #227918)
Vinicius Silva
llvmlistbot at llvm.org
Wed Sep 30 18:07:43 PDT 2026
https://github.com/viniciusfdasilva created https://github.com/llvm/llvm-project/pull/227918
This PR fixes #226052 treating unknown users record the symbol table having this specific users instead use the assertion.
Please see my comment here explaining where the bug was introduced! [here](https://github.com/llvm/llvm-project/issues/226052#issuecomment-5922633002).
>From 046d0ee8c67382381658ae9540b24067ac8873e6 Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Wed, 30 Sep 2026 21:48:46 -0300
Subject: [PATCH] [mlir][SymbolTable] Handle unknown symbol users in
SymbolUserMap
---
mlir/include/mlir/IR/SymbolTable.h | 3 +++
mlir/lib/IR/SymbolTable.cpp | 15 +++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/mlir/include/mlir/IR/SymbolTable.h b/mlir/include/mlir/IR/SymbolTable.h
index 1e57e3ff82912..afb4b91c7d04f 100644
--- a/mlir/include/mlir/IR/SymbolTable.h
+++ b/mlir/include/mlir/IR/SymbolTable.h
@@ -437,6 +437,9 @@ class SymbolUserMap {
/// Non-private symbols whose uses are all visible within this map's scope.
DenseSet<Operation *> symbolsWithAllUsesVisible;
+
+ // Symbol tables for which the uses of some nested op could not be computed
+ DenseSet<Operation *> symbolTablesWithUnknownUsers;
};
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp
index 4b19b4b0d4113..b02bcc2db17d8 100644
--- a/mlir/lib/IR/SymbolTable.cpp
+++ b/mlir/lib/IR/SymbolTable.cpp
@@ -1059,7 +1059,13 @@ SymbolUserMap::SymbolUserMap(SymbolTableCollection &symbolTable,
symbolsWithAllUsesVisible.insert(&nestedOp);
}
auto symbolUses = SymbolTable::getSymbolUses(&nestedOp);
- assert(symbolUses && "expected uses to be valid");
+
+ if (!symbolUses) {
+ // An unknown op with a region may reference any symbol visible from
+ // this table, so we cannot know all users. Record it and move on.
+ symbolTablesWithUnknownUsers.insert(symbolTableOp);
+ continue;
+ }
for (const SymbolTable::SymbolUse &use : *symbolUses) {
symbols.clear();
@@ -1076,6 +1082,11 @@ SymbolUserMap::SymbolUserMap(SymbolTableCollection &symbolTable,
}
bool SymbolUserMap::areAllUsesVisible(Operation *symbol) const {
+ for (Operation *parent = symbol->getParentOp(); parent; parent = parent->getParentOp()){
+ if(symbolTablesWithUnknownUsers.contains(parent)){
+ return false;
+ }
+ }
// Private symbols can only have users within their table.
if (cast<SymbolOpInterface>(symbol).isPrivate())
return true;
@@ -1132,4 +1143,4 @@ ParseResult impl::parseOptionalVisibilityKeyword(OpAsmParser &parser,
/// Include the generated symbol interfaces.
#include "mlir/IR/SymbolInterfaces.cpp.inc"
-#include "mlir/IR/SymbolInterfacesAttrInterface.cpp.inc"
+#include "mlir/IR/SymbolInterfacesAttrInterface.cpp.inc"
\ No newline at end of file
More information about the Mlir-commits
mailing list