[Mlir-commits] [mlir] 4ca5e95 - [mlir] Symbol DCE ignores unknown symbols

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 5 12:48:36 PST 2022


Author: Mogball
Date: 2022-01-05T20:48:30Z
New Revision: 4ca5e95c6f4e8f48cd8315d801c186f4e7cae69c

URL: https://github.com/llvm/llvm-project/commit/4ca5e95c6f4e8f48cd8315d801c186f4e7cae69c
DIFF: https://github.com/llvm/llvm-project/commit/4ca5e95c6f4e8f48cd8315d801c186f4e7cae69c.diff

LOG: [mlir] Symbol DCE ignores unknown symbols

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

Added: 
    

Modified: 
    mlir/lib/Transforms/SymbolDCE.cpp
    mlir/test/Transforms/test-symbol-dce.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/SymbolDCE.cpp b/mlir/lib/Transforms/SymbolDCE.cpp
index 0319cb95d77d1..1169239099595 100644
--- a/mlir/lib/Transforms/SymbolDCE.cpp
+++ b/mlir/lib/Transforms/SymbolDCE.cpp
@@ -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)

diff  --git a/mlir/test/Transforms/test-symbol-dce.mlir b/mlir/test/Transforms/test-symbol-dce.mlir
index 181352234bddd..a342cdcb6d1ce 100644
--- a/mlir/test/Transforms/test-symbol-dce.mlir
+++ b/mlir/test/Transforms/test-symbol-dce.mlir
@@ -84,7 +84,17 @@ module {
 
 // -----
 
+// Check that unknown symbol references are OK.
 module {
-  // expected-error at +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]} : () -> ()
 }


        


More information about the Mlir-commits mailing list