]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_target/src/abi/call/s390x.rs
Rollup merge of #107316 - ChrisDenton:snap, r=oli-obk
[rust.git] / compiler / rustc_target / src / abi / call / s390x.rs
1 // FIXME: The assumes we're using the non-vector ABI, i.e., compiling
2 // for a pre-z13 machine or using -mno-vx.
3
4 use crate::abi::call::{ArgAbi, FnAbi, Reg};
5 use crate::abi::{HasDataLayout, TyAbiInterface};
6
7 fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
8     if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
9         ret.extend_integer_width_to(64);
10     } else {
11         ret.make_indirect();
12     }
13 }
14
15 fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
16 where
17     Ty: TyAbiInterface<'a, C> + Copy,
18     C: HasDataLayout,
19 {
20     if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
21         arg.extend_integer_width_to(64);
22         return;
23     }
24
25     if arg.layout.is_single_fp_element(cx) {
26         match arg.layout.size.bytes() {
27             4 => arg.cast_to(Reg::f32()),
28             8 => arg.cast_to(Reg::f64()),
29             _ => arg.make_indirect(),
30         }
31     } else {
32         match arg.layout.size.bytes() {
33             1 => arg.cast_to(Reg::i8()),
34             2 => arg.cast_to(Reg::i16()),
35             4 => arg.cast_to(Reg::i32()),
36             8 => arg.cast_to(Reg::i64()),
37             _ => arg.make_indirect(),
38         }
39     }
40 }
41
42 pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
43 where
44     Ty: TyAbiInterface<'a, C> + Copy,
45     C: HasDataLayout,
46 {
47     if !fn_abi.ret.is_ignore() {
48         classify_ret(&mut fn_abi.ret);
49     }
50
51     for arg in fn_abi.args.iter_mut() {
52         if arg.is_ignore() {
53             continue;
54         }
55         classify_arg(cx, arg);
56     }
57 }