brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 90fe93f Raw
136 lines · plain
1// RUN: mlir-opt -allow-unregistered-dialect %s -symbol-dce -split-input-file -verify-diagnostics | FileCheck %s2// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline="builtin.module(builtin.module(symbol-dce))" -split-input-file | FileCheck %s --check-prefix=NESTED3 4// Check that trivially dead and trivially live non-nested cases are handled.5 6// CHECK-LABEL: module attributes {test.simple}7module attributes {test.simple} {8  // CHECK-NOT: func private @dead_private_function9  func.func private @dead_private_function()10 11  // CHECK-NOT: func nested @dead_nested_function12  func.func nested @dead_nested_function()13 14  // CHECK: func private @live_private_function15  func.func private @live_private_function()16 17  // CHECK: func nested @live_nested_function18  func.func nested @live_nested_function()19 20  // CHECK: func @public_function21  func.func @public_function() {22    "foo.return"() {uses = [@live_private_function, @live_nested_function]} : () -> ()23  }24}25 26// -----27 28// Check that we don't DCE nested symbols if they are used.29// CHECK-LABEL: module attributes {test.nested}30module attributes {test.nested} {31  // CHECK: module @public_module32  module @public_module {33    // CHECK-NOT: func nested @dead_nested_function34    func.func nested @dead_nested_function()35 36    // CHECK: func private @private_function37    func.func private @private_function()38 39    // CHECK: func nested @nested_function40    func.func nested @nested_function() {41      "foo.return"() {uses = [@private_function]} : () -> ()42    }43  }44 45  "live.user"() {uses = [@public_module::@nested_function]} : () -> ()46}47 48// -----49 50// Check that we don't DCE symbols if we can't prove that the top-level symbol51// table that we are running on is hidden from above.52// NESTED-LABEL: module attributes {test.no_dce_non_hidden_parent}53module attributes {test.no_dce_non_hidden_parent} {54  // NESTED: module @public_module55  module @public_module {56    // NESTED: func nested @nested_function57    func.func nested @nested_function()58  }59  // NESTED: module @nested_module60  module @nested_module attributes { sym_visibility = "nested" } {61    // NESTED: func nested @nested_function62    func.func nested @nested_function()63  }64 65  // Only private modules can be assumed to be hidden.66  // NESTED: module @private_module67  module @private_module attributes { sym_visibility = "private" } {68    // NESTED-NOT: func nested @nested_function69    func.func nested @nested_function()70  }71 72  "live.user"() {uses = [@nested_module, @private_module]} : () -> ()73}74 75// -----76 77module {78  func.func private @private_symbol()79 80  // expected-error@+1 {{contains potentially unknown symbol table}}81  "foo.possibly_unknown_symbol_table"() ({82  }) : () -> ()83}84 85// -----86 87// Check that unknown symbol references are OK.88module {89  // CHECK-NOT: func private @dead_private_function90  func.func private @dead_private_function()91 92  // CHECK: func private @live_private_function93  func.func private @live_private_function()94 95  // CHECK: "live.user"() {uses = [@live_private_function]} : () -> ()96  "live.user"() {uses = [@live_private_function]} : () -> ()97 98  // CHECK: "live.user"() {uses = [@unknown_symbol]} : () -> ()99  "live.user"() {uses = [@unknown_symbol]} : () -> ()100}101 102// -----103 104// Check that we don't DCE nested symbols if they are nested inside region105// without SymbolTable.106 107// CHECK-LABEL: module attributes {test.nested_nosymboltable_region}108module attributes { test.nested_nosymboltable_region } {109  "test.one_region_op"() ({110    "test.symbol_scope"() ({111      // CHECK: func nested @nfunction112      func.func nested @nfunction() {113        return114      }115      func.call @nfunction() : () -> ()116      "test.finish"() : () -> ()117    }) : () -> ()118    "test.finish"() : () -> ()119  }) : () -> ()120}121 122// -----123 124// CHECK-LABEL: module attributes {test.nested_nosymboltable_region_notcalled}125// CHECK-NOT: @nested126// CHECK: @main127module attributes { test.nested_nosymboltable_region_notcalled } {128  "test.one_region_op"() ({129    module {130      func.func nested @nested() { return }131      func.func @main() { return }132    }133    "test.finish"() : () -> ()134  }) : () -> ()135}136