diff options
author | Jan Voung <jvoung@chromium.org> | 2013-04-29 15:52:38 -0700 |
---|---|---|
committer | Jan Voung <jvoung@chromium.org> | 2013-04-29 15:52:38 -0700 |
commit | 1174111b6f8ab1b95085aeb9c3c451e155a27642 (patch) | |
tree | 7bc2b5f216e8722d216594fb3ec2ad996c17835a | |
parent | 9986176a70307f63f089d1bc79284ccb8f19d6cb (diff) |
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
R=mseaborn@chromium.org
Review URL: https://codereview.chromium.org/14197004
-rw-r--r-- | lib/Transforms/NaCl/ExpandVarArgs.cpp | 2 | ||||
-rw-r--r-- | test/Transforms/NaCl/expand-varargs-attrs.ll | 6 | ||||
-rw-r--r-- | test/Transforms/NaCl/expand-varargs-struct.ll | 4 | ||||
-rw-r--r-- | test/Transforms/NaCl/expand-varargs.ll | 38 |
4 files changed, 20 insertions, 30 deletions
diff --git a/lib/Transforms/NaCl/ExpandVarArgs.cpp b/lib/Transforms/NaCl/ExpandVarArgs.cpp index cbafbc2757..fc5f70960a 100644 --- a/lib/Transforms/NaCl/ExpandVarArgs.cpp +++ b/lib/Transforms/NaCl/ExpandVarArgs.cpp @@ -230,7 +230,7 @@ static bool ExpandVarArgCall(InstType *Call, DataLayout *DL) { // Create struct type for packing variable arguments into. We // create this as packed for now and assume that no alignment // padding is desired. - StructType *VarArgsTy = StructType::create(VarArgsTypes, "vararg_call", true); + StructType *VarArgsTy = StructType::get(*Context, VarArgsTypes, true); // Allocate space for the variable argument buffer. Do this at the // start of the function so that we don't leak space if the function diff --git a/test/Transforms/NaCl/expand-varargs-attrs.ll b/test/Transforms/NaCl/expand-varargs-attrs.ll index f1a41f9df8..32c671aa2a 100644 --- a/test/Transforms/NaCl/expand-varargs-attrs.ll +++ b/test/Transforms/NaCl/expand-varargs-attrs.ll @@ -20,7 +20,7 @@ define void @call_with_arg_attrs(%MyStruct* %s) { ret void } ; CHECK: define void @call_with_arg_attrs(%MyStruct* %s) { -; CHECK: call void %vararg_func(%MyStruct* byval %s, %vararg_call{{.*}} %vararg_buffer) +; CHECK: call void %vararg_func(%MyStruct* byval %s, <{ i32 }>* %vararg_buffer) ; The "byval" attribute here should be dropped. @@ -29,7 +29,7 @@ define i32 @pass_struct_via_vararg1(%MyStruct* %s) { ret i32 %result } ; CHECK: define i32 @pass_struct_via_vararg1(%MyStruct* %s) { -; CHECK: %result = call i32 %vararg_func(i32 111, %{{.*}}* %vararg_buffer) +; CHECK: %result = call i32 %vararg_func(i32 111, <{ %MyStruct }>* %vararg_buffer) ; The "byval" attribute here should be dropped. @@ -38,7 +38,7 @@ define i32 @pass_struct_via_vararg2(%MyStruct* %s) { ret i32 %result } ; CHECK: define i32 @pass_struct_via_vararg2(%MyStruct* %s) { -; CHECK: %result = call i32 %vararg_func(i32 111, %{{.*}}* %vararg_buffer) +; CHECK: %result = call i32 %vararg_func(i32 111, <{ i32, %MyStruct }>* %vararg_buffer) ; Check that return attributes such as "signext" are preserved. diff --git a/test/Transforms/NaCl/expand-varargs-struct.ll b/test/Transforms/NaCl/expand-varargs-struct.ll index f147d7006f..7bb310fd40 100644 --- a/test/Transforms/NaCl/expand-varargs-struct.ll +++ b/test/Transforms/NaCl/expand-varargs-struct.ll @@ -5,8 +5,6 @@ declare i32 @varargs_func(i32 %arg, ...) %MyStruct = type { i64, i64 } -; CHECK: %vararg_call = type <{ i64, %MyStruct }> - ; Test passing a struct by value. define i32 @varargs_call_struct(%MyStruct* %ptr) { %result = call i32 (i32, ...)* @varargs_func(i32 111, i64 222, %MyStruct* byval %ptr) @@ -14,5 +12,5 @@ define i32 @varargs_call_struct(%MyStruct* %ptr) { } ; CHECK: define i32 @varargs_call_struct(%MyStruct* %ptr) { ; CHECK: %vararg_struct_copy = load %MyStruct* %ptr -; CHECK: %vararg_ptr1 = getelementptr %vararg_call* %vararg_buffer, i32 0, i32 1 +; CHECK: %vararg_ptr1 = getelementptr <{ i64, %MyStruct }>* %vararg_buffer, i32 0, i32 1 ; CHECK: store %MyStruct %vararg_struct_copy, %MyStruct* %vararg_ptr1 diff --git a/test/Transforms/NaCl/expand-varargs.ll b/test/Transforms/NaCl/expand-varargs.ll index 93ba538cca..d398cc7a5c 100644 --- a/test/Transforms/NaCl/expand-varargs.ll +++ b/test/Transforms/NaCl/expand-varargs.ll @@ -8,15 +8,6 @@ declare void @llvm.va_copy(i8*, i8*) declare i32 @outside_func(i32 %arg, %va_list* %args) - -; Produced by the expansion of @varargs_call1(): -; CHECK: %vararg_call = type <{ i64, i32 }> - -; Produced by the expansion of @call_with_zero_varargs(). -; We have a dummy field to deal with buggy programs: -; CHECK: %vararg_call.0 = type <{ i32 }> - - define i32 @varargs_func(i32 %arg, ...) { %arglist_alloc = alloca %va_list %arglist = bitcast %va_list* %arglist_alloc to i8* @@ -40,15 +31,15 @@ define i32 @varargs_call1() { ret i32 %result } ; CHECK: define i32 @varargs_call1() { -; CHECK-NEXT: %vararg_buffer = alloca %vararg_call -; CHECK-NEXT: %vararg_lifetime_bitcast = bitcast %vararg_call* %vararg_buffer to i8* +; CHECK-NEXT: %vararg_buffer = alloca <{ i64, i32 }> +; CHECK-NEXT: %vararg_lifetime_bitcast = bitcast <{ i64, i32 }>* %vararg_buffer to i8* ; CHECK-NEXT: call void @llvm.lifetime.start(i64 12, i8* %vararg_lifetime_bitcast) -; CHECK-NEXT: %vararg_ptr = getelementptr %vararg_call* %vararg_buffer, i32 0, i32 0 +; CHECK-NEXT: %vararg_ptr = getelementptr <{ i64, i32 }>* %vararg_buffer, i32 0, i32 0 ; CHECK-NEXT: store i64 222, i64* %vararg_ptr -; CHECK-NEXT: %vararg_ptr1 = getelementptr %vararg_call* %vararg_buffer, i32 0, i32 1 +; CHECK-NEXT: %vararg_ptr1 = getelementptr <{ i64, i32 }>* %vararg_buffer, i32 0, i32 1 ; CHECK-NEXT: store i32 333, i32* %vararg_ptr1 -; CHECK-NEXT: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, %vararg_call*)* -; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, %vararg_call* %vararg_buffer) +; CHECK-NEXT: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, <{ i64, i32 }>*)* +; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, <{ i64, i32 }>* %vararg_buffer) ; CHECK-NEXT: call void @llvm.lifetime.end(i64 12, i8* %vararg_lifetime_bitcast) ; CHECK-NEXT: ret i32 %result @@ -59,9 +50,10 @@ define i32 @call_with_zero_varargs() { ret i32 %result } ; CHECK: define i32 @call_with_zero_varargs() { -; CHECK-NEXT: %vararg_buffer = alloca %vararg_call.0 -; CHECK: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, %vararg_call.0*)* -; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, %vararg_call.0* %vararg_buffer) +; We have a dummy i32 field to deal with buggy programs: +; CHECK-NEXT: %vararg_buffer = alloca <{ i32 }> +; CHECK: %vararg_func = bitcast i32 (i32, ...)* bitcast (i32 (i32, i8*)* @varargs_func to i32 (i32, ...)*) to i32 (i32, <{ i32 }>*)* +; CHECK-NEXT: %result = call i32 %vararg_func(i32 111, <{ i32 }>* %vararg_buffer) ; Check that "invoke" instructions are expanded out too. @@ -75,7 +67,7 @@ lpad: ret i32 0 } ; CHECK: @varargs_invoke -; CHECK: %result = invoke i32 %vararg_func(i32 111, %vararg_call.1* %vararg_buffer) +; CHECK: %result = invoke i32 %vararg_func(i32 111, <{ i64 }>* %vararg_buffer) ; CHECK-NEXT: to label %cont unwind label %lpad ; CHECK: cont: ; CHECK-NEXT: call void @llvm.lifetime.end(i64 8, i8* %vararg_lifetime_bitcast) @@ -90,10 +82,10 @@ define void @varargs_multiple_calls() { } ; CHECK: @varargs_multiple_calls() ; The added allocas should appear at the start of the function. -; CHECK: %vararg_buffer{{.*}} = alloca %vararg_call{{.*}} -; CHECK: %vararg_buffer{{.*}} = alloca %vararg_call{{.*}} -; CHECK: %call1 = call i32 %vararg_func{{.*}}(i32 11, %vararg_call{{.*}}* %vararg_buffer{{.*}}) -; CHECK: %call2 = call i32 %vararg_func{{.*}}(i32 44, %vararg_call{{.*}}* %vararg_buffer{{.*}}) +; CHECK: %vararg_buffer{{.*}} = alloca <{ i64, i32 }> +; CHECK: %vararg_buffer{{.*}} = alloca <{ i64, i32 }> +; CHECK: %call1 = call i32 %vararg_func{{.*}}(i32 11, <{ i64, i32 }>* %vararg_buffer{{.*}}) +; CHECK: %call2 = call i32 %vararg_func{{.*}}(i32 44, <{ i64, i32 }>* %vararg_buffer{{.*}}) define i32 @va_arg_i32(i8* %arglist) { |