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::{FnType, ArgType, LayoutExt, Reg};
15 use context::CrateContext;
17 use rustc::ty::layout::{self, TyLayout};
19 fn classify_ret_ty(ret: &mut ArgType) {
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, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
28 layout: TyLayout<'tcx>) -> bool {
30 layout::Abi::Scalar(ref scalar) => {
32 layout::F32 | layout::F64 => true,
36 layout::Abi::Aggregate { .. } => {
37 if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
38 is_single_fp_element(ccx, layout.field(ccx, 0))
47 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
48 if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
49 arg.extend_integer_width_to(64);
53 if is_single_fp_element(ccx, 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, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
71 if !fty.ret.is_ignore() {
72 classify_ret_ty(&mut fty.ret);
75 for arg in &mut fty.args {
76 if arg.is_ignore() { continue; }
77 classify_arg_ty(ccx, arg);