rustc_target/callconv/
powerpc64.rs
1use rustc_abi::{Endian, HasDataLayout, TyAbiInterface};
6
7use crate::callconv::{Align, ArgAbi, FnAbi, Reg, RegKind, Uniform};
8use crate::spec::HasTargetSpec;
9
10#[derive(Debug, Clone, Copy, PartialEq)]
11enum ABI {
12 ELFv1, ELFv2, AIX, }
16use ABI::*;
17
18fn is_homogeneous_aggregate<'a, Ty, C>(
19 cx: &C,
20 arg: &mut ArgAbi<'a, Ty>,
21 abi: ABI,
22) -> Option<Uniform>
23where
24 Ty: TyAbiInterface<'a, C> + Copy,
25 C: HasDataLayout,
26{
27 arg.layout.homogeneous_aggregate(cx).ok().and_then(|ha| ha.unit()).and_then(|unit| {
28 if ((abi == ELFv1 || abi == AIX) && arg.layout.size > unit.size)
31 || arg.layout.size > unit.size.checked_mul(8, cx).unwrap()
32 {
33 return None;
34 }
35
36 let valid_unit = match unit.kind {
37 RegKind::Integer => false,
38 RegKind::Float => true,
39 RegKind::Vector => arg.layout.size.bits() == 128,
40 };
41
42 valid_unit.then_some(Uniform::consecutive(unit, arg.layout.size))
43 })
44}
45
46fn classify<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI, is_ret: bool)
47where
48 Ty: TyAbiInterface<'a, C> + Copy,
49 C: HasDataLayout,
50{
51 if arg.is_ignore() || !arg.layout.is_sized() {
52 return;
54 }
55 if !arg.layout.is_aggregate() {
56 arg.extend_integer_width_to(64);
57 return;
58 }
59
60 if !is_ret && abi == AIX {
65 arg.pass_by_stack_offset(Some(Align::from_bytes(8).unwrap()));
66 return;
67 }
68
69 if is_ret && (abi == ELFv1 || abi == AIX) {
71 arg.make_indirect();
72 return;
73 }
74
75 if let Some(uniform) = is_homogeneous_aggregate(cx, arg, abi) {
76 arg.cast_to(uniform);
77 return;
78 }
79
80 let size = arg.layout.size;
81 if is_ret && size.bits() > 128 {
82 arg.make_indirect();
84 } else if size.bits() <= 64 {
85 arg.cast_to(Reg { kind: RegKind::Integer, size })
88 } else {
89 let reg = if arg.layout.align.abi.bytes() > 8 { Reg::i128() } else { Reg::i64() };
93 arg.cast_to(Uniform::consecutive(
94 reg,
95 size.align_to(Align::from_bytes(reg.size.bytes()).unwrap()),
96 ))
97 };
98}
99
100pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
101where
102 Ty: TyAbiInterface<'a, C> + Copy,
103 C: HasDataLayout + HasTargetSpec,
104{
105 let abi = if cx.target_spec().env == "musl" || cx.target_spec().os == "freebsd" {
106 ELFv2
107 } else if cx.target_spec().os == "aix" {
108 AIX
109 } else {
110 match cx.data_layout().endian {
111 Endian::Big => ELFv1,
112 Endian::Little => ELFv2,
113 }
114 };
115
116 classify(cx, &mut fn_abi.ret, abi, true);
117
118 for arg in fn_abi.args.iter_mut() {
119 classify(cx, arg, abi, false);
120 }
121}