[llvm] r217451 - When merging two common GlobalValues, keep the largest.
Rafael Espindola
rafael.espindola at gmail.com
Tue Sep 9 08:59:12 PDT 2014
Author: rafael
Date: Tue Sep 9 10:59:12 2014
New Revision: 217451
URL: http://llvm.org/viewvc/llvm-project?rev=217451&view=rev
Log:
When merging two common GlobalValues, keep the largest.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/test/Linker/Inputs/linkage2.ll
llvm/trunk/test/Linker/linkage2.ll
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=217451&r1=217450&r2=217451&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Tue Sep 9 10:59:12 2014
@@ -688,6 +688,9 @@ bool ModuleLinker::shouldLinkFromSource(
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(
// 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()) {
Modified: llvm/trunk/test/Linker/Inputs/linkage2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/linkage2.ll?rev=217451&r1=217450&r2=217451&view=diff
==============================================================================
--- llvm/trunk/test/Linker/Inputs/linkage2.ll (original)
+++ llvm/trunk/test/Linker/Inputs/linkage2.ll Tue Sep 9 10:59:12 2014
@@ -1,3 +1,5 @@
@test1_a = weak global i8 1
@test2_a = external dllimport global i8
+
+ at test3_a = common global i16 0
Modified: llvm/trunk/test/Linker/linkage2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/linkage2.ll?rev=217451&r1=217450&r2=217451&view=diff
==============================================================================
--- llvm/trunk/test/Linker/linkage2.ll (original)
+++ llvm/trunk/test/Linker/linkage2.ll Tue Sep 9 10:59:12 2014
@@ -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
+
+ at test3_a = common global i8 0
+; CHECK-DAG: @test3_a = common global i16 0
More information about the llvm-commits
mailing list