]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/abi/call/s390x.rs
Various minor/cosmetic improvements to code
[rust.git] / src / librustc_target / abi / call / s390x.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // FIXME: The assumes we're using the non-vector ABI, i.e., compiling
12 // for a pre-z13 machine or using -mno-vx.
13
14 use abi::call::{FnType, ArgType, Reg};
15 use abi::{self, HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
16
17 fn classify_ret_ty<'a, Ty, C>(ret: &mut ArgType<Ty>)
18     where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> + HasDataLayout
19 {
20     if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
21         ret.extend_integer_width_to(64);
22     } else {
23         ret.make_indirect();
24     }
25 }
26
27 fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>) -> bool
28     where Ty: TyLayoutMethods<'a, C>,
29           C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
30 {
31     match layout.abi {
32         abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
33         abi::Abi::Aggregate { .. } => {
34             if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
35                 is_single_fp_element(cx, layout.field(cx, 0))
36             } else {
37                 false
38             }
39         }
40         _ => false
41     }
42 }
43
44 fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>)
45     where Ty: TyLayoutMethods<'a, C> + Copy,
46           C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
47 {
48     if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
49         arg.extend_integer_width_to(64);
50         return;
51     }
52
53     if is_single_fp_element(cx, arg.layout) {
54         match arg.layout.size.bytes() {
55             4 => arg.cast_to(Reg::f32()),
56             8 => arg.cast_to(Reg::f64()),
57             _ => arg.make_indirect()
58         }
59     } else {
60         match arg.layout.size.bytes() {
61             1 => arg.cast_to(Reg::i8()),
62             2 => arg.cast_to(Reg::i16()),
63             4 => arg.cast_to(Reg::i32()),
64             8 => arg.cast_to(Reg::i64()),
65             _ => arg.make_indirect()
66         }
67     }
68 }
69
70 pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>)
71     where Ty: TyLayoutMethods<'a, C> + Copy,
72           C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
73 {
74     if !fty.ret.is_ignore() {
75         classify_ret_ty(&mut fty.ret);
76     }
77
78     for arg in &mut fty.args {
79         if arg.is_ignore() { continue; }
80         classify_arg_ty(cx, arg);
81     }
82 }