1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[ThinLTO] Keep non-prevailing (linkonce|weak)_odr symbols live

Summary:
If we have a symbol with (linkonce|weak)_odr linkage, we do not want
to dead strip it even it is not prevailing.

IR level (linkonce|weak)_odr symbol can become non-prevailing when we mix
ELF objects and IR objects where the (linkonce|weak)_odr symbol in the ELF
object is prevailing and the ones in the IR objects are not. Stripping
them will prevent us from doing optimizations with them.

By not dead stripping them, We will convert these symbols to
available_externally linkage as a result of non-prevailing and eventually
dropping them after inlining.

I modified cache-prevailing.ll to use linkonce linkage as it is
testing whether cache prevailing bit is effective or not, not
we should treat linkonce_odr alive or not

Reviewers: tejohnson, pcc

Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, llvm-commits

Differential Revision: https://reviews.llvm.org/D52893

llvm-svn: 343970
This commit is contained in:
Xin Tong 2018-10-08 15:12:48 +00:00
parent db32f39ce4
commit 295f397ddc
4 changed files with 33 additions and 10 deletions

View File

@ -741,24 +741,28 @@ void llvm::computeDeadSymbols(
return;
// We only keep live symbols that are known to be non-prevailing if any are
// available_externally. Those symbols are discarded later in the
// EliminateAvailableExternally pass and setting them to not-live breaks
// downstreams users of liveness information (PR36483).
// available_externally, linkonceodr, weakodr. Those symbols are discarded
// later in the EliminateAvailableExternally pass and setting them to
// not-live could break downstreams users of liveness information (PR36483)
// or limit optimization opportunities.
if (isPrevailing(VI.getGUID()) == PrevailingType::No) {
bool AvailableExternally = false;
bool KeepAliveLinkage = false;
bool Interposable = false;
for (auto &S : VI.getSummaryList()) {
if (S->linkage() == GlobalValue::AvailableExternallyLinkage)
AvailableExternally = true;
if (S->linkage() == GlobalValue::AvailableExternallyLinkage ||
S->linkage() == GlobalValue::WeakODRLinkage ||
S->linkage() == GlobalValue::LinkOnceODRLinkage)
KeepAliveLinkage = true;
else if (GlobalValue::isInterposableLinkage(S->linkage()))
Interposable = true;
}
if (!AvailableExternally)
if (!KeepAliveLinkage)
return;
if (Interposable)
report_fatal_error("Interposable and available_externally symbol");
report_fatal_error(
"Interposable and available_externally/linkonce_odr/weak_odr symbol");
}
for (auto &S : VI.getSummaryList())

View File

@ -10,7 +10,7 @@
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.11.0"
@foo = linkonce_odr constant i32 1, comdat
@foo = linkonce constant i32 1, comdat
$foo = comdat any
define i32* @bar() {

View File

@ -18,6 +18,8 @@
; RUN: -r %t1.bc,_baz,l \
; RUN: -r %t1.bc,_boo,l \
; RUN: -r %t1.bc,_live_available_externally_func,l \
; RUN: -r %t1.bc,_live_linkonce_odr_func,l \
; RUN: -r %t1.bc,_live_weak_odr_func,l \
; RUN: -r %t2.bc,_baz,pl \
; RUN: -r %t2.bc,_boo,pl \
; RUN: -r %t2.bc,_dead_func,l \
@ -33,12 +35,16 @@
; COMBINED-DAG: <COMBINED {{.*}} op2=119
; Live, dso_local, Internal
; COMBINED-DAG: <COMBINED {{.*}} op2=103
; Live, Local, LinkOnceODR
; COMBINED-DAG: <COMBINED {{.*}} op2=99
; Live, Local, AvailableExternally
; COMBINED-DAG: <COMBINED {{.*}} op2=97
; Live, Local, External
; COMBINED-DAG: <COMBINED {{.*}} op2=96
; COMBINED-DAG: <COMBINED {{.*}} op2=96
; COMBINED-DAG: <COMBINED {{.*}} op2=96
; Live, Local, WeakODR
; COMBINED-DAG: <COMBINED {{.*}} op2=69
; Local, (Dead)
; COMBINED-DAG: <COMBINED {{.*}} op2=64
; COMBINED-DAG: <COMBINED {{.*}} op2=64
@ -95,6 +101,8 @@
; RUN: -r %t1.bc,_baz,l \
; RUN: -r %t1.bc,_boo,l \
; RUN: -r %t1.bc,_live_available_externally_func,l \
; RUN: -r %t1.bc,_live_linkonce_odr_func,l \
; RUN: -r %t1.bc,_live_weak_odr_func,l \
; RUN: -r %t3.bc,_baz,pl \
; RUN: -r %t3.bc,_boo,pl \
; RUN: -r %t3.bc,_dead_func,l \
@ -140,6 +148,15 @@ define void @dead_func() {
ret void
}
define linkonce_odr void @live_linkonce_odr_func() {
ret void
}
define weak_odr void @live_weak_odr_func() {
ret void
}
define available_externally void @live_available_externally_func() {
ret void
}
@ -147,6 +164,8 @@ define available_externally void @live_available_externally_func() {
define void @main() {
call void @bar()
call void @bar_internal()
call void @live_linkonce_odr_func()
call void @live_weak_odr_func()
call void @live_available_externally_func()
ret void
}

View File

@ -3,7 +3,7 @@
; RUN: not llvm-lto2 run -o %t3.bc %t1.bc %t2.bc -r %t1.bc,bar,px \
; RUN: -r %t1.bc,foo,x -r %t2.bc,foo,x -save-temps 2>&1 | FileCheck %s
; CHECK: Interposable and available_externally symbol
; CHECK: Interposable and available_externally/linkonce_odr/weak_odr symbol
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"