rustc_target/callconv/
mips.rs1use rustc_abi::{
2 CanonAbi, Float, HasDataLayout, Integer, Numeric, Reg, RegKind, Size, TyAbiInterface,
3};
4use rustc_span::bug;
5
6use crate::callconv::{ArgAbi, CastTarget, ComputeCallConv, Uniform};
7
8fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, offset: &mut Size)
9where
10 Ty: TyAbiInterface<'a, C> + Copy,
11 C: HasDataLayout,
12{
13 let dl = cx.data_layout();
14 let size = ret.layout.size;
15
16 let is_supported_complex_component = |numeric| match numeric {
18 Numeric::Int(Integer::I8 | Integer::I16 | Integer::I32 | Integer::I64, _) => true,
19 Numeric::Int(Integer::I128, _) => false,
20 Numeric::Float(Float::F32 | Float::F64) => true,
21 Numeric::Float(Float::F16 | Float::F128) => false,
22 Numeric::Float(Float::F16B | Float::X87F80 | Float::PpcF128) => ::rustc_span::macros::bug_impl(None, format_args!("unsupported on mips"),
Location::caller())bug!("unsupported on mips"),
23 };
24
25 if let Some(component) = ret.layout.complex_number(cx)
26 && is_supported_complex_component(component)
27 {
28 match component {
29 Numeric::Int(Integer::I8 | Integer::I16, _) => {
30 ret.cast_to(Reg { kind: RegKind::Integer, size });
32 }
33 _ => {
34 let reg = Reg { kind: component.reg_kind(), size: component.size() };
35 ret.cast_to(CastTarget::from(Uniform::new(reg, size)));
36 }
37 }
38 } else if ret.layout.is_aggregate() {
39 ret.make_indirect();
40 *offset += dl.pointer_size();
41 } else {
42 ret.extend_integer_width_to(32);
43 }
44}
45
46fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, offset: &mut Size)
47where
48 Ty: TyAbiInterface<'a, C> + Copy,
49 C: HasDataLayout,
50{
51 if !arg.layout.is_sized() {
52 return;
55 }
56 let dl = cx.data_layout();
57 let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
58
59 if arg.layout.pass_indirectly_in_non_rustic_abis(cx) {
60 arg.make_indirect();
61 *offset = offset.align_to(align) + dl.pointer_size().align_to(align);
62 return;
63 }
64
65 let size = arg.layout.size;
66 if arg.layout.is_aggregate() {
67 let pad_i32 = u8::from(!offset.is_aligned(align));
68 arg.cast_to_and_pad_i32(Uniform::new(Reg::i32(), size), pad_i32);
69 } else {
70 arg.extend_integer_width_to(32);
71 }
72
73 *offset = offset.align_to(align) + size.align_to(align);
74}
75
76pub(crate) struct MipsCallConv {
77 offset: Size,
78}
79
80impl<'a, Ty, C> ComputeCallConv<'a, Ty, C> for MipsCallConv
81where
82 Ty: TyAbiInterface<'a, C> + Copy,
83 C: HasDataLayout,
84{
85 fn new(_cx: &C, _conv: CanonAbi, _c_variadic: bool) -> Self {
86 Self { offset: Size::ZERO }
87 }
88
89 fn compute_ret_abi(&mut self, cx: &C, ret: &mut ArgAbi<'a, Ty>) {
90 classify_ret(cx, ret, &mut self.offset);
91 }
92
93 fn compute_arg_abi(&mut self, cx: &C, arg: &mut ArgAbi<'a, Ty>, _is_vararg: bool) {
94 classify_arg(cx, arg, &mut self.offset);
95 }
96}