Skip to content

Commit d52bb6d

Browse files
committed
[PowerPC][AIX] ByVal formal argument support: passing on the stack.
Adds support for passing a ByVal formal argument completely on the stack (ie after all argument registers are exhausted). Differential Revision: https://reviews.llvm.org/D78263
1 parent 4cfb71a commit d52bb6d

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7141,12 +7141,11 @@ SDValue PPCTargetLowering::LowerFormalArguments_AIX(
71417141
continue;
71427142

71437143
if (Flags.isByVal() && VA.isMemLoc()) {
7144-
if (Flags.getByValSize() != 0)
7145-
report_fatal_error(
7146-
"ByVal arguments passed on stack not implemented yet");
7147-
7144+
const unsigned Size =
7145+
alignTo(Flags.getByValSize() ? Flags.getByValSize() : PtrByteSize,
7146+
PtrByteSize);
71487147
const int FI = MF.getFrameInfo().CreateFixedObject(
7149-
PtrByteSize, VA.getLocMemOffset(), /* IsImmutable */ false,
7148+
Size, VA.getLocMemOffset(), /* IsImmutable */ false,
71507149
/* IsAliased */ true);
71517150
SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
71527151
InVals.push_back(FIN);

llvm/test/CodeGen/PowerPC/aix-cc-byval-limitation2.ll

Lines changed: 0 additions & 11 deletions
This file was deleted.

llvm/test/CodeGen/PowerPC/aix-cc-byval-mem.ll

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222

2323
define void @call_test_byval_mem1() {
2424
entry:
25-
call void @test_byval_mem1(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, %struct_S1* byval(%struct_S1) align 1 @gS1)
25+
%call = call zeroext i8 @test_byval_mem1(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, %struct_S1* byval(%struct_S1) align 1 @gS1)
2626
ret void
2727
}
2828

29-
declare void @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1* byval(%struct_S1) align 1)
3029

3130
; CHECKASM-LABEL: .call_test_byval_mem1:
3231

@@ -44,18 +43,40 @@ declare void @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1
4443
; ASM64BIT: bl .test_byval_mem1
4544
; ASM64BIT: addi 1, 1, 128
4645

46+
define zeroext i8 @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1* byval(%struct_S1) align 1 %s) {
47+
entry:
48+
%gep = getelementptr inbounds %struct_S1, %struct_S1* %s, i32 0, i32 0
49+
%load = load i8, i8* %gep, align 1
50+
ret i8 %load
51+
}
52+
53+
; CHECK-LABEL: name: test_byval_mem1
54+
55+
; 32BIT: fixedStack:
56+
; 32BIT-NEXT: - { id: 0, type: default, offset: 56, size: 4, alignment: 8, stack-id: default,
57+
; 32BIT: bb.0.entry:
58+
; 32BIT-NEXT: %[[VAL:[0-9]+]]:gprc = LBZ 0, %fixed-stack.0
59+
; 32BIT-NEXT: $r3 = COPY %[[VAL]]
60+
; 32BIT-NEXT: BLR
61+
62+
; 64BIT: fixedStack:
63+
; 64BIT-NEXT: - { id: 0, type: default, offset: 112, size: 8, alignment: 16, stack-id: default,
64+
; 64BIT: bb.0.entry:
65+
; 64BIT-NEXT: %[[VAL:[0-9]+]]:g8rc = LBZ8 0, %fixed-stack.0
66+
; 64BIT-NEXT: $x3 = COPY %[[VAL]]
67+
; 64BIT-NEXT: BLR8
68+
4769

4870
%struct_S256 = type { [256 x i8] }
4971

5072
@gS256 = external global %struct_S256, align 1
5173

5274
define void @call_test_byval_mem2() {
5375
entry:
54-
call void @test_byval_mem2(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, %struct_S256* byval(%struct_S256) align 1 @gS256)
76+
%call = call zeroext i8 @test_byval_mem2(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, %struct_S256* byval(%struct_S256) align 1 @gS256)
5577
ret void
5678
}
5779

58-
declare void @test_byval_mem2(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S256* byval(%struct_S256) align 1)
5980

6081
; CHECK-LABEL: name: call_test_byval_mem2
6182

@@ -122,6 +143,29 @@ declare void @test_byval_mem2(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S2
122143
; ASM64BIT: addi 1, 1, 368
123144

124145

146+
define zeroext i8 @test_byval_mem2(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S256* byval(%struct_S256) align 1 %s) {
147+
entry:
148+
%gep = getelementptr inbounds %struct_S256, %struct_S256* %s, i32 0, i32 0, i32 255
149+
%load = load i8, i8* %gep, align 1
150+
ret i8 %load
151+
}
152+
153+
; CHECK-LABEL: name: test_byval_mem2
154+
155+
; 32BIT: fixedStack:
156+
; 32BIT-NEXT: - { id: 0, type: default, offset: 56, size: 256, alignment: 8, stack-id: default,
157+
; 32BIT: bb.0.entry:
158+
; 32BIT-NEXT: %[[VAL:[0-9]+]]:gprc = LBZ 255, %fixed-stack.0
159+
; 32BIT-NEXT: $r3 = COPY %[[VAL]]
160+
; 32BIT-NEXT: BLR
161+
162+
; 64BIT: fixedStack:
163+
; 64BIT-NEXT: - { id: 0, type: default, offset: 112, size: 256, alignment: 16, stack-id: default,
164+
; 64BIT: bb.0.entry:
165+
; 64BIT-NEXT: %[[VAL:[0-9]+]]:g8rc = LBZ8 255, %fixed-stack.0
166+
; 64BIT-NEXT: $x3 = COPY %[[VAL]]
167+
; 64BIT-NEXT: BLR8
168+
125169
%struct_S57 = type { [57 x i8] }
126170

127171
@gS57 = external global %struct_S57, align 1

0 commit comments

Comments
 (0)