Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 6ceaaa4

Browse files
authored
Merge pull request #109 from varkor/bss-undefined-globals
Place undefined globals in .bss instead of .data
2 parents 0903c72 + 6baafaa commit 6ceaaa4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/Target/TargetLoweringObjectFile.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,24 @@ TargetLoweringObjectFile::~TargetLoweringObjectFile() {
5252
delete Mang;
5353
}
5454

55+
static bool isNullOrUndef(const Constant *C) {
56+
// Check that the constant isn't all zeros or undefs.
57+
if (C->isNullValue() || isa<UndefValue>(C))
58+
return true;
59+
if (!isa<ConstantAggregate>(C))
60+
return false;
61+
for (auto Operand : C->operand_values()) {
62+
if (!isNullOrUndef(cast<Constant>(Operand)))
63+
return false;
64+
}
65+
return true;
66+
}
67+
5568
static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
5669
const Constant *C = GV->getInitializer();
5770

5871
// Must have zero initializer.
59-
if (!C->isNullValue())
72+
if (!isNullOrUndef(C))
6073
return false;
6174

6275
// Leave constant zeros in readonly constant sections, so they can be shared.

test/CodeGen/ARM/memfunc.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,10 @@ entry:
421421
; CHECK: arr5:
422422
; CHECK-NOT: .p2align
423423
; CHECK: arr6:
424-
; CHECK: .p2align 4
425-
; CHECK: arr8:
424+
; CHECK-IOS: arr8,128,4
425+
; CHECK-DARWIN: arr8,128,4
426+
; CHECK-EABI: arr8,128,16
427+
; CHECK-GNUEABI: arr8,128,16
426428
; CHECK: .p2align 4
427429
; CHECK: arr9:
428430

test/CodeGen/X86/undef-globals-bss.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: llc < %s | FileCheck %s
2+
target triple = "x86_64-apple-darwin"
3+
4+
; CHECK: .zerofill __DATA,__bss,_vals,8000000,2 ## @vals
5+
@vals = internal unnamed_addr global [2000000 x i32] undef, align 4
6+
7+
; CHECK: .zerofill __DATA,__bss,_struct,8000040,3 ## @struct
8+
@struct = internal global { i1, [8000000 x i8], [7 x i8], i64, { [4 x i32], { i8 }, i1 } }
9+
{ i1 false, [8000000 x i8] zeroinitializer, [7 x i8] undef, i64 0,
10+
{ [4 x i32], { i8 }, i1 }
11+
{ [4 x i32] zeroinitializer, { i8 } { i8 undef }, i1 false }
12+
}, align 8

0 commit comments

Comments
 (0)