]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/ThinLTO/X86/deadstrip.ll
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / test / ThinLTO / X86 / deadstrip.ll
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 -stats %t1.bc %t2.bc 2>&1 | FileCheck %s --check-prefix=STATS
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 -stats \
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 %t1.bc,_live_linkonce_odr_func,l \
22 ; RUN:   -r %t1.bc,_live_weak_odr_func,l \
23 ; RUN:   -r %t1.bc,_linkonceodralias,pl \
24 ; RUN:   -r %t1.bc,_linkonceodrfuncwithalias,l \
25 ; RUN:   -r %t1.bc,_linkonceodrfuncwithalias_caller,pl \
26 ; RUN:   -r %t2.bc,_baz,pl \
27 ; RUN:   -r %t2.bc,_boo,pl \
28 ; RUN:   -r %t2.bc,_dead_func,l \
29 ; RUN:   -r %t2.bc,_another_dead_func,pl \
30 ; RUN:   -r %t2.bc,_linkonceodrfuncwithalias,pl \
31 ; RUN:   -thinlto-threads=1 \
32 ; RUN:   -debug-only=function-import 2>&1 | FileCheck %s --check-prefix=DEBUG --check-prefix=STATS
33 ; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s --check-prefix=LTO2
34 ; RUN: llvm-dis < %t.out.2.3.import.bc | FileCheck %s --check-prefix=LTO2-CHECK2
35 ; RUN: llvm-nm %t.out.1 | FileCheck %s --check-prefix=CHECK2-NM
36
37 ; RUN: llvm-bcanalyzer -dump %t.out.index.bc | FileCheck %s --check-prefix=COMBINED
38 ; Live, NotEligibleForImport, dso_local, Internal
39 ; COMBINED-DAG: <COMBINED {{.*}} op2=119
40 ; Live, dso_local, Internal
41 ; COMBINED-DAG: <COMBINED {{.*}} op2=103
42 ; Live, Local, WeakODR
43 ; COMBINED-DAG: <COMBINED {{.*}} op2=101
44 ; Live, Local, LinkOnceODR
45 ; COMBINED-DAG: <COMBINED {{.*}} op2=99
46 ; Live, Local, AvailableExternally
47 ; COMBINED-DAG: <COMBINED {{.*}} op2=97
48 ; Live, Local, External
49 ; COMBINED-DAG: <COMBINED {{.*}} op2=96
50 ; COMBINED-DAG: <COMBINED {{.*}} op2=96
51 ; COMBINED-DAG: <COMBINED {{.*}} op2=96
52 ; Local, (Dead)
53 ; COMBINED-DAG: <COMBINED {{.*}} op2=64
54 ; COMBINED-DAG: <COMBINED {{.*}} op2=64
55 ; COMBINED-DAG: <COMBINED {{.*}} op2=64
56
57 ; Dead-stripping on the index allows to internalize these,
58 ; and limit the import of @baz thanks to early pruning.
59 ; CHECK-NOT: available_externally {{.*}} @baz()
60 ; CHECK: @llvm.global_ctors =
61 ; CHECK: define internal void @_GLOBAL__I_a()
62 ; CHECK: define internal void @bar() {
63 ; CHECK: define internal void @bar_internal()
64 ; CHECK: define internal void @dead_func() {
65 ; CHECK-NOT: available_externally {{.*}} @baz()
66 ; LTO2-NOT: available_externally {{.*}} @baz()
67 ; LTO2: @llvm.global_ctors =
68 ; LTO2: define internal void @_GLOBAL__I_a()
69 ; LTO2: define internal void @bar() {
70 ; LTO2: define internal void @bar_internal()
71 ; LTO2-NOT: @dead_func()
72 ; LTO2-NOT: available_externally {{.*}} @baz()
73
74 ; Make sure we didn't internalize @boo, which is reachable via
75 ; llvm.global_ctors
76 ; CHECK2: define void @boo()
77 ; LTO2-CHECK2: define dso_local void @boo()
78
79 ; Make sure we keep @linkonceodrfuncwithalias in Input/deadstrip.ll alive as it
80 ; is reachable from @main.
81 ; LTO2-CHECK2: define weak_odr dso_local void @linkonceodrfuncwithalias() {
82
83 ; We should have eventually removed @baz since it was internalized and unused
84 ; CHECK2-NM-NOT: _baz
85
86 ; The final binary should not contain any of the dead functions,
87 ; only main is expected because bar is expected to be inlined and stripped out.
88 ; CHECK-NM-NOT: bar
89 ; CHECK-NM-NOT: dead
90 ; CHECK-NM: T _main
91 ; CHECK-NM-NOT: bar
92 ; CHECK-NM-NOT: dead
93
94 ; DEBUG-DAG: Live root: 2412314959268824392 (llvm.global_ctors)
95 ; DEBUG-DAG: Live root: 15822663052811949562 (main)
96 ; DEBUG-DAG: Ignores Dead GUID: 7342339837106705152 (dead_func)
97 ; DEBUG-DAG: Ignores Dead GUID: 7546896869197086323 (baz)
98 ; DEBUG-DAG: Initialize import for 15611644523426561710 (boo)
99 ; DEBUG-DAG: Ignores Dead GUID: 2384416018110111308 (another_dead_func)
100
101 ; STATS: 3 function-import  - Number of dead stripped symbols in index
102
103 ; Next test the case where Inputs/deadstrip.ll does not get a module index,
104 ; which will cause it to be handled by regular LTO in the new LTO API.
105 ; In that case there are uses of @dead_func in the regular LTO partition
106 ; and it shouldn't be internalized.
107 ; RUN: opt %p/Inputs/deadstrip.ll -o %t3.bc
108 ; RUN: llvm-lto2 run %t1.bc %t3.bc -o %t4.out -save-temps \
109 ; RUN:   -r %t1.bc,_main,plx \
110 ; RUN:   -r %t1.bc,_bar,pl \
111 ; RUN:   -r %t1.bc,_dead_func,pl \
112 ; RUN:   -r %t1.bc,_baz,l \
113 ; RUN:   -r %t1.bc,_boo,l \
114 ; RUN:   -r %t1.bc,_live_available_externally_func,l \
115 ; RUN:   -r %t1.bc,_live_linkonce_odr_func,l \
116 ; RUN:   -r %t1.bc,_live_weak_odr_func,l \
117 ; RUN:   -r %t1.bc,_linkonceodralias,pl \
118 ; RUN:   -r %t1.bc,_linkonceodrfuncwithalias,l \
119 ; RUN:   -r %t1.bc,_linkonceodrfuncwithalias_caller,pl \
120 ; RUN:   -r %t3.bc,_baz,pl \
121 ; RUN:   -r %t3.bc,_boo,pl \
122 ; RUN:   -r %t3.bc,_dead_func,l \
123 ; RUN:   -r %t3.bc,_another_dead_func,pl \
124 ; RUN:   -r %t3.bc,_linkonceodrfuncwithalias,pl
125 ; RUN: llvm-dis < %t4.out.1.3.import.bc | FileCheck %s --check-prefix=CHECK-NOTDEAD
126 ; RUN: llvm-nm %t4.out.0 | FileCheck %s --check-prefix=CHECK-NM-NOTDEAD
127
128 ; We can't internalize @dead_func because of the use in the regular LTO
129 ; partition.
130 ; CHECK-NOTDEAD: define dso_local void @dead_func()
131 ; We also can't eliminate @baz because it is in the regular LTO partition
132 ; and called from @dead_func.
133 ; CHECK-NM-NOTDEAD: T _baz
134
135 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
136 target triple = "x86_64-apple-macosx10.11.0"
137
138
139 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
140
141 declare void @baz()
142
143 declare void @boo()
144
145 define internal void @_GLOBAL__I_a() #1 section "__TEXT,__StaticInit,regular,pure_instructions" {
146 entry:
147     call void @boo()
148     ret void
149 }
150
151 define void @bar() {
152     ret void
153 }
154
155 define internal void @bar_internal() {
156     ret void
157 }
158
159 define void @dead_func() {
160     call void @bar()
161     call void @baz()
162     call void @bar_internal()
163     ret void
164 }
165
166
167 define linkonce_odr void @live_linkonce_odr_func() {
168     ret void
169 }
170
171 define weak_odr void @live_weak_odr_func() {
172     ret void
173 }
174
175 define available_externally void @live_available_externally_func() {
176     ret void
177 }
178
179 ; This alias will set its base object in this file (linkonceodrfuncwithalias)
180 ; alive.
181 ; We want to make sure the @linkonceodrfuncwithalias copy in Input/deadstrip.ll
182 ; is also scanned when computing reachability.
183 @linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
184
185 define linkonce_odr void @linkonceodrfuncwithalias() {
186 entry:
187   ret void
188 }
189
190 define void @linkonceodrfuncwithalias_caller() {
191 entry:
192   call void @linkonceodrfuncwithalias()
193   ret void
194 }
195
196
197 define void @main() {
198     call void @bar()
199     call void @bar_internal()
200     call void @live_linkonce_odr_func()
201     call void @live_weak_odr_func()
202     call void @live_available_externally_func()
203     call void @linkonceodrfuncwithalias_caller()
204     call void @linkonceodralias()
205     ret void
206 }