summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Brawn <john.brawn@arm.com>2015-07-17 12:12:03 +0000
committerJohn Brawn <john.brawn@arm.com>2015-07-17 12:12:03 +0000
commit9ca9ca2805db7542530dbc41c9ee0f8a20cfa769 (patch)
treeeecdceffe2ee2441b78f7c73a83a0547f5ec9463
parent022622f1d4ee7fc981d182868e0d8aded4c346fe (diff)
downloadbcm5719-llvm-9ca9ca2805db7542530dbc41c9ee0f8a20cfa769.tar.gz
bcm5719-llvm-9ca9ca2805db7542530dbc41c9ee0f8a20cfa769.zip
Make global aliases have symbol size equal to their type
This is mainly for the benefit of GlobalMerge, so that an alias into a MergedGlobals variable has the same size as the original non-merged variable. Differential Revision: http://reviews.llvm.org/D10837 llvm-svn: 242520
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp10
-rw-r--r--llvm/test/CodeGen/AArch64/global-merge-2.ll3
-rw-r--r--llvm/test/CodeGen/AArch64/global-merge-3.ll2
-rw-r--r--llvm/test/CodeGen/ARM/aliases.ll19
4 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 6766fb62b66..068b9172e9f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1111,6 +1111,16 @@ bool AsmPrinter::doFinalization(Module &M) {
// Emit the directives as assignments aka .set:
OutStreamer->EmitAssignment(Name, lowerConstant(Alias.getAliasee()));
+
+ // Set the size of the alias symbol if we can, as otherwise the alias gets
+ // the size of the aliasee which may not be correct e.g. if the alias is of
+ // a member of a struct.
+ if (MAI->hasDotTypeDotSizeDirective() && Alias.getValueType()->isSized()) {
+ const DataLayout &DL = M.getDataLayout();
+ uint64_t Size = DL.getTypeAllocSize(Alias.getValueType());
+ OutStreamer->emitELFSize(cast<MCSymbolELF>(Name),
+ MCConstantExpr::create(Size, OutContext));
+ }
}
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
diff --git a/llvm/test/CodeGen/AArch64/global-merge-2.ll b/llvm/test/CodeGen/AArch64/global-merge-2.ll
index af684039bf1..cdbdb8aed2e 100644
--- a/llvm/test/CodeGen/AArch64/global-merge-2.ll
+++ b/llvm/test/CodeGen/AArch64/global-merge-2.ll
@@ -35,10 +35,13 @@ define void @g1(i32 %a1, i32 %a2) {
;CHECK: .globl x
;CHECK: x = _MergedGlobals_x
+;CHECK: .size x, 4
;CHECK: .globl y
;CHECK: y = _MergedGlobals_x+4
+;CHECK: .size y, 4
;CHECK: .globl z
;CHECK: z = _MergedGlobals_x+8
+;CHECK: .size z, 4
;CHECK-APPLE-IOS: .globl __MergedGlobals_x ; @_MergedGlobals_x
;CHECK-APPLE-IOS: .zerofill __DATA,__common,__MergedGlobals_x,12,3
diff --git a/llvm/test/CodeGen/AArch64/global-merge-3.ll b/llvm/test/CodeGen/AArch64/global-merge-3.ll
index 925108308e5..2e459a069bb 100644
--- a/llvm/test/CodeGen/AArch64/global-merge-3.ll
+++ b/llvm/test/CodeGen/AArch64/global-merge-3.ll
@@ -42,8 +42,10 @@ define void @f1(i32 %a1, i32 %a2, i32 %a3) {
;CHECK: .globl x
;CHECK: x = _MergedGlobals_x+4
+;CHECK: .size x, 4000
;CHECK: .globl y
;CHECK: y = _MergedGlobals_y
+;CHECK: .size y, 4000
;CHECK-APPLE-IOS:.globl _x
;CHECK-APPLE-IOS: _x = __MergedGlobals_x+4
diff --git a/llvm/test/CodeGen/ARM/aliases.ll b/llvm/test/CodeGen/ARM/aliases.ll
index 04ca3e87548..8d0d57db44b 100644
--- a/llvm/test/CodeGen/ARM/aliases.ll
+++ b/llvm/test/CodeGen/ARM/aliases.ll
@@ -2,19 +2,34 @@
; CHECK: .globl test
+; CHECK: .globl structvar
+; CHECK: .size structvar, 8
+
; CHECK: .globl foo1
; CHECK: foo1 = bar
+; CHECK: .size foo1, 4
; CHECK: .globl foo2
; CHECK: foo2 = bar
+; CHECK: .size foo2, 4
; CHECK: .weak bar_f
; CHECK: bar_f = foo_f
; CHECK: bar_i = bar
+; CHECK: .size bar_i, 4
; CHECK: .globl A
; CHECK: A = bar
+; CHECK: .size A, 8
+
+; CHECK: .globl elem0
+; CHECK: elem0 = structvar
+; CHECK: .size elem0, 4
+
+; CHECK: .globl elem1
+; CHECK: elem1 = structvar+4
+; CHECK: .size elem1, 4
@bar = global i32 42
@foo1 = alias i32* @bar
@@ -31,6 +46,10 @@ define i32 @foo_f() {
@A = alias bitcast (i32* @bar to i64*)
+@structvar = global {i32, i32} {i32 1, i32 2}
+@elem0 = alias getelementptr({i32, i32}, {i32, i32}* @structvar, i32 0, i32 0)
+@elem1 = alias getelementptr({i32, i32}, {i32, i32}* @structvar, i32 0, i32 1)
+
define i32 @test() {
entry:
%tmp = load i32, i32* @foo1
OpenPOWER on IntegriCloud