]> git.proxmox.com Git - rustc.git/blame - src/librustc_target/abi/call/s390x.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_target / abi / call / s390x.rs
CommitLineData
0731742a 1// FIXME: The assumes we're using the non-vector ABI, i.e., compiling
9e0c209e
SL
2// for a pre-z13 machine or using -mno-vx.
3
60c5eb7d 4use crate::abi::call::{FnAbi, ArgAbi, Reg};
9fa01778 5use crate::abi::{self, HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
9e0c209e 6
60c5eb7d 7fn classify_ret<'a, Ty, C>(ret: &mut ArgAbi<'_, Ty>)
83c7162d
XL
8 where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> + HasDataLayout
9{
ff7c6d11 10 if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
9e0c209e
SL
11 ret.extend_integer_width_to(64);
12 } else {
ff7c6d11 13 ret.make_indirect();
9e0c209e
SL
14 }
15}
16
a1dfa0c6 17fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>) -> bool
83c7162d
XL
18 where Ty: TyLayoutMethods<'a, C>,
19 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
20{
ff7c6d11 21 match layout.abi {
94b46f34 22 abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
83c7162d 23 abi::Abi::Aggregate { .. } => {
ff7c6d11 24 if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
2c00a5a8 25 is_single_fp_element(cx, layout.field(cx, 0))
cc61c64b
XL
26 } else {
27 false
9e0c209e
SL
28 }
29 }
cc61c64b 30 _ => false
9e0c209e 31 }
cc61c64b 32}
9e0c209e 33
60c5eb7d 34fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
83c7162d
XL
35 where Ty: TyLayoutMethods<'a, C> + Copy,
36 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
37{
ff7c6d11 38 if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
9e0c209e 39 arg.extend_integer_width_to(64);
cc61c64b 40 return;
9e0c209e 41 }
9e0c209e 42
2c00a5a8 43 if is_single_fp_element(cx, arg.layout) {
ff7c6d11
XL
44 match arg.layout.size.bytes() {
45 4 => arg.cast_to(Reg::f32()),
46 8 => arg.cast_to(Reg::f64()),
47 _ => arg.make_indirect()
cc61c64b
XL
48 }
49 } else {
ff7c6d11
XL
50 match arg.layout.size.bytes() {
51 1 => arg.cast_to(Reg::i8()),
52 2 => arg.cast_to(Reg::i16()),
53 4 => arg.cast_to(Reg::i32()),
54 8 => arg.cast_to(Reg::i64()),
55 _ => arg.make_indirect()
cc61c64b 56 }
9e0c209e
SL
57 }
58}
59
60c5eb7d 60pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
83c7162d
XL
61 where Ty: TyLayoutMethods<'a, C> + Copy,
62 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
63{
60c5eb7d
XL
64 if !fn_abi.ret.is_ignore() {
65 classify_ret(&mut fn_abi.ret);
9e0c209e
SL
66 }
67
60c5eb7d 68 for arg in &mut fn_abi.args {
9e0c209e 69 if arg.is_ignore() { continue; }
60c5eb7d 70 classify_arg(cx, arg);
9e0c209e
SL
71 }
72}