Skip to content

Commit 1174111

Browse files
author
Jan Voung
committed
Use unique'ed types for varargs expansion instead of non-unique named types.
Saves a tiny bit of space for var-args heavy bitcode programs, since the anonymous types get unique'ed. E.g., saves 20KB out of 1.6MB in spec gcc when comparing the gzipped files, or about 100KB when not zipped. This is only a savings with the current wire format. If we change the alloca, etc. to only have sizes and not struct types then we would also not have this duplication. Just happened to notice while looking through code for what struct types remain used in the bitcode. random cleanup for: BUG= https://code.google.com/p/nativeclient/issues/detail?id=3338 [email protected] Review URL: https://codereview.chromium.org/14197004
1 parent 9986176 commit 1174111

File tree

4 files changed

+20
-30
lines changed

4 files changed

+20
-30
lines changed

lib/Transforms/NaCl/ExpandVarArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static bool ExpandVarArgCall(InstType *Call, DataLayout *DL) {
230230
// Create struct type for packing variable arguments into. We
231231
// create this as packed for now and assume that no alignment
232232
// padding is desired.
233-
StructType *VarArgsTy = StructType::create(VarArgsTypes, "vararg_call", true);
233+
StructType *VarArgsTy = StructType::get(*Context, VarArgsTypes, true);
234234

235235
// Allocate space for the variable argument buffer. Do this at the
236236
// start of the function so that we don't leak space if the function

test/Transforms/NaCl/expand-varargs-attrs.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define void @call_with_arg_attrs(%MyStruct* %s) {
2020
ret void
2121
}
2222
; CHECK: define void @call_with_arg_attrs(%MyStruct* %s) {
23-
; CHECK: call void %vararg_func(%MyStruct* byval %s, %vararg_call{{.*}} %vararg_buffer)
23+
; CHECK: call void %vararg_func(%MyStruct* byval %s, <{ i32 }>* %vararg_buffer)
2424

2525

2626
; The "byval" attribute here should be dropped.
@@ -29,7 +29,7 @@ define i32 @pass_struct_via_vararg1(%MyStruct* %s) {
2929
ret i32 %result
3030
}
3131
; CHECK: define i32 @pass_struct_via_vararg1(%MyStruct* %s) {
32-
; CHECK: %result = call i32 %vararg_func(i32 111, %{{.*}}* %vararg_buffer)
32+
; CHECK: %result = call i32 %vararg_func(i32 111, <{ %MyStruct }>* %vararg_buffer)
3333

3434

3535
; The "byval" attribute here should be dropped.
@@ -38,7 +38,7 @@ define i32 @pass_struct_via_vararg2(%MyStruct* %s) {
3838
ret i32 %result
3939
}
4040
; CHECK: define i32 @pass_struct_via_vararg2(%MyStruct* %s) {
41-
; CHECK: %result = call i32 %vararg_func(i32 111, %{{.*}}* %vararg_buffer)
41+
; CHECK: %result = call i32 %vararg_func(i32 111, <{ i32, %MyStruct }>* %vararg_buffer)
4242

4343

4444
; Check that return attributes such as "signext" are preserved.

test/Transforms/NaCl/expand-varargs-struct.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ declare i32 @varargs_func(i32 %arg, ...)
55

66
%MyStruct = type { i64, i64 }
77

8-
; CHECK: %vararg_call = type <{ i64, %MyStruct }>
9-
108
; Test passing a struct by value.
119
define i32 @varargs_call_struct(%MyStruct* %ptr) {
1210
%result = call i32 (i32, ...)* @varargs_func(i32 111, i64 222, %MyStruct* byval %ptr)
1311
ret i32 %result
1412
}
1513
; CHECK: define i32 @varargs_call_struct(%MyStruct* %ptr) {
1614
; CHECK: %vararg_struct_copy = load %MyStruct* %ptr
17-
; CHECK: %vararg_ptr1 = getelementptr %vararg_call* %vararg_buffer, i32 0, i32 1
15+
; CHECK: %vararg_ptr1 = getelementptr <{ i64, %MyStruct }>* %vararg_buffer, i32 0, i32 1
1816
; CHECK: store %MyStruct %vararg_struct_copy, %MyStruct* %vararg_ptr1

test/Transforms/NaCl/expand-varargs.ll

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ declare void @llvm.va_copy(i8*, i8*)
88

99
declare i32 @outside_func(i32 %arg, %va_list* %args)
1010

11-
12-
; Produced by the expansion of @varargs_call1():
13-
; CHECK: %vararg_call = type <{ i64, i32 }>
14-
15-
; Produced by the expansion of @call_with_zero_varargs().
16-
; We have a dummy field to deal with buggy programs:
17-
; CHECK: %vararg_call.0 = type <{ i32 }>
18-
19-
2011
define i32 @varargs_func(i32 %arg, ...) {
2112
%arglist_alloc = alloca %va_list
2213
%arglist = bitcast %va_list* %arglist_alloc to i8*
@@ -40,15 +31,15 @@ define i32 @varargs_call1() {
4031
ret i32 %result
4132
}
4233
; CHECK: define i32 @varargs_call1() {
43-
; CHECK-NEXT: %vararg_buffer = alloca %vararg_call
44-
; CHECK-NEXT: %vararg_lifetime_bitcast = bitcast %vararg_call* %vararg_buffer to i8*
34+
; CHECK-NEXT: %vararg_buffer = alloca <{ i64, i32 }>
35+
; CHECK-NEXT: %vararg_lifetime_bitcast = bitcast <{ i64, i32 }>* %vararg_buffer to i8*
4536
; CHECK-NEXT: call void @llvm.lifetime.start(i64 12, i8* %vararg_lifetime_bitcast)
46-
; CHECK-NEXT: %vararg_ptr = getelementptr %vararg_call* %vararg_buffer, i32 0, i32 0
37+
; CHECK-NEXT: %vararg_ptr = getelementptr <{ i64, i32 }>* %vararg_buffer, i32 0, i32 0
4738
; CHECK-NEXT: store i64 222, i64* %vararg_ptr
48-
; CHECK-NEXT: %vararg_ptr1 = getelementptr %vararg_call* %vararg_buffer, i32 0, i32 1
39+
; CHECK-NEXT: %vararg_ptr1 = getelementptr <{ i64, i32 }>* %vararg_buffer, i32 0, i32 1
4940
; CHECK-NEXT: store i32 333, i32* %vararg_ptr1
50-
; CHECK-NEXT: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, %vararg_call*)*
51-
; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, %vararg_call* %vararg_buffer)
41+
; CHECK-NEXT: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, <{ i64, i32 }>*)*
42+
; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, <{ i64, i32 }>* %vararg_buffer)
5243
; CHECK-NEXT: call void @llvm.lifetime.end(i64 12, i8* %vararg_lifetime_bitcast)
5344
; CHECK-NEXT: ret i32 %result
5445

@@ -59,9 +50,10 @@ define i32 @call_with_zero_varargs() {
5950
ret i32 %result
6051
}
6152
; CHECK: define i32 @call_with_zero_varargs() {
62-
; CHECK-NEXT: %vararg_buffer = alloca %vararg_call.0
63-
; CHECK: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, %vararg_call.0*)*
64-
; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, %vararg_call.0* %vararg_buffer)
53+
; We have a dummy i32 field to deal with buggy programs:
54+
; CHECK-NEXT: %vararg_buffer = alloca <{ i32 }>
55+
; CHECK: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, <{ i32 }>*)*
56+
; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, <{ i32 }>* %vararg_buffer)
6557

6658

6759
; Check that "invoke" instructions are expanded out too.
@@ -75,7 +67,7 @@ lpad:
7567
ret i32 0
7668
}
7769
; CHECK: @varargs_invoke
78-
; CHECK: %result = invoke i32 %vararg_func(i32 111, %vararg_call.1* %vararg_buffer)
70+
; CHECK: %result = invoke i32 %vararg_func(i32 111, <{ i64 }>* %vararg_buffer)
7971
; CHECK-NEXT: to label %cont unwind label %lpad
8072
; CHECK: cont:
8173
; CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* %vararg_lifetime_bitcast)
@@ -90,10 +82,10 @@ define void @varargs_multiple_calls() {
9082
}
9183
; CHECK: @varargs_multiple_calls()
9284
; The added allocas should appear at the start of the function.
93-
; CHECK: %vararg_buffer{{.*}} = alloca %vararg_call{{.*}}
94-
; CHECK: %vararg_buffer{{.*}} = alloca %vararg_call{{.*}}
95-
; CHECK: %call1 = call i32 %vararg_func{{.*}}(i32 11, %vararg_call{{.*}}* %vararg_buffer{{.*}})
96-
; CHECK: %call2 = call i32 %vararg_func{{.*}}(i32 44, %vararg_call{{.*}}* %vararg_buffer{{.*}})
85+
; CHECK: %vararg_buffer{{.*}} = alloca <{ i64, i32 }>
86+
; CHECK: %vararg_buffer{{.*}} = alloca <{ i64, i32 }>
87+
; CHECK: %call1 = call i32 %vararg_func{{.*}}(i32 11, <{ i64, i32 }>* %vararg_buffer{{.*}})
88+
; CHECK: %call2 = call i32 %vararg_func{{.*}}(i32 44, <{ i64, i32 }>* %vararg_buffer{{.*}})
9789

9890

9991
define i32 @va_arg_i32(i8* %arglist) {

0 commit comments

Comments
 (0)