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.
12 // Alignment of 128 bit types is not currently handled, this will
13 // need to be fixed when PowerPC vector support is added.
15 use abi::{FnType, ArgType, LayoutExt, Reg, RegKind, Uniform};
16 use context::CrateContext;
18 fn is_homogeneous_aggregate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>)
20 arg.layout.homogeneous_aggregate(ccx).and_then(|unit| {
21 let size = arg.layout.size(ccx);
23 // Ensure we have at most eight uniquely addressable members.
24 if size > unit.size.checked_mul(8, ccx).unwrap() {
28 let valid_unit = match unit.kind {
29 RegKind::Integer => false,
30 RegKind::Float => true,
31 RegKind::Vector => size.bits() == 128
45 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
46 if !ret.layout.is_aggregate() {
47 ret.extend_integer_width_to(64);
51 // The PowerPC64 big endian ABI doesn't return aggregates in registers
52 if ccx.sess().target.target.target_endian == "big" {
53 ret.make_indirect(ccx);
56 if let Some(uniform) = is_homogeneous_aggregate(ccx, ret) {
57 ret.cast_to(ccx, uniform);
60 let size = ret.layout.size(ccx);
61 let bits = size.bits();
63 let unit = if bits <= 8 {
65 } else if bits <= 16 {
67 } else if bits <= 32 {
73 ret.cast_to(ccx, Uniform {
80 ret.make_indirect(ccx);
83 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
84 if !arg.layout.is_aggregate() {
85 arg.extend_integer_width_to(64);
89 if let Some(uniform) = is_homogeneous_aggregate(ccx, arg) {
90 arg.cast_to(ccx, uniform);
94 let total = arg.layout.size(ccx);
95 arg.cast_to(ccx, Uniform {
101 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
102 if !fty.ret.is_ignore() {
103 classify_ret_ty(ccx, &mut fty.ret);
106 for arg in &mut fty.args {
107 if arg.is_ignore() { continue; }
108 classify_arg_ty(ccx, arg);