]> git.proxmox.com Git - rustc.git/blob - src/librustc_target/abi/call/arm.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / librustc_target / abi / call / arm.rs
1 // Copyright 2012-2013 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 use abi::call::{Conv, FnType, ArgType, Reg, RegKind, Uniform};
12 use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
13 use spec::HasTargetSpec;
14
15 fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>)
16 -> Option<Uniform>
17 where Ty: TyLayoutMethods<'a, C> + Copy,
18 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
19 {
20 arg.layout.homogeneous_aggregate(cx).and_then(|unit| {
21 let size = arg.layout.size;
22
23 // Ensure we have at most four uniquely addressable members.
24 if size > unit.size.checked_mul(4, cx).unwrap() {
25 return None;
26 }
27
28 let valid_unit = match unit.kind {
29 RegKind::Integer => false,
30 RegKind::Float => true,
31 RegKind::Vector => size.bits() == 64 || size.bits() == 128
32 };
33
34 if valid_unit {
35 Some(Uniform {
36 unit,
37 total: size
38 })
39 } else {
40 None
41 }
42 })
43 }
44
45 fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>, vfp: bool)
46 where Ty: TyLayoutMethods<'a, C> + Copy,
47 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
48 {
49 if !ret.layout.is_aggregate() {
50 ret.extend_integer_width_to(32);
51 return;
52 }
53
54 if vfp {
55 if let Some(uniform) = is_homogeneous_aggregate(cx, ret) {
56 ret.cast_to(uniform);
57 return;
58 }
59 }
60
61 let size = ret.layout.size;
62 let bits = size.bits();
63 if bits <= 32 {
64 let unit = if bits <= 8 {
65 Reg::i8()
66 } else if bits <= 16 {
67 Reg::i16()
68 } else {
69 Reg::i32()
70 };
71 ret.cast_to(Uniform {
72 unit,
73 total: size
74 });
75 return;
76 }
77 ret.make_indirect();
78 }
79
80 fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, vfp: bool)
81 where Ty: TyLayoutMethods<'a, C> + Copy,
82 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
83 {
84 if !arg.layout.is_aggregate() {
85 arg.extend_integer_width_to(32);
86 return;
87 }
88
89 if vfp {
90 if let Some(uniform) = is_homogeneous_aggregate(cx, arg) {
91 arg.cast_to(uniform);
92 return;
93 }
94 }
95
96 let align = arg.layout.align.abi();
97 let total = arg.layout.size;
98 arg.cast_to(Uniform {
99 unit: if align <= 4 { Reg::i32() } else { Reg::i64() },
100 total
101 });
102 }
103
104 pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>)
105 where Ty: TyLayoutMethods<'a, C> + Copy,
106 C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout + HasTargetSpec
107 {
108 // If this is a target with a hard-float ABI, and the function is not explicitly
109 // `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates.
110 let vfp = cx.target_spec().llvm_target.ends_with("hf")
111 && fty.conv != Conv::ArmAapcs
112 && !fty.variadic;
113
114 if !fty.ret.is_ignore() {
115 classify_ret_ty(cx, &mut fty.ret, vfp);
116 }
117
118 for arg in &mut fty.args {
119 if arg.is_ignore() { continue; }
120 classify_arg_ty(cx, arg, vfp);
121 }
122 }