|
1 | | -use rustc_abi::TyAbiInterface; |
| 1 | +use rustc_abi::{HasDataLayout, TyAbiInterface}; |
2 | 2 |
|
3 | | -use crate::callconv::{ArgAbi, FnAbi}; |
| 3 | +use crate::callconv::{ArgAbi, FnAbi, Reg, Uniform}; |
4 | 4 |
|
5 | | -fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) { |
6 | | - if ret.layout.is_aggregate() && ret.layout.size.bits() > 64 { |
7 | | - ret.make_indirect(); |
8 | | - } else { |
| 5 | +fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>) |
| 6 | +where |
| 7 | + Ty: TyAbiInterface<'a, C> + Copy, |
| 8 | + C: HasDataLayout, |
| 9 | +{ |
| 10 | + if !ret.layout.is_sized() { |
| 11 | + return; |
| 12 | + } |
| 13 | + |
| 14 | + if !ret.layout.is_aggregate() { |
9 | 15 | ret.extend_integer_width_to(32); |
| 16 | + return; |
| 17 | + } |
| 18 | + |
| 19 | + // Per the Hexagon ABI: |
| 20 | + // - Aggregates up to 32 bits are returned in R0 |
| 21 | + // - Aggregates 33-64 bits are returned in R1:R0 |
| 22 | + // - Aggregates > 64 bits are returned indirectly via hidden first argument |
| 23 | + let size = ret.layout.size; |
| 24 | + let bits = size.bits(); |
| 25 | + if bits <= 32 { |
| 26 | + ret.cast_to(Uniform::new(Reg::i32(), size)); |
| 27 | + } else if bits <= 64 { |
| 28 | + ret.cast_to(Uniform::new(Reg::i64(), size)); |
| 29 | + } else { |
| 30 | + ret.make_indirect(); |
10 | 31 | } |
11 | 32 | } |
12 | 33 |
|
13 | 34 | fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) |
14 | 35 | where |
15 | 36 | Ty: TyAbiInterface<'a, C> + Copy, |
| 37 | + C: HasDataLayout, |
16 | 38 | { |
| 39 | + if !arg.layout.is_sized() { |
| 40 | + return; |
| 41 | + } |
17 | 42 | if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { |
18 | 43 | arg.make_indirect(); |
19 | 44 | return; |
20 | 45 | } |
21 | | - if arg.layout.is_aggregate() && arg.layout.size.bits() > 64 { |
22 | | - arg.make_indirect(); |
23 | | - } else { |
| 46 | + |
| 47 | + if !arg.layout.is_aggregate() { |
24 | 48 | arg.extend_integer_width_to(32); |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + // Per the Hexagon ABI: |
| 53 | + // - Aggregates up to 32 bits are passed in a single register |
| 54 | + // - Aggregates 33-64 bits are passed in a register pair |
| 55 | + // - Aggregates > 64 bits are passed on the stack |
| 56 | + let size = arg.layout.size; |
| 57 | + let bits = size.bits(); |
| 58 | + if bits <= 32 { |
| 59 | + arg.cast_to(Uniform::new(Reg::i32(), size)); |
| 60 | + } else if bits <= 64 { |
| 61 | + arg.cast_to(Uniform::new(Reg::i64(), size)); |
| 62 | + } else { |
| 63 | + arg.pass_by_stack_offset(None); |
25 | 64 | } |
26 | 65 | } |
27 | 66 |
|
28 | 67 | pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) |
29 | 68 | where |
30 | 69 | Ty: TyAbiInterface<'a, C> + Copy, |
| 70 | + C: HasDataLayout, |
31 | 71 | { |
32 | 72 | if !fn_abi.ret.is_ignore() { |
33 | | - classify_ret(&mut fn_abi.ret); |
| 73 | + classify_ret(cx, &mut fn_abi.ret); |
34 | 74 | } |
35 | 75 |
|
36 | 76 | for arg in fn_abi.args.iter_mut() { |
|
0 commit comments