1 ; Require asserts for -debug-only 2 ; REQUIRES: asserts 3 4 ; RUN: opt -module-summary %s -o %t1.bc 5 ; RUN: opt -module-summary %p/Inputs/deadstrip.ll -o %t2.bc 6 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc 7 8 ; RUN: llvm-lto -exported-symbol=_main -thinlto-action=promote %t1.bc -thinlto-index=%t.index.bc -o - | llvm-lto -exported-symbol=_main -thinlto-action=internalize -thinlto-index %t.index.bc -thinlto-module-id=%t1.bc - -o - | llvm-dis -o - | FileCheck %s 9 ; RUN: llvm-lto -exported-symbol=_main -thinlto-action=promote %t2.bc -thinlto-index=%t.index.bc -o - | llvm-lto -exported-symbol=_main -thinlto-action=internalize -thinlto-index %t.index.bc -thinlto-module-id=%t2.bc - -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK2 10 11 ; RUN: llvm-lto -exported-symbol=_main -thinlto-action=run %t1.bc %t2.bc 12 ; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck %s --check-prefix=CHECK-NM 13 14 ; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.out -save-temps \ 15 ; RUN: -r %t1.bc,_main,plx \ 16 ; RUN: -r %t1.bc,_bar,pl \ 17 ; RUN: -r %t1.bc,_dead_func,pl \ 18 ; RUN: -r %t1.bc,_baz,l \ 19 ; RUN: -r %t1.bc,_boo,l \ 20 ; RUN: -r %t1.bc,_live_available_externally_func,l \ 21 ; RUN: -r %t2.bc,_baz,pl \ 22 ; RUN: -r %t2.bc,_boo,pl \ 23 ; RUN: -r %t2.bc,_dead_func,l \ 24 ; RUN: -r %t2.bc,_another_dead_func,pl \ 25 ; RUN: -thinlto-threads=1 \ 26 ; RUN: -debug-only=function-import 2>&1 | FileCheck %s --check-prefix=DEBUG 27 ; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s --check-prefix=LTO2 28 ; RUN: llvm-dis < %t.out.2.3.import.bc | FileCheck %s --check-prefix=LTO2-CHECK2 29 ; RUN: llvm-nm %t.out.1 | FileCheck %s --check-prefix=CHECK2-NM 30 31 ; RUN: llvm-bcanalyzer -dump %t.out.index.bc | FileCheck %s --check-prefix=COMBINED 32 ; Live, NotEligibleForImport, dso_local, Internal 33 ; COMBINED-DAG: <COMBINED {{.*}} op2=119 34 ; Live, dso_local, Internal 35 ; COMBINED-DAG: <COMBINED {{.*}} op2=103 36 ; Live, Local, AvailableExternally 37 ; COMBINED-DAG: <COMBINED {{.*}} op2=97 38 ; Live, Local, External 39 ; COMBINED-DAG: <COMBINED {{.*}} op2=96 40 ; COMBINED-DAG: <COMBINED {{.*}} op2=96 41 ; COMBINED-DAG: <COMBINED {{.*}} op2=96 42 ; Local, (Dead) 43 ; COMBINED-DAG: <COMBINED {{.*}} op2=64 44 ; COMBINED-DAG: <COMBINED {{.*}} op2=64 45 ; COMBINED-DAG: <COMBINED {{.*}} op2=64 46 47 ; Dead-stripping on the index allows to internalize these, 48 ; and limit the import of @baz thanks to early pruning. 49 ; CHECK-NOT: available_externally {{.*}} @baz() 50 ; CHECK: @llvm.global_ctors = 51 ; CHECK: define internal void @_GLOBAL__I_a() 52 ; CHECK: define internal void @bar() { 53 ; CHECK: define internal void @bar_internal() 54 ; CHECK: define internal void @dead_func() { 55 ; CHECK-NOT: available_externally {{.*}} @baz() 56 ; LTO2-NOT: available_externally {{.*}} @baz() 57 ; LTO2: @llvm.global_ctors = 58 ; LTO2: define internal void @_GLOBAL__I_a() 59 ; LTO2: define internal void @bar() { 60 ; LTO2: define internal void @bar_internal() 61 ; LTO2-NOT: @dead_func() 62 ; LTO2-NOT: available_externally {{.*}} @baz() 63 64 ; Make sure we didn't internalize @boo, which is reachable via 65 ; llvm.global_ctors 66 ; CHECK2: define void @boo() 67 ; LTO2-CHECK2: define dso_local void @boo() 68 ; We should have eventually removed @baz since it was internalized and unused 69 ; CHECK2-NM-NOT: _baz 70 71 ; The final binary should not contain any of the dead functions, 72 ; only main is expected because bar is expected to be inlined and stripped out. 73 ; CHECK-NM-NOT: bar 74 ; CHECK-NM-NOT: dead 75 ; CHECK-NM: T _main 76 ; CHECK-NM-NOT: bar 77 ; CHECK-NM-NOT: dead 78 79 ; DEBUG-DAG: Live root: 2412314959268824392 (llvm.global_ctors) 80 ; DEBUG-DAG: Live root: 15822663052811949562 (main) 81 ; DEBUG-DAG: Ignores Dead GUID: 7342339837106705152 (dead_func) 82 ; DEBUG-DAG: Ignores Dead GUID: 7546896869197086323 (baz) 83 ; DEBUG-DAG: Initialize import for 15611644523426561710 (boo) 84 ; DEBUG-DAG: Ignores Dead GUID: 2384416018110111308 (another_dead_func) 85 86 ; Next test the case where Inputs/deadstrip.ll does not get a module index, 87 ; which will cause it to be handled by regular LTO in the new LTO API. 88 ; In that case there are uses of @dead_func in the regular LTO partition 89 ; and it shouldn't be internalized. 90 ; RUN: opt %p/Inputs/deadstrip.ll -o %t3.bc 91 ; RUN: llvm-lto2 run %t1.bc %t3.bc -o %t4.out -save-temps \ 92 ; RUN: -r %t1.bc,_main,plx \ 93 ; RUN: -r %t1.bc,_bar,pl \ 94 ; RUN: -r %t1.bc,_dead_func,pl \ 95 ; RUN: -r %t1.bc,_baz,l \ 96 ; RUN: -r %t1.bc,_boo,l \ 97 ; RUN: -r %t1.bc,_live_available_externally_func,l \ 98 ; RUN: -r %t3.bc,_baz,pl \ 99 ; RUN: -r %t3.bc,_boo,pl \ 100 ; RUN: -r %t3.bc,_dead_func,l \ 101 ; RUN: -r %t3.bc,_another_dead_func,pl 102 ; RUN: llvm-dis < %t4.out.1.3.import.bc | FileCheck %s --check-prefix=CHECK-NOTDEAD 103 ; RUN: llvm-nm %t4.out.0 | FileCheck %s --check-prefix=CHECK-NM-NOTDEAD 104 105 ; We can't internalize @dead_func because of the use in the regular LTO 106 ; partition. 107 ; CHECK-NOTDEAD: define dso_local void @dead_func() 108 ; We also can't eliminate @baz because it is in the regular LTO partition 109 ; and called from @dead_func. 110 ; CHECK-NM-NOTDEAD: T _baz 111 112 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 113 target triple = "x86_64-apple-macosx10.11.0" 114 115 116 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }] 117 118 declare void @baz() 119 120 declare void @boo() 121 122 define internal void @_GLOBAL__I_a() #1 section "__TEXT,__StaticInit,regular,pure_instructions" { 123 entry: 124 call void @boo() 125 ret void 126 } 127 128 define void @bar() { 129 ret void 130 } 131 132 define internal void @bar_internal() { 133 ret void 134 } 135 136 define void @dead_func() { 137 call void @bar() 138 call void @baz() 139 call void @bar_internal() 140 ret void 141 } 142 143 define available_externally void @live_available_externally_func() { 144 ret void 145 } 146 147 define void @main() { 148 call void @bar() 149 call void @bar_internal() 150 call void @live_available_externally_func() 151 ret void 152 } 153