rustc_target/callconv/
csky.rs

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
6
7use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform};
8
9fn classify_ret<Ty>(arg: &mut ArgAbi<'_, Ty>) {
10    if !arg.layout.is_sized() {
11        // Not touching this...
12        return;
13    }
14    // For return type, aggregate which <= 2*XLen will be returned in registers.
15    // Otherwise, aggregate will be returned indirectly.
16    if arg.layout.is_aggregate() {
17        let total = arg.layout.size;
18        if total.bits() > 64 {
19            arg.make_indirect();
20        } else if total.bits() > 32 {
21            arg.cast_to(Uniform::new(Reg::i32(), total));
22        } else {
23            arg.cast_to(Reg::i32());
24        }
25    } else {
26        arg.extend_integer_width_to(32);
27    }
28}
29
30fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
31    if !arg.layout.is_sized() {
32        // Not touching this...
33        return;
34    }
35    // For argument type, the first 4*XLen parts of aggregate will be passed
36    // in registers, and the rest will be passed in stack.
37    // So we can coerce to integers directly and let backend handle it correctly.
38    if arg.layout.is_aggregate() {
39        let total = arg.layout.size;
40        if total.bits() > 32 {
41            arg.cast_to(Uniform::new(Reg::i32(), total));
42        } else {
43            arg.cast_to(Reg::i32());
44        }
45    } else {
46        arg.extend_integer_width_to(32);
47    }
48}
49
50pub(crate) fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
51    if !fn_abi.ret.is_ignore() {
52        classify_ret(&mut fn_abi.ret);
53    }
54
55    for arg in fn_abi.args.iter_mut() {
56        if arg.is_ignore() {
57            continue;
58        }
59        classify_arg(arg);
60    }
61}