1 // Copyright 2014-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: This needs an audit for correctness and completeness.
13 use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform};
14 use context::CrateContext;
16 fn is_homogenous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
18 arg.layout.homogenous_aggregate(ccx).and_then(|unit| {
19 let size = arg.layout.size(ccx);
21 // Ensure we have at most eight uniquely addressable members.
22 if size > unit.size.checked_mul(8, ccx).unwrap() {
26 let valid_unit = match unit.kind {
27 RegKind::Integer => false,
28 RegKind::Float => true,
29 RegKind::Vector => size.bits() == 128
43 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
44 if !ret.layout.is_aggregate() {
45 ret.extend_integer_width_to(64);
49 if let Some(uniform) = is_homogenous_aggregate(ccx, ret) {
50 ret.cast_to(ccx, uniform);
53 let size = ret.layout.size(ccx);
54 let bits = size.bits();
56 let unit = if bits <= 8 {
58 } else if bits <= 16 {
60 } else if bits <= 32 {
66 ret.cast_to(ccx, Uniform {
73 // don't return aggregates in registers
74 ret.make_indirect(ccx);
77 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
78 if !arg.layout.is_aggregate() {
79 arg.extend_integer_width_to(64);
83 if let Some(uniform) = is_homogenous_aggregate(ccx, arg) {
84 arg.cast_to(ccx, uniform);
88 let total = arg.layout.size(ccx);
89 arg.cast_to(ccx, Uniform {
95 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
96 if !fty.ret.is_ignore() {
97 classify_ret_ty(ccx, &mut fty.ret);
100 for arg in &mut fty.args {
101 if arg.is_ignore() { continue; }
102 classify_arg_ty(ccx, arg);