mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-14 15:19:33 +00:00
LTO: Link non-prevailing weak_odr or linkonce_odr globals into the combined module with available_externally linkage.
These linkages mean that the ultimately prevailing symbol will have the same semantics as any non-prevailing copy of the symbol, so we are free to ignore the linker's resolution. Differential Revision: https://reviews.llvm.org/D29367 llvm-svn: 293865
This commit is contained in:
parent
4ab9ae596a
commit
615d8261c2
@ -446,6 +446,11 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI,
|
|||||||
if (GV.hasAppendingLinkage())
|
if (GV.hasAppendingLinkage())
|
||||||
Keep.push_back(&GV);
|
Keep.push_back(&GV);
|
||||||
|
|
||||||
|
DenseSet<GlobalObject *> AliasedGlobals;
|
||||||
|
for (auto &GA : M.aliases())
|
||||||
|
if (GlobalObject *GO = GA.getBaseObject())
|
||||||
|
AliasedGlobals.insert(GO);
|
||||||
|
|
||||||
for (const InputFile::Symbol &Sym :
|
for (const InputFile::Symbol &Sym :
|
||||||
make_range(InputFile::symbol_iterator(SymTab.symbols().begin(), SymTab,
|
make_range(InputFile::symbol_iterator(SymTab.symbols().begin(), SymTab,
|
||||||
nullptr),
|
nullptr),
|
||||||
@ -471,13 +476,21 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI,
|
|||||||
GV->setLinkage(GlobalValue::WeakODRLinkage);
|
GV->setLinkage(GlobalValue::WeakODRLinkage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (GV->hasAvailableExternallyLinkage()) {
|
} else if (isa<GlobalObject>(GV) &&
|
||||||
// We can link available_externally symbols even if they are
|
(GV->hasLinkOnceODRLinkage() || GV->hasWeakODRLinkage() ||
|
||||||
// non-prevailing.
|
GV->hasAvailableExternallyLinkage()) &&
|
||||||
|
!AliasedGlobals.count(cast<GlobalObject>(GV))) {
|
||||||
|
// Either of the above three types of linkage indicates that the
|
||||||
|
// chosen prevailing symbol will have the same semantics as this copy of
|
||||||
|
// the symbol, so we can link it with available_externally linkage. We
|
||||||
|
// only need to do this if the symbol is undefined.
|
||||||
GlobalValue *CombinedGV =
|
GlobalValue *CombinedGV =
|
||||||
RegularLTO.CombinedModule->getNamedValue(GV->getName());
|
RegularLTO.CombinedModule->getNamedValue(GV->getName());
|
||||||
if (!CombinedGV || CombinedGV->isDeclaration())
|
if (!CombinedGV || CombinedGV->isDeclaration()) {
|
||||||
Keep.push_back(GV);
|
Keep.push_back(GV);
|
||||||
|
GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
|
||||||
|
cast<GlobalObject>(GV)->setComdat(nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Common resolution: collect the maximum size/alignment over all commons.
|
// Common resolution: collect the maximum size/alignment over all commons.
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
define linkonce_odr i32 @f() {
|
||||||
|
ret i32 2
|
||||||
|
}
|
@ -3,16 +3,29 @@
|
|||||||
|
|
||||||
; RUN: llvm-as %s -o %t1
|
; RUN: llvm-as %s -o %t1
|
||||||
; RUN: llvm-as %S/Inputs/link-odr-availextern-ae.ll -o %t2ae
|
; RUN: llvm-as %S/Inputs/link-odr-availextern-ae.ll -o %t2ae
|
||||||
|
; RUN: llvm-as %S/Inputs/link-odr-availextern-odr.ll -o %t2odr
|
||||||
|
|
||||||
; RUN: llvm-lto2 -o %t3 %t1 %t2ae -r %t1,f,p -r %t2ae,f, -save-temps
|
; RUN: llvm-lto2 -o %t3 %t1 %t2ae -r %t1,f,p -r %t2ae,f, -save-temps
|
||||||
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
|
||||||
|
|
||||||
|
; RUN: llvm-lto2 -o %t3 %t1 %t2odr -r %t1,f,p -r %t2odr,f, -save-temps
|
||||||
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
|
||||||
|
|
||||||
; RUN: llvm-lto2 -o %t3 %t2ae %t1 -r %t1,f,p -r %t2ae,f, -save-temps
|
; RUN: llvm-lto2 -o %t3 %t2ae %t1 -r %t1,f,p -r %t2ae,f, -save-temps
|
||||||
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
|
||||||
|
|
||||||
|
; RUN: llvm-lto2 -o %t3 %t2odr %t1 -r %t1,f,p -r %t2odr,f, -save-temps
|
||||||
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
|
||||||
|
|
||||||
; RUN: llvm-lto2 -o %t3 %t2ae -r %t2ae,f, -save-temps
|
; RUN: llvm-lto2 -o %t3 %t2ae -r %t2ae,f, -save-temps
|
||||||
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
|
||||||
|
|
||||||
|
; RUN: llvm-lto2 -o %t3 %t2odr -r %t2odr,f, -save-temps
|
||||||
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
|
||||||
|
|
||||||
|
; RUN: llvm-lto2 -o %t3 %t2odr %t1 -r %t1,f, -r %t2odr,f, -save-temps
|
||||||
|
; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
|
||||||
|
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user