2020-03-30 06:35:38 +08:00
|
|
|
// RUN: mlir-opt -allow-unregistered-dialect %s -symbol-dce -split-input-file -verify-diagnostics | FileCheck %s
|
|
|
|
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="module(symbol-dce)" -split-input-file | FileCheck %s --check-prefix=NESTED
|
2020-01-28 15:24:48 +08:00
|
|
|
|
|
|
|
// Check that trivially dead and trivially live non-nested cases are handled.
|
|
|
|
|
|
|
|
// CHECK-LABEL: module attributes {test.simple}
|
|
|
|
module attributes {test.simple} {
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK-NOT: func private @dead_private_function
|
|
|
|
func private @dead_private_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK-NOT: func nested @dead_nested_function
|
|
|
|
func nested @dead_nested_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK: func private @live_private_function
|
|
|
|
func private @live_private_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK: func nested @live_nested_function
|
|
|
|
func nested @live_nested_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
|
|
|
// CHECK: func @public_function
|
|
|
|
func @public_function() {
|
|
|
|
"foo.return"() {uses = [@live_private_function, @live_nested_function]} : () -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// Check that we don't DCE nested symbols if they are used.
|
|
|
|
// CHECK-LABEL: module attributes {test.nested}
|
|
|
|
module attributes {test.nested} {
|
|
|
|
// CHECK: module @public_module
|
|
|
|
module @public_module {
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK-NOT: func nested @dead_nested_function
|
|
|
|
func nested @dead_nested_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK: func private @private_function
|
|
|
|
func private @private_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
2020-11-10 00:23:55 +08:00
|
|
|
// CHECK: func nested @nested_function
|
|
|
|
func nested @nested_function() {
|
2020-01-28 15:24:48 +08:00
|
|
|
"foo.return"() {uses = [@private_function]} : () -> ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"live.user"() {uses = [@public_module::@nested_function]} : () -> ()
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// Check that we don't DCE symbols if we can't prove that the top-level symbol
|
|
|
|
// table that we are running on is hidden from above.
|
|
|
|
// NESTED-LABEL: module attributes {test.no_dce_non_hidden_parent}
|
|
|
|
module attributes {test.no_dce_non_hidden_parent} {
|
|
|
|
// NESTED: module @public_module
|
|
|
|
module @public_module {
|
2020-11-10 00:23:55 +08:00
|
|
|
// NESTED: func nested @nested_function
|
|
|
|
func nested @nested_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
}
|
|
|
|
// NESTED: module @nested_module
|
|
|
|
module @nested_module attributes { sym_visibility = "nested" } {
|
2020-11-10 00:23:55 +08:00
|
|
|
// NESTED: func nested @nested_function
|
|
|
|
func nested @nested_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only private modules can be assumed to be hidden.
|
|
|
|
// NESTED: module @private_module
|
|
|
|
module @private_module attributes { sym_visibility = "private" } {
|
2020-11-10 00:23:55 +08:00
|
|
|
// NESTED-NOT: func nested @nested_function
|
|
|
|
func nested @nested_function()
|
2020-01-28 15:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
"live.user"() {uses = [@nested_module, @private_module]} : () -> ()
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
module {
|
2020-11-10 00:23:55 +08:00
|
|
|
func private @private_symbol()
|
2020-01-28 15:24:48 +08:00
|
|
|
|
|
|
|
// expected-error@+1 {{contains potentially unknown symbol table}}
|
|
|
|
"foo.possibly_unknown_symbol_table"() ({
|
|
|
|
}) : () -> ()
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
module {
|
|
|
|
// expected-error@+1 {{unable to resolve reference to symbol}}
|
|
|
|
"live.user"() {uses = [@unknown_symbol]} : () -> ()
|
|
|
|
}
|