llvm.org GIT mirror llvm / 42d4335
This patch addresses an ABI compatibility issue with empty aggregate parameters. Examples of these are: struct { } a; union { } b[256]; int a[0]; An empty aggregate has an address, although dereferencing that address is pointless. When passed as a parameter, an empty aggregate does not consume a protocol register, nor does it consume a doubleword in the parameter save area. Passing an empty aggregate by reference passes an address just as for any other aggregate. Returning an empty aggregate uses GPR3 as a hidden address of the return value location, just as for any other aggregate. The patch modifies PPCTargetLowering::LowerFormalArguments_64SVR4 and PPCTargetLowering::LowerCall_64SVR4 to properly skip empty aggregate parameters passed by value. The handling of return values and by-reference parameters was already correct. Built on powerpc64-unknown-linux-gnu and tested with no new regressions. A test case is included to test proper handling of empty aggregate parameters on both sides of the function call protocol. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167090 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Schmidt 7 years ago
2 changed file(s) with 70 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
20902090 // ObjSize is the true size, ArgSize rounded up to multiple of registers.
20912091 ObjSize = Flags.getByValSize();
20922092 ArgSize = ((ObjSize + PtrByteSize - 1)/PtrByteSize) * PtrByteSize;
2093 // Empty aggregate parameters do not take up registers. Examples:
2094 // struct { } a;
2095 // union { } b;
2096 // int c[0];
2097 // etc. However, we have to provide a place-holder in InVals, so
2098 // pretend we have an 8-byte item at the current address for that
2099 // purpose.
2100 if (!ObjSize) {
2101 int FI = MFI->CreateFixedObject(PtrByteSize, ArgOffset, true);
2102 SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
2103 InVals.push_back(FIN);
2104 continue;
2105 }
20932106 // All aggregates smaller than 8 bytes must be passed right-justified.
20942107 if (ObjSize < PtrByteSize)
20952108 CurArgOffset = CurArgOffset + (PtrByteSize - ObjSize);
36543667 // These are the proper values we need for right-justifying the
36553668 // aggregate in a parameter register.
36563669 unsigned Size = Flags.getByValSize();
3670
3671 // An empty aggregate parameter takes up no storage and no
3672 // registers.
3673 if (Size == 0)
3674 continue;
3675
36573676 // All aggregates smaller than 8 bytes must be passed right-justified.
36583677 if (Size==1 || Size==2 || Size==4) {
36593678 EVT VT = (Size==1) ? MVT::i8 : ((Size==2) ? MVT::i16 : MVT::i32);
0 ; RUN: llc -mcpu=pwr7 -O0 < %s | FileCheck %s
1
2 ; This tests correct handling of empty aggregate parameters and return values.
3 ; An empty parameter passed by value does not consume a protocol register or
4 ; a parameter save area doubleword. An empty parameter passed by reference
5 ; is treated as any other pointer parameter. An empty aggregate return value
6 ; is treated as any other aggregate return value, passed via address as a
7 ; hidden parameter in GPR3. In this example, GPR3 contains the return value
8 ; address, GPR4 contains the address of e2, and e1 and e3 are not passed or
9 ; received.
10
11 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
12 target triple = "powerpc64-unknown-linux-gnu"
13
14 %struct.empty = type {}
15
16 define void @callee(%struct.empty* noalias sret %agg.result, %struct.empty* byval %a1, %struct.empty* %a2, %struct.empty* byval %a3) nounwind {
17 entry:
18 %a2.addr = alloca %struct.empty*, align 8
19 store %struct.empty* %a2, %struct.empty** %a2.addr, align 8
20 %0 = load %struct.empty** %a2.addr, align 8
21 %1 = bitcast %struct.empty* %agg.result to i8*
22 %2 = bitcast %struct.empty* %0 to i8*
23 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* %2, i64 0, i32 1, i1 false)
24 ret void
25 }
26
27 ; CHECK: callee:
28 ; CHECK: std 4,
29 ; CHECK: std 3,
30 ; CHECK-NOT: std 5,
31 ; CHECK-NOT: std 6,
32 ; CHECK: blr
33
34 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
35
36 define void @caller(%struct.empty* noalias sret %agg.result) nounwind {
37 entry:
38 %e1 = alloca %struct.empty, align 1
39 %e2 = alloca %struct.empty, align 1
40 %e3 = alloca %struct.empty, align 1
41 call void @callee(%struct.empty* sret %agg.result, %struct.empty* byval %e1, %struct.empty* %e2, %struct.empty* byval %e3)
42 ret void
43 }
44
45 ; CHECK: caller:
46 ; CHECK: addi 4,
47 ; CHECK: std 3,
48 ; CHECK-NOT: std 5,
49 ; CHECK-NOT: std 6,
50 ; CHECK: bl callee