Skip to content

Commit

Permalink
Unrolled build for rust-lang#117154
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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`
  • Loading branch information
rust-timer authored Oct 25, 2023
2 parents cf226e9 + 32339f8 commit d7edb0e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
38 changes: 30 additions & 8 deletions compiler/rustc_target/src/abi/call/csky.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
// See https://github.com/llvm/llvm-project/blob/d85b94bf0080dcd780656c0f5e6342800720eba9/llvm/lib/Target/CSKY/CSKYCallingConv.td
use crate::abi::call::{ArgAbi, FnAbi};
// 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

fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if ret.layout.is_aggregate() || ret.layout.size.bits() > 64 {
ret.make_indirect();
use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform};

fn classify_ret<Ty>(arg: &mut ArgAbi<'_, Ty>) {
// For return type, aggregate which <= 2*XLen will be returned in registers.
// Otherwise, aggregate will be returned indirectly.
if arg.layout.is_aggregate() {
let total = arg.layout.size;
if total.bits() > 64 {
arg.make_indirect();
} else if total.bits() > 32 {
arg.cast_to(Uniform { unit: Reg::i32(), total });
} else {
arg.cast_to(Reg::i32());
}
} else {
ret.extend_integer_width_to(32);
arg.extend_integer_width_to(32);
}
}

fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
if arg.layout.is_aggregate() || arg.layout.size.bits() > 64 {
arg.make_indirect();
// For argument type, the first 4*XLen parts of aggregate will be passed
// in registers, and the rest will be passed in stack.
// So we can coerce to integers directly and let backend handle it correctly.
if arg.layout.is_aggregate() {
let total = arg.layout.size;
if total.bits() > 32 {
arg.cast_to(Uniform { unit: Reg::i32(), total });
} else {
arg.cast_to(Reg::i32());
}
} else {
arg.extend_integer_width_to(32);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ target | std | host | notes
`csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian)

Reference:
https://c-sky.github.io/

https://gitlab.com/c-sky/
- [CSKY ABI Manual](https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1695027452256/T-HEAD_800_Series_ABI_Standards_Manual.pdf)
- [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)
- [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)

other links:

- https://c-sky.github.io/
- https://gitlab.com/c-sky/

## Target maintainers

Expand Down

0 comments on commit d7edb0e

Please sign in to comment.