Skip to content

Commit

Permalink
[mlir] Symbol DCE ignores unknown symbols
Browse files Browse the repository at this point in the history
Instead of failing when it encounters a reference to an unknown symbol, Symbol DCE should ignore them. References to unknown symbols do not affect the overall function of Symbol DCE, so it should not need to fail when it encounters one.

In general, requiring that symbol references always be valid rather than only when necessary can be overly conservative.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D116047
  • Loading branch information
Mogball committed Jan 5, 2022
1 parent dd83bef commit 4ca5e95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 3 additions & 5 deletions mlir/lib/Transforms/SymbolDCE.cpp
Expand Up @@ -124,11 +124,9 @@ LogicalResult SymbolDCE::computeLiveness(Operation *symbolTableOp,
// Lookup the symbols referenced by this use.
resolvedSymbols.clear();
if (failed(symbolTable.lookupSymbolIn(
op->getParentOp(), use.getSymbolRef(), resolvedSymbols))) {
return use.getUser()->emitError()
<< "unable to resolve reference to symbol "
<< use.getSymbolRef();
}
op->getParentOp(), use.getSymbolRef(), resolvedSymbols)))
// Ignore references to unknown symbols.
continue;

// Mark each of the resolved symbols as live.
for (Operation *resolvedSymbol : resolvedSymbols)
Expand Down
12 changes: 11 additions & 1 deletion mlir/test/Transforms/test-symbol-dce.mlir
Expand Up @@ -84,7 +84,17 @@ module {

// -----

// Check that unknown symbol references are OK.
module {
// expected-error@+1 {{unable to resolve reference to symbol}}
// CHECK-NOT: func private @dead_private_function
func private @dead_private_function()

// CHECK: func private @live_private_function
func private @live_private_function()

// CHECK: "live.user"() {uses = [@live_private_function]} : () -> ()
"live.user"() {uses = [@live_private_function]} : () -> ()

// CHECK: "live.user"() {uses = [@unknown_symbol]} : () -> ()
"live.user"() {uses = [@unknown_symbol]} : () -> ()
}

0 comments on commit 4ca5e95

Please sign in to comment.