2018-06-28 02:03:39 +08:00
|
|
|
; Require asserts for -debug-only
|
|
|
|
; REQUIRES: asserts
|
|
|
|
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: opt -module-summary %s -o %t1.bc
|
|
|
|
; RUN: opt -module-summary %p/Inputs/deadstrip.ll -o %t2.bc
|
|
|
|
; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
|
|
|
|
|
[ThinLTO] Fix ThinLTOCodegenerator to export llvm.used symbols
Summary:
Reapply r357931 with fixes to ThinLTO testcases and llvm-lto tool.
ThinLTOCodeGenerator currently does not preserve llvm.used symbols and
it can internalize them. In order to pass the necessary information to the
legacy ThinLTOCodeGenerator, the input to the code generator is
rewritten to be based on lto::InputFile.
Now ThinLTO using the legacy LTO API will requires data layout in
Module.
"internalize" thinlto action in llvm-lto is updated to run both
"promote" and "internalize" with the same configuration as
ThinLTOCodeGenerator. The old "promote" + "internalize" option does not
produce the same output as ThinLTOCodeGenerator.
This fixes: PR41236
rdar://problem/49293439
Reviewers: tejohnson, pcc, kromanova, dexonsmith
Reviewed By: tejohnson
Subscribers: ormris, bd1976llvm, mehdi_amini, inglorion, eraman, hiraditya, jkorous, dexonsmith, arphaman, dang, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60421
llvm-svn: 358601
2019-04-18 01:38:09 +08:00
|
|
|
; RUN: llvm-lto -exported-symbol=_main -thinlto-action=internalize %t1.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s
|
|
|
|
; RUN: llvm-lto -exported-symbol=_main -thinlto-action=internalize %t2.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK2
|
2017-01-06 05:34:18 +08:00
|
|
|
|
2018-10-17 01:37:45 +08:00
|
|
|
; RUN: llvm-lto -exported-symbol=_main -thinlto-action=run -stats %t1.bc %t2.bc 2>&1 | FileCheck %s --check-prefix=STATS
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck %s --check-prefix=CHECK-NM
|
|
|
|
|
2018-10-17 01:37:45 +08:00
|
|
|
; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.out -save-temps -stats \
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: -r %t1.bc,_main,plx \
|
|
|
|
; RUN: -r %t1.bc,_bar,pl \
|
|
|
|
; RUN: -r %t1.bc,_dead_func,pl \
|
|
|
|
; RUN: -r %t1.bc,_baz,l \
|
|
|
|
; RUN: -r %t1.bc,_boo,l \
|
2018-03-13 13:08:48 +08:00
|
|
|
; RUN: -r %t1.bc,_live_available_externally_func,l \
|
2018-10-08 23:12:48 +08:00
|
|
|
; RUN: -r %t1.bc,_live_linkonce_odr_func,l \
|
|
|
|
; RUN: -r %t1.bc,_live_weak_odr_func,l \
|
2019-01-03 07:18:20 +08:00
|
|
|
; RUN: -r %t1.bc,_linkonceodralias,pl \
|
|
|
|
; RUN: -r %t1.bc,_linkonceodrfuncwithalias,l \
|
|
|
|
; RUN: -r %t1.bc,_linkonceodrfuncwithalias_caller,pl \
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: -r %t2.bc,_baz,pl \
|
|
|
|
; RUN: -r %t2.bc,_boo,pl \
|
2017-12-16 00:27:33 +08:00
|
|
|
; RUN: -r %t2.bc,_dead_func,l \
|
2018-06-28 02:03:39 +08:00
|
|
|
; RUN: -r %t2.bc,_another_dead_func,pl \
|
2019-01-03 07:18:20 +08:00
|
|
|
; RUN: -r %t2.bc,_linkonceodrfuncwithalias,pl \
|
2018-06-28 02:03:39 +08:00
|
|
|
; RUN: -thinlto-threads=1 \
|
2018-10-17 01:37:45 +08:00
|
|
|
; RUN: -debug-only=function-import 2>&1 | FileCheck %s --check-prefix=DEBUG --check-prefix=STATS
|
2017-12-16 10:40:20 +08:00
|
|
|
; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s --check-prefix=LTO2
|
2017-12-16 10:10:00 +08:00
|
|
|
; RUN: llvm-dis < %t.out.2.3.import.bc | FileCheck %s --check-prefix=LTO2-CHECK2
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: llvm-nm %t.out.1 | FileCheck %s --check-prefix=CHECK2-NM
|
|
|
|
|
2017-06-03 02:24:17 +08:00
|
|
|
; RUN: llvm-bcanalyzer -dump %t.out.index.bc | FileCheck %s --check-prefix=COMBINED
|
2018-01-12 06:15:05 +08:00
|
|
|
; Live, NotEligibleForImport, dso_local, Internal
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=119
|
|
|
|
; Live, dso_local, Internal
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=103
|
2018-10-09 00:38:00 +08:00
|
|
|
; Live, Local, WeakODR
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=101
|
2018-10-08 23:12:48 +08:00
|
|
|
; Live, Local, LinkOnceODR
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=99
|
2018-03-13 13:08:48 +08:00
|
|
|
; Live, Local, AvailableExternally
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=97
|
2017-11-05 01:04:39 +08:00
|
|
|
; Live, Local, External
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=96
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=96
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=96
|
|
|
|
; Local, (Dead)
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=64
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=64
|
|
|
|
; COMBINED-DAG: <COMBINED {{.*}} op2=64
|
2017-06-03 02:24:17 +08:00
|
|
|
|
2017-01-06 05:34:18 +08:00
|
|
|
; Dead-stripping on the index allows to internalize these,
|
|
|
|
; and limit the import of @baz thanks to early pruning.
|
|
|
|
; CHECK-NOT: available_externally {{.*}} @baz()
|
|
|
|
; CHECK: @llvm.global_ctors =
|
|
|
|
; CHECK: define internal void @_GLOBAL__I_a()
|
|
|
|
; CHECK: define internal void @bar() {
|
|
|
|
; CHECK: define internal void @bar_internal()
|
|
|
|
; CHECK: define internal void @dead_func() {
|
|
|
|
; CHECK-NOT: available_externally {{.*}} @baz()
|
2017-11-05 01:04:39 +08:00
|
|
|
; LTO2-NOT: available_externally {{.*}} @baz()
|
|
|
|
; LTO2: @llvm.global_ctors =
|
|
|
|
; LTO2: define internal void @_GLOBAL__I_a()
|
2018-01-12 06:15:05 +08:00
|
|
|
; LTO2: define internal void @bar() {
|
2017-11-05 01:04:39 +08:00
|
|
|
; LTO2: define internal void @bar_internal()
|
2018-02-06 08:43:39 +08:00
|
|
|
; LTO2-NOT: @dead_func()
|
2017-11-05 01:04:39 +08:00
|
|
|
; LTO2-NOT: available_externally {{.*}} @baz()
|
2017-01-06 05:34:18 +08:00
|
|
|
|
|
|
|
; Make sure we didn't internalize @boo, which is reachable via
|
|
|
|
; llvm.global_ctors
|
2017-02-03 15:41:43 +08:00
|
|
|
; CHECK2: define void @boo()
|
2017-11-05 01:04:39 +08:00
|
|
|
; LTO2-CHECK2: define dso_local void @boo()
|
2019-01-03 07:18:20 +08:00
|
|
|
|
|
|
|
; Make sure we keep @linkonceodrfuncwithalias in Input/deadstrip.ll alive as it
|
|
|
|
; is reachable from @main.
|
|
|
|
; LTO2-CHECK2: define weak_odr dso_local void @linkonceodrfuncwithalias() {
|
|
|
|
|
2017-06-03 02:24:17 +08:00
|
|
|
; We should have eventually removed @baz since it was internalized and unused
|
2017-01-06 05:34:18 +08:00
|
|
|
; CHECK2-NM-NOT: _baz
|
|
|
|
|
|
|
|
; The final binary should not contain any of the dead functions,
|
|
|
|
; only main is expected because bar is expected to be inlined and stripped out.
|
|
|
|
; CHECK-NM-NOT: bar
|
|
|
|
; CHECK-NM-NOT: dead
|
|
|
|
; CHECK-NM: T _main
|
|
|
|
; CHECK-NM-NOT: bar
|
|
|
|
; CHECK-NM-NOT: dead
|
|
|
|
|
2018-06-28 03:00:35 +08:00
|
|
|
; DEBUG-DAG: Live root: 2412314959268824392 (llvm.global_ctors)
|
|
|
|
; DEBUG-DAG: Live root: 15822663052811949562 (main)
|
|
|
|
; DEBUG-DAG: Ignores Dead GUID: 7342339837106705152 (dead_func)
|
|
|
|
; DEBUG-DAG: Ignores Dead GUID: 7546896869197086323 (baz)
|
|
|
|
; DEBUG-DAG: Initialize import for 15611644523426561710 (boo)
|
|
|
|
; DEBUG-DAG: Ignores Dead GUID: 2384416018110111308 (another_dead_func)
|
2018-06-28 02:03:39 +08:00
|
|
|
|
2018-10-17 01:37:45 +08:00
|
|
|
; STATS: 3 function-import - Number of dead stripped symbols in index
|
|
|
|
|
2017-01-06 05:34:18 +08:00
|
|
|
; Next test the case where Inputs/deadstrip.ll does not get a module index,
|
|
|
|
; which will cause it to be handled by regular LTO in the new LTO API.
|
|
|
|
; In that case there are uses of @dead_func in the regular LTO partition
|
|
|
|
; and it shouldn't be internalized.
|
|
|
|
; RUN: opt %p/Inputs/deadstrip.ll -o %t3.bc
|
2017-04-12 02:12:00 +08:00
|
|
|
; RUN: llvm-lto2 run %t1.bc %t3.bc -o %t4.out -save-temps \
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: -r %t1.bc,_main,plx \
|
|
|
|
; RUN: -r %t1.bc,_bar,pl \
|
|
|
|
; RUN: -r %t1.bc,_dead_func,pl \
|
|
|
|
; RUN: -r %t1.bc,_baz,l \
|
|
|
|
; RUN: -r %t1.bc,_boo,l \
|
2018-03-13 13:08:48 +08:00
|
|
|
; RUN: -r %t1.bc,_live_available_externally_func,l \
|
2018-10-08 23:12:48 +08:00
|
|
|
; RUN: -r %t1.bc,_live_linkonce_odr_func,l \
|
|
|
|
; RUN: -r %t1.bc,_live_weak_odr_func,l \
|
2019-01-03 07:18:20 +08:00
|
|
|
; RUN: -r %t1.bc,_linkonceodralias,pl \
|
|
|
|
; RUN: -r %t1.bc,_linkonceodrfuncwithalias,l \
|
|
|
|
; RUN: -r %t1.bc,_linkonceodrfuncwithalias_caller,pl \
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: -r %t3.bc,_baz,pl \
|
|
|
|
; RUN: -r %t3.bc,_boo,pl \
|
2017-12-16 00:27:33 +08:00
|
|
|
; RUN: -r %t3.bc,_dead_func,l \
|
2019-01-03 07:18:20 +08:00
|
|
|
; RUN: -r %t3.bc,_another_dead_func,pl \
|
|
|
|
; RUN: -r %t3.bc,_linkonceodrfuncwithalias,pl
|
2017-01-06 05:34:18 +08:00
|
|
|
; RUN: llvm-dis < %t4.out.1.3.import.bc | FileCheck %s --check-prefix=CHECK-NOTDEAD
|
|
|
|
; RUN: llvm-nm %t4.out.0 | FileCheck %s --check-prefix=CHECK-NM-NOTDEAD
|
|
|
|
|
|
|
|
; We can't internalize @dead_func because of the use in the regular LTO
|
|
|
|
; partition.
|
2017-11-05 01:04:39 +08:00
|
|
|
; CHECK-NOTDEAD: define dso_local void @dead_func()
|
2017-01-06 05:34:18 +08:00
|
|
|
; We also can't eliminate @baz because it is in the regular LTO partition
|
|
|
|
; and called from @dead_func.
|
|
|
|
; CHECK-NM-NOTDEAD: T _baz
|
|
|
|
|
2019-09-11 07:15:38 +08:00
|
|
|
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
2017-01-06 05:34:18 +08:00
|
|
|
target triple = "x86_64-apple-macosx10.11.0"
|
|
|
|
|
|
|
|
|
2019-05-15 11:08:21 +08:00
|
|
|
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
|
2017-01-06 05:34:18 +08:00
|
|
|
|
|
|
|
declare void @baz()
|
|
|
|
|
|
|
|
declare void @boo()
|
|
|
|
|
|
|
|
define internal void @_GLOBAL__I_a() #1 section "__TEXT,__StaticInit,regular,pure_instructions" {
|
|
|
|
entry:
|
|
|
|
call void @boo()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @bar() {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define internal void @bar_internal() {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @dead_func() {
|
|
|
|
call void @bar()
|
|
|
|
call void @baz()
|
|
|
|
call void @bar_internal()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2018-10-08 23:12:48 +08:00
|
|
|
|
|
|
|
define linkonce_odr void @live_linkonce_odr_func() {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define weak_odr void @live_weak_odr_func() {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:08:48 +08:00
|
|
|
define available_externally void @live_available_externally_func() {
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2019-01-03 07:18:20 +08:00
|
|
|
; This alias will set its base object in this file (linkonceodrfuncwithalias)
|
|
|
|
; alive.
|
|
|
|
; We want to make sure the @linkonceodrfuncwithalias copy in Input/deadstrip.ll
|
|
|
|
; is also scanned when computing reachability.
|
|
|
|
@linkonceodralias = linkonce_odr alias void (), void ()* @linkonceodrfuncwithalias
|
|
|
|
|
|
|
|
define linkonce_odr void @linkonceodrfuncwithalias() {
|
|
|
|
entry:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @linkonceodrfuncwithalias_caller() {
|
|
|
|
entry:
|
|
|
|
call void @linkonceodrfuncwithalias()
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-06 05:34:18 +08:00
|
|
|
define void @main() {
|
|
|
|
call void @bar()
|
|
|
|
call void @bar_internal()
|
2018-10-08 23:12:48 +08:00
|
|
|
call void @live_linkonce_odr_func()
|
|
|
|
call void @live_weak_odr_func()
|
2018-03-13 13:08:48 +08:00
|
|
|
call void @live_available_externally_func()
|
2019-01-03 07:18:20 +08:00
|
|
|
call void @linkonceodrfuncwithalias_caller()
|
|
|
|
call void @linkonceodralias()
|
2017-01-06 05:34:18 +08:00
|
|
|
ret void
|
|
|
|
}
|