Skip to content

Commit f3d2059

Browse files
authored
Unrolled build for rust-lang#131208
Rollup merge of rust-lang#131208 - mustartt:aix-call-abi, r=davidtwco ABI: Pass aggregates by value on AIX On AIX we pass aggregates byval. Adds new ABI for AIX for powerpc64. https://github.com/llvm/llvm-project/blob/313ad85dfa40a18f2edefd7ce2edc0528d5a554a/clang/lib/CodeGen/Targets/PPC.cpp#L216 Fixes the following 2 testcases on AIX: ``` tests/ui/abi/extern/extern-pass-TwoU16s.rs tests/ui/abi/extern/extern-pass-TwoU8s.rs ```
2 parents f496659 + e502a7f commit f3d2059

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

compiler/rustc_target/src/abi/call/powerpc64.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::spec::HasTargetSpec;
1010
enum ABI {
1111
ELFv1, // original ABI used for powerpc64 (big-endian)
1212
ELFv2, // newer ABI used for powerpc64le and musl (both endians)
13+
AIX, // used by AIX OS, big-endian only
1314
}
1415
use ABI::*;
1516

@@ -23,9 +24,9 @@ where
2324
C: HasDataLayout,
2425
{
2526
arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
26-
// ELFv1 only passes one-member aggregates transparently.
27+
// ELFv1 and AIX only passes one-member aggregates transparently.
2728
// ELFv2 passes up to eight uniquely addressable members.
28-
if (abi == ELFv1 && arg.layout.size > unit.size)
29+
if ((abi == ELFv1 || abi == AIX) && arg.layout.size > unit.size)
2930
|| arg.layout.size > unit.size.checked_mul(8, cx).unwrap()
3031
{
3132
return None;
@@ -55,8 +56,15 @@ where
5556
return;
5657
}
5758

59+
// The AIX ABI expect byval for aggregates
60+
// See https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/Targets/PPC.cpp.
61+
if !is_ret && abi == AIX {
62+
arg.pass_by_stack_offset(None);
63+
return;
64+
}
65+
5866
// The ELFv1 ABI doesn't return aggregates in registers
59-
if is_ret && abi == ELFv1 {
67+
if is_ret && (abi == ELFv1 || abi == AIX) {
6068
arg.make_indirect();
6169
return;
6270
}
@@ -93,6 +101,8 @@ where
93101
{
94102
let abi = if cx.target_spec().env == "musl" {
95103
ELFv2
104+
} else if cx.target_spec().os == "aix" {
105+
AIX
96106
} else {
97107
match cx.data_layout().endian {
98108
Endian::Big => ELFv1,

tests/assembly/powerpc64-struct-abi.rs

+39-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ revisions: elfv1-be elfv2-be elfv2-le
1+
//@ revisions: elfv1-be elfv2-be elfv2-le aix
22
//@ assembly-output: emit-asm
33
//@ compile-flags: -O
44
//@[elfv1-be] compile-flags: --target powerpc64-unknown-linux-gnu
@@ -7,8 +7,13 @@
77
//@[elfv2-be] needs-llvm-components: powerpc
88
//@[elfv2-le] compile-flags: --target powerpc64le-unknown-linux-gnu
99
//@[elfv2-le] needs-llvm-components: powerpc
10+
//@[aix] compile-flags: --target powerpc64-ibm-aix
11+
//@[aix] needs-llvm-components: powerpc
1012
//@[elfv1-be] filecheck-flags: --check-prefix be
1113
//@[elfv2-be] filecheck-flags: --check-prefix be
14+
//@[elfv1-be] filecheck-flags: --check-prefix elf
15+
//@[elfv2-be] filecheck-flags: --check-prefix elf
16+
//@[elfv2-le] filecheck-flags: --check-prefix elf
1217

1318
#![feature(no_core, lang_items)]
1419
#![no_std]
@@ -44,6 +49,10 @@ struct FiveU16s(u16, u16, u16, u16, u16);
4449
struct ThreeU8s(u8, u8, u8);
4550

4651
// CHECK-LABEL: read_large
52+
// aix: lwz [[REG1:.*]], 16(4)
53+
// aix-NEXT: lxvd2x 0, 0, 4
54+
// aix-NEXT: stw [[REG1]], 16(3)
55+
// aix-NEXT: stxvd2x 0, 0, 3
4756
// be: lwz [[REG1:.*]], 16(4)
4857
// be-NEXT: stw [[REG1]], 16(3)
4958
// be-NEXT: ld [[REG2:.*]], 8(4)
@@ -61,6 +70,10 @@ extern "C" fn read_large(x: &FiveU32s) -> FiveU32s {
6170
}
6271

6372
// CHECK-LABEL: read_medium
73+
// aix: lhz [[REG1:.*]], 8(4)
74+
// aix-NEXT: ld [[REG2:.*]], 0(4)
75+
// aix-NEXT: sth [[REG1]], 8(3)
76+
// aix-NEXT: std [[REG2]], 0(3)
6477
// elfv1-be: lhz [[REG1:.*]], 8(4)
6578
// elfv1-be-NEXT: ld [[REG2:.*]], 0(4)
6679
// elfv1-be-NEXT: sth [[REG1]], 8(3)
@@ -78,6 +91,10 @@ extern "C" fn read_medium(x: &FiveU16s) -> FiveU16s {
7891
}
7992

8093
// CHECK-LABEL: read_small
94+
// aix: lbz [[REG1:.*]], 2(4)
95+
// aix-NEXT: lhz [[REG2:.*]], 0(4)
96+
// aix-NEXT: stb [[REG1]], 2(3)
97+
// aix-NEXT: sth [[REG2]], 0(3)
8198
// elfv1-be: lbz [[REG1:.*]], 2(4)
8299
// elfv1-be-NEXT: lhz [[REG2:.*]], 0(4)
83100
// elfv1-be-NEXT: stb [[REG1]], 2(3)
@@ -95,9 +112,17 @@ extern "C" fn read_small(x: &ThreeU8s) -> ThreeU8s {
95112
}
96113

97114
// CHECK-LABEL: write_large
98-
// CHECK: std 3, 0(6)
115+
// aix: std 3, 48(1)
116+
// aix-NEXT: rldicl [[REG1:.*]], 5, 32, 32
117+
// aix-NEXT: std 5, 64(1)
118+
// aix-NEXT: std 4, 56(1)
119+
// aix-NEXT: stw [[REG1]], 16(6)
120+
// aix-NEXT: addi [[REG2:.*]], 1, 48
121+
// aix-NEXT: lxvd2x 0, 0, [[REG2]]
122+
// aix-NEXT: stxvd2x 0, 0, 6
123+
// elf: std 3, 0(6)
99124
// be-NEXT: rldicl [[REG1:.*]], 5, 32, 32
100-
// CHECK-NEXT: std 4, 8(6)
125+
// elf-NEXT: std 4, 8(6)
101126
// be-NEXT: stw [[REG1]], 16(6)
102127
// elfv2-le-NEXT: stw 5, 16(6)
103128
// CHECK-NEXT: blr
@@ -107,7 +132,12 @@ extern "C" fn write_large(x: FiveU32s, dest: &mut FiveU32s) {
107132
}
108133

109134
// CHECK-LABEL: write_medium
110-
// CHECK: std 3, 0(5)
135+
// aix: std 4, 56(1)
136+
// aix-NEXT: rldicl [[REG1:.*]], 4, 16, 48
137+
// aix-NEXT: std 3, 48(1)
138+
// aix-NEXT: std 3, 0(5)
139+
// aix-NEXT: sth [[REG1]], 8(5)
140+
// elf: std 3, 0(5)
111141
// be-NEXT: rldicl [[REG1:.*]], 4, 16, 48
112142
// be-NEXT: sth [[REG1]], 8(5)
113143
// elfv2-le-NEXT: sth 4, 8(5)
@@ -118,6 +148,11 @@ extern "C" fn write_medium(x: FiveU16s, dest: &mut FiveU16s) {
118148
}
119149

120150
// CHECK-LABEL: write_small
151+
// aix: std 3, 48(1)
152+
// aix-NEXT: rldicl [[REG1:.*]], 3, 16, 48
153+
// aix-NEXT: sth 3, 0(4)
154+
// aix-NEXT: lbz 3, 50(1)
155+
// aix-NEXT: stb [[REG1]], 2(4)
121156
// be: stb 3, 2(4)
122157
// be-NEXT: srwi [[REG1:.*]], 3, 8
123158
// be-NEXT: sth [[REG1]], 0(4)

0 commit comments

Comments
 (0)