1 // RUN: mlir-opt -allow-unregistered-dialect %s -symbol-dce -split-input-file -verify-diagnostics | FileCheck %s
2 // RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="builtin.module(builtin.module(symbol-dce))" -split-input-file | FileCheck %s --check-prefix=NESTED
4 // Check that trivially dead and trivially live non-nested cases are handled.
6 // CHECK-LABEL: module attributes {test.simple}
7 module attributes {test.simple} {
8 // CHECK-NOT: func private @dead_private_function
9 func.func private @dead_private_function()
11 // CHECK-NOT: func nested @dead_nested_function
12 func.func nested @dead_nested_function()
14 // CHECK: func private @live_private_function
15 func.func private @live_private_function()
17 // CHECK: func nested @live_nested_function
18 func.func nested @live_nested_function()
20 // CHECK: func @public_function
21 func.func @public_function() {
22 "foo.return"() {uses = [@live_private_function, @live_nested_function]} : () -> ()
28 // Check that we don't DCE nested symbols if they are used.
29 // CHECK-LABEL: module attributes {test.nested}
30 module attributes {test.nested} {
31 // CHECK: module @public_module
32 module @public_module {
33 // CHECK-NOT: func nested @dead_nested_function
34 func.func nested @dead_nested_function()
36 // CHECK: func private @private_function
37 func.func private @private_function()
39 // CHECK: func nested @nested_function
40 func.func nested @nested_function() {
41 "foo.return"() {uses = [@private_function]} : () -> ()
45 "live.user"() {uses = [@public_module::@nested_function]} : () -> ()
50 // Check that we don't DCE symbols if we can't prove that the top-level symbol
51 // table that we are running on is hidden from above.
52 // NESTED-LABEL: module attributes {test.no_dce_non_hidden_parent}
53 module attributes {test.no_dce_non_hidden_parent} {
54 // NESTED: module @public_module
55 module @public_module {
56 // NESTED: func nested @nested_function
57 func.func nested @nested_function()
59 // NESTED: module @nested_module
60 module @nested_module attributes { sym_visibility = "nested" } {
61 // NESTED: func nested @nested_function
62 func.func nested @nested_function()
65 // Only private modules can be assumed to be hidden.
66 // NESTED: module @private_module
67 module @private_module attributes { sym_visibility = "private" } {
68 // NESTED-NOT: func nested @nested_function
69 func.func nested @nested_function()
72 "live.user"() {uses = [@nested_module, @private_module]} : () -> ()
78 func.func private @private_symbol()
80 // expected-error@+1 {{contains potentially unknown symbol table}}
81 "foo.possibly_unknown_symbol_table"() ({
87 // Check that unknown symbol references are OK.
89 // CHECK-NOT: func private @dead_private_function
90 func.func private @dead_private_function()
92 // CHECK: func private @live_private_function
93 func.func private @live_private_function()
95 // CHECK: "live.user"() {uses = [@live_private_function]} : () -> ()
96 "live.user"() {uses = [@live_private_function]} : () -> ()
98 // CHECK: "live.user"() {uses = [@unknown_symbol]} : () -> ()
99 "live.user"() {uses = [@unknown_symbol]} : () -> ()