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.
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.
11 // FIXME: The assumes we're using the non-vector ABI, i.e., compiling
12 // for a pre-z13 machine or using -mno-vx.
14 use abi::call::{FnType, ArgType, Reg};
15 use abi::{self, HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
17 fn classify_ret_ty<'a, Ty, C>(ret: &mut ArgType<Ty>)
18 where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> + HasDataLayout
20 if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
21 ret.extend_integer_width_to(64);
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
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))
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
48 if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
49 arg.extend_integer_width_to(64);
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()
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()
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
74 if !fty.ret.is_ignore() {
75 classify_ret_ty(&mut fty.ret);
78 for arg in &mut fty.args {
79 if arg.is_ignore() { continue; }
80 classify_arg_ty(cx, arg);