Skip to main content

rustc_target/callconv/
s390x.rs

1// Reference: ELF Application Binary Interface s390x Supplement
2// https://github.com/IBM/s390x-abi
3
4use rustc_abi::{BackendRepr, HasDataLayout, TyAbiInterface};
5
6use crate::callconv::{ArgAbi, FnAbi, Reg};
7use crate::spec::{Env, HasTargetSpec, Os};
8
9fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
10    let size = ret.layout.size;
11    if size.bits() <= 128 && #[allow(non_exhaustive_omitted_patterns)] match ret.layout.backend_repr {
    BackendRepr::SimdVector { .. } => true,
    _ => false,
}matches!(ret.layout.backend_repr, BackendRepr::SimdVector { .. }) {
12        return;
13    }
14    if !ret.layout.is_aggregate() && size.bits() <= 64 {
15        ret.extend_integer_width_to(64);
16    } else {
17        ret.make_indirect();
18    }
19}
20
21fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
22where
23    Ty: TyAbiInterface<'a, C> + Copy,
24    C: HasDataLayout + HasTargetSpec,
25{
26    if !arg.layout.is_sized() {
27        // Not touching this...
28        return;
29    }
30    if arg.is_ignore() {
31        // s390x-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs.
32        if cx.target_spec().os == Os::Linux
33            && #[allow(non_exhaustive_omitted_patterns)] match cx.target_spec().env {
    Env::Gnu | Env::Musl | Env::Uclibc => true,
    _ => false,
}matches!(cx.target_spec().env, Env::Gnu | Env::Musl | Env::Uclibc)
34            && arg.layout.is_zst()
35        {
36            arg.make_indirect_from_ignore();
37        }
38        return;
39    }
40    if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
41        arg.make_indirect();
42        return;
43    }
44
45    if arg.layout.is_complex_number(cx) {
46        arg.make_indirect();
47        return;
48    }
49
50    let size = arg.layout.size;
51    if size.bits() <= 128 {
52        if let BackendRepr::SimdVector { .. } = arg.layout.backend_repr {
53            // pass non-wrapped vector types using `PassMode::Direct`
54            return;
55        }
56
57        if arg.layout.is_single_vector_element(cx, size) {
58            // pass non-transparent wrappers around a vector as `PassMode::Cast`
59            arg.cast_to(Reg::opaque_vector(size));
60            return;
61        }
62    }
63    if !arg.layout.is_aggregate() && size.bits() <= 64 {
64        arg.extend_integer_width_to(64);
65        return;
66    }
67
68    if arg.layout.is_single_fp_element(cx) {
69        match size.bytes() {
70            4 => arg.cast_to(Reg::f32()),
71            8 => arg.cast_to(Reg::f64()),
72            _ => arg.make_indirect(),
73        }
74    } else {
75        match size.bytes() {
76            1 => arg.cast_to(Reg::i8()),
77            2 => arg.cast_to(Reg::i16()),
78            4 => arg.cast_to(Reg::i32()),
79            8 => arg.cast_to(Reg::i64()),
80            _ => arg.make_indirect(),
81        }
82    }
83}
84
85pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
86where
87    Ty: TyAbiInterface<'a, C> + Copy,
88    C: HasDataLayout + HasTargetSpec,
89{
90    if !fn_abi.ret.is_ignore() {
91        classify_ret(&mut fn_abi.ret);
92    }
93
94    for arg in fn_abi.args.iter_mut() {
95        classify_arg(cx, arg);
96    }
97}