1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

When merging two common GlobalValues, keep the largest.

llvm-svn: 217451
This commit is contained in:
Rafael Espindola 2014-09-09 15:59:12 +00:00
parent 0946a33225
commit c6225c6511
3 changed files with 24 additions and 4 deletions

View File

@ -688,6 +688,9 @@ bool ModuleLinker::shouldLinkFromSource(const GlobalValue &Dest,
bool SrcIsDeclaration = isDeclaration(Src);
bool DestIsDeclaration = isDeclaration(Dest);
// FIXME: Make datalayout mandatory and just use getDataLayout().
DataLayout DL(Dest.getParent());
if (SrcIsDeclaration) {
// If Src is external or if both Src & Dest are external.. Just link the
// external globals, we aren't adding anything.
@ -702,14 +705,26 @@ bool ModuleLinker::shouldLinkFromSource(const GlobalValue &Dest,
// If Dest is external but Src is not:
return true;
if (Src.hasCommonLinkage()) {
if (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage())
return true;
if (!Dest.hasCommonLinkage())
return false;
uint64_t DestSize = DL.getTypeAllocSize(Dest.getType()->getElementType());
uint64_t SrcSize = DL.getTypeAllocSize(Src.getType()->getElementType());
return SrcSize > DestSize;
}
if (Src.isWeakForLinker()) {
assert(!Dest.hasExternalWeakLinkage());
assert(!Dest.hasAvailableExternallyLinkage());
if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage())
return true;
return (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage()) &&
Src.hasCommonLinkage();
return false;
}
if (Dest.isWeakForLinker()) {

View File

@ -1,3 +1,5 @@
@test1_a = weak global i8 1
@test2_a = external dllimport global i8
@test3_a = common global i16 0

View File

@ -2,7 +2,10 @@
; RUN: llvm-link %p/Inputs/linkage2.ll %s -S | FileCheck %s
@test1_a = common global i8 0
; CHECK: @test1_a = common global i8 0
; CHECK-DAG: @test1_a = common global i8 0
@test2_a = global i8 0
; CHECK: @test2_a = global i8 0
; CHECK-DAG: @test2_a = global i8 0
@test3_a = common global i8 0
; CHECK-DAG: @test3_a = common global i16 0