rustc_target/callconv/
s390x.rs1use rustc_abi::{BackendRepr, HasDataLayout, TyAbiInterface};
5
6use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind};
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 && 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 return;
29 }
30 if arg.is_ignore() {
31 if cx.target_spec().os == Os::Linux
33 && 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 let size = arg.layout.size;
46 if size.bits() <= 128 {
47 if let BackendRepr::SimdVector { .. } = arg.layout.backend_repr {
48 return;
50 }
51
52 if arg.layout.is_single_vector_element(cx, size) {
53 arg.cast_to(Reg { kind: RegKind::Vector, size });
55 return;
56 }
57 }
58 if !arg.layout.is_aggregate() && size.bits() <= 64 {
59 arg.extend_integer_width_to(64);
60 return;
61 }
62
63 if arg.layout.is_single_fp_element(cx) {
64 match size.bytes() {
65 4 => arg.cast_to(Reg::f32()),
66 8 => arg.cast_to(Reg::f64()),
67 _ => arg.make_indirect(),
68 }
69 } else {
70 match size.bytes() {
71 1 => arg.cast_to(Reg::i8()),
72 2 => arg.cast_to(Reg::i16()),
73 4 => arg.cast_to(Reg::i32()),
74 8 => arg.cast_to(Reg::i64()),
75 _ => arg.make_indirect(),
76 }
77 }
78}
79
80pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
81where
82 Ty: TyAbiInterface<'a, C> + Copy,
83 C: HasDataLayout + HasTargetSpec,
84{
85 if !fn_abi.ret.is_ignore() {
86 classify_ret(&mut fn_abi.ret);
87 }
88
89 for arg in fn_abi.args.iter_mut() {
90 classify_arg(cx, arg);
91 }
92}