[PowerPC][AIX] ByVal formal argument support: passing on the stack.
authorSean Fertile <sd.fertile@gmail.com>
Wed, 8 Apr 2020 13:26:57 +0000 (09:26 -0400)
committerSean Fertile <sd.fertile@gmail.com>
Mon, 20 Apr 2020 16:04:59 +0000 (12:04 -0400)
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

llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/CodeGen/PowerPC/aix-cc-byval-limitation2.ll [deleted file]
llvm/test/CodeGen/PowerPC/aix-cc-byval-mem.ll

index c9bd6e8..c90dec2 100644 (file)
@@ -7141,12 +7141,11 @@ SDValue PPCTargetLowering::LowerFormalArguments_AIX(
       continue;
 
     if (Flags.isByVal() && VA.isMemLoc()) {
-      if (Flags.getByValSize() != 0)
-        report_fatal_error(
-            "ByVal arguments passed on stack not implemented yet");
-
+      const unsigned Size =
+          alignTo(Flags.getByValSize() ? Flags.getByValSize() : PtrByteSize,
+                  PtrByteSize);
       const int FI = MF.getFrameInfo().CreateFixedObject(
-          PtrByteSize, VA.getLocMemOffset(), /* IsImmutable */ false,
+          Size, VA.getLocMemOffset(), /* IsImmutable */ false,
           /* IsAliased */ true);
       SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
       InVals.push_back(FIN);
diff --git a/llvm/test/CodeGen/PowerPC/aix-cc-byval-limitation2.ll b/llvm/test/CodeGen/PowerPC/aix-cc-byval-limitation2.ll
deleted file mode 100644 (file)
index e78d595..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-; RUN: not --crash llc -mtriple powerpc-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
-; RUN: not --crash llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s
-
-%struct.S = type { i8 }
-
-define void @foo(i32 %i1, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, %struct.S* byval(%struct.S) align 1 %s) {
-entry:
-  ret void
-}
-
-; CHECK: LLVM ERROR: ByVal arguments passed on stack not implemented yet
index dd55744..4dbe114 100644 (file)
 
 define void @call_test_byval_mem1() {
 entry:
-  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)
+  %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)
   ret void
 }
 
-declare void @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1* byval(%struct_S1) align 1)
 
 ; CHECKASM-LABEL: .call_test_byval_mem1:
 
@@ -44,6 +43,29 @@ declare void @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1
 ; ASM64BIT:       bl .test_byval_mem1
 ; ASM64BIT:       addi 1, 1, 128
 
+define zeroext  i8 @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1* byval(%struct_S1) align 1 %s) {
+entry:
+  %gep = getelementptr inbounds %struct_S1, %struct_S1* %s, i32 0, i32 0
+  %load = load i8, i8* %gep, align 1
+  ret i8 %load
+}
+
+; CHECK-LABEL: name:            test_byval_mem1
+
+; 32BIT:       fixedStack:
+; 32BIT-NEXT:    - { id: 0, type: default, offset: 56, size: 4, alignment: 8, stack-id: default,
+; 32BIT:       bb.0.entry:
+; 32BIT-NEXT:    %[[VAL:[0-9]+]]:gprc = LBZ 0, %fixed-stack.0
+; 32BIT-NEXT:    $r3 = COPY %[[VAL]]
+; 32BIT-NEXT:    BLR
+
+; 64BIT:       fixedStack:
+; 64BIT-NEXT:    - { id: 0, type: default, offset: 112, size: 8, alignment: 16, stack-id: default,
+; 64BIT:       bb.0.entry:
+; 64BIT-NEXT:    %[[VAL:[0-9]+]]:g8rc = LBZ8 0, %fixed-stack.0
+; 64BIT-NEXT:    $x3 = COPY %[[VAL]]
+; 64BIT-NEXT:    BLR8
+
 
 %struct_S256 = type { [256 x i8] }
 
@@ -51,11 +73,10 @@ declare void @test_byval_mem1(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S1
 
 define void @call_test_byval_mem2() {
 entry:
-  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)
+  %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)
   ret void
 }
 
-declare void @test_byval_mem2(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S256* byval(%struct_S256) align 1)
 
 ; CHECK-LABEL:    name: call_test_byval_mem2
 
@@ -122,6 +143,29 @@ declare void @test_byval_mem2(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S2
 ; ASM64BIT:       addi 1, 1, 368
 
 
+define zeroext i8 @test_byval_mem2(i32, i32, i32, i32, i32, i32, i32, i32, %struct_S256* byval(%struct_S256) align 1 %s) {
+entry:
+  %gep = getelementptr inbounds %struct_S256, %struct_S256* %s, i32 0, i32 0, i32 255
+  %load = load i8, i8* %gep, align 1
+  ret i8 %load
+}
+
+; CHECK-LABEL: name:            test_byval_mem2
+
+; 32BIT:      fixedStack:
+; 32BIT-NEXT:   - { id: 0, type: default, offset: 56, size: 256, alignment: 8, stack-id: default,
+; 32BIT:      bb.0.entry:
+; 32BIT-NEXT:   %[[VAL:[0-9]+]]:gprc = LBZ 255, %fixed-stack.0
+; 32BIT-NEXT:   $r3 = COPY %[[VAL]]
+; 32BIT-NEXT:   BLR
+
+; 64BIT:      fixedStack:
+; 64BIT-NEXT:   - { id: 0, type: default, offset: 112, size: 256, alignment: 16, stack-id: default,
+; 64BIT:      bb.0.entry:
+; 64BIT-NEXT:   %[[VAL:[0-9]+]]:g8rc = LBZ8 255, %fixed-stack.0
+; 64BIT-NEXT:   $x3 = COPY %[[VAL]]
+; 64BIT-NEXT:   BLR8
+
 %struct_S57 = type { [57 x i8] }
 
 @gS57 = external global %struct_S57, align 1