Skip to content

Commit 74c2b98

Browse files
authored
Rollup merge of #117154 - Dirreke:csky-unknown-linux-gunabiv2, r=bjorn3
implement C ABI lowering for CSKY fix rust-lang/compiler-builtins#551 ​Reference: [CSKY ABI Manual](https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1695027452256/T-HEAD_800_Series_ABI_Standards_Manual.pdf) ​ Reference: [Clang CSKY lowering code](https://github.com/llvm/llvm-project/blob/4a074f32a6914f2a8d7215d78758c24942dddc3d/clang/lib/CodeGen/Targets/CSKY.cpp#L76-L162) r? `@bjorn3`
2 parents 585a122 + 32339f8 commit 74c2b98

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

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

+30-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
1-
// See https://github.com/llvm/llvm-project/blob/d85b94bf0080dcd780656c0f5e6342800720eba9/llvm/lib/Target/CSKY/CSKYCallingConv.td
2-
use crate::abi::call::{ArgAbi, FnAbi};
1+
// Reference: CSKY ABI Manual
2+
// https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1695027452256/T-HEAD_800_Series_ABI_Standards_Manual.pdf
3+
//
4+
// Reference: Clang CSKY lowering code
5+
// https://github.com/llvm/llvm-project/blob/4a074f32a6914f2a8d7215d78758c24942dddc3d/clang/lib/CodeGen/Targets/CSKY.cpp#L76-L162
36

4-
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
5-
if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 {
6-
ret.make_indirect();
7+
use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform};
8+
9+
fn classify_ret<Ty>(arg: &mut ArgAbi<'_, Ty>) {
10+
// For return type, aggregate which <= 2*XLen will be returned in registers.
11+
// Otherwise, aggregate will be returned indirectly.
12+
if arg.layout.is_aggregate() {
13+
let total = arg.layout.size;
14+
if total.bits() > 64 {
15+
arg.make_indirect();
16+
} else if total.bits() > 32 {
17+
arg.cast_to(Uniform { unit: Reg::i32(), total });
18+
} else {
19+
arg.cast_to(Reg::i32());
20+
}
721
} else {
8-
ret.extend_integer_width_to(32);
22+
arg.extend_integer_width_to(32);
923
}
1024
}
1125

1226
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
13-
if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 {
14-
arg.make_indirect();
27+
// For argument type, the first 4*XLen parts of aggregate will be passed
28+
// in registers, and the rest will be passed in stack.
29+
// So we can coerce to integers directly and let backend handle it correctly.
30+
if arg.layout.is_aggregate() {
31+
let total = arg.layout.size;
32+
if total.bits() > 32 {
33+
arg.cast_to(Uniform { unit: Reg::i32(), total });
34+
} else {
35+
arg.cast_to(Reg::i32());
36+
}
1537
} else {
1638
arg.extend_integer_width_to(32);
1739
}

src/doc/rustc/src/platform-support/csky-unknown-linux-gnuabiv2.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ target | std | host | notes
1010
`csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian)
1111

1212
Reference:
13-
https://c-sky.github.io/
1413

15-
https://gitlab.com/c-sky/
14+
- [CSKY ABI Manual](https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1695027452256/T-HEAD_800_Series_ABI_Standards_Manual.pdf)
15+
- [csky-linux-gnuabiv2-toolchain](https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource/1356021/1619528643136/csky-linux-gnuabiv2-tools-x86_64-glibc-linux-4.9.56-20210423.tar.gz)
16+
- [csky-linux-gnuabiv2-qemu](https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1689324918932/xuantie-qemu-x86_64-Ubuntu-18.04-20230714-0202.tar.gz)
17+
18+
other links:
19+
20+
- https://c-sky.github.io/
21+
- https://gitlab.com/c-sky/
1622

1723
## Target maintainers
1824

0 commit comments

Comments
 (0)