[Mlir-commits] [mlir] [mlir] Walk nested non-symbol table ops in symbol dce (PR #143353)
Jacques Pienaar
llvmlistbot at llvm.org
Tue Jun 24 02:38:47 PDT 2025
================
@@ -108,15 +112,42 @@ LogicalResult SymbolDCE::computeLiveness(Operation *symbolTableOp,
// that are referenced within.
while (!worklist.empty()) {
Operation *op = worklist.pop_back_val();
+ LLVM_DEBUG(llvm::dbgs() << "processing: " << op->getName() << "\n");
// If this is a symbol table, recursively compute its liveness.
if (op->hasTrait<OpTrait::SymbolTable>()) {
// The internal symbol table is hidden if the parent is, if its not a
// symbol, or if it is a private symbol.
SymbolOpInterface symbol = dyn_cast<SymbolOpInterface>(op);
bool symIsHidden = symbolTableIsHidden || !symbol || symbol.isPrivate();
+ LLVM_DEBUG(llvm::dbgs() << "\tsymbol table: " << op->getName()
+ << " is hidden: " << symIsHidden << "\n");
if (failed(computeLiveness(op, symbolTable, symIsHidden, liveSymbols)))
return failure();
+ } else {
+ LLVM_DEBUG(llvm::dbgs()
+ << "\tnon-symbol table: " << op->getName() << " is hidden\n");
+ // If the op is not a symbol table, then, unless op itself is dead which
+ // would be handled by DCE, we need to check all the regions and blocks
+ // within the op to find the uses (e.g., consider visibility within op as
+ // if top level rather than relying on pure symbol table visibility). This
+ // is more conservative than SymbolTable::walkSymbolTables in the case
+ // where there is again SymbolTable information to take advantage of.
+ for (auto ®ion : op->getRegions()) {
+ for (auto &block : region.getBlocks()) {
+ for (Operation &op : block) {
+ SymbolOpInterface symbol = dyn_cast<SymbolOpInterface>(&op);
----------------
jpienaar wrote:
That's a good point, I was just treating it like a top, but I can just always add as it shouldn't happen, so can just add unconditionally. Simplified, thanks
https://github.com/llvm/llvm-project/pull/143353
More information about the Mlir-commits
mailing list