rustc_target/callconv/
amdgpu.rs1use rustc_abi::{
2 AddressSpace, BackendRepr, CanonAbi, HasDataLayout, Reg, RegKind, TyAbiInterface, TyAndLayout,
3};
4
5use crate::callconv::{ArgAbi, ComputeCallConv, Uniform};
6
7fn single_element_struct_to_reg<'a, Ty, C>(cx: &C, ty: TyAndLayout<'a, Ty>) -> Option<Uniform>
12where
13 Ty: TyAbiInterface<'a, C> + Copy,
14 C: HasDataLayout,
15{
16 if !ty.is_aggregate() {
{
::core::panicking::panic_fmt(format_args!("Only handles aggregate types"));
}
};assert!(ty.is_aggregate(), "Only handles aggregate types");
17 if ty.layout.fields.count() != 1 {
18 return None;
19 }
20 let field = ty.field(cx, 0);
21 match field.backend_repr {
22 BackendRepr::SimdScalableVector { .. } => {
::core::panicking::panic_fmt(format_args!("scalable vectors are unsupported"));
}panic!("scalable vectors are unsupported"),
23 BackendRepr::Scalar(_) => {
24 let size = field.layout.size.bytes();
26 if ty.layout.size.bytes() != size {
27 return None;
28 }
29
30 match size {
32 1 => Some(Uniform::new(Reg::i8(), field.layout.size)),
33 2 => Some(Uniform::new(Reg::i16(), field.layout.size)),
34 4 => Some(Uniform::new(Reg::i32(), field.layout.size)),
35 8 => Some(Uniform::new(Reg::i64(), field.layout.size)),
36 16 => Some(Uniform::new(Reg::i128(), field.layout.size)),
37 s => {
::core::panicking::panic_fmt(format_args!("Unhandled scalar of size {0} in amdgpu gpu-kernel ABI",
s));
}panic!("Unhandled scalar of size {s} in amdgpu gpu-kernel ABI"),
38 }
39 }
40 BackendRepr::SimdVector { element, .. } => {
41 let size = field.layout.size.bytes();
43 if ty.layout.size.bytes() != size {
44 return None;
45 }
46
47 let reg = Reg {
50 kind: RegKind::Vector { hint_vector_elem: element.primitive() },
51 size: field.layout.size,
52 };
53 Some(Uniform::new(reg, field.layout.size))
54 }
55 BackendRepr::Memory { .. } => single_element_struct_to_reg(cx, field),
56 BackendRepr::ScalarPair { .. } => None,
57 }
58}
59
60pub(crate) struct AmdGpuCallConv {
61 conv: CanonAbi,
62}
63
64impl<'a, Ty, C> ComputeCallConv<'a, Ty, C> for AmdGpuCallConv
65where
66 Ty: TyAbiInterface<'a, C> + Copy,
67 C: HasDataLayout,
68{
69 fn new(_cx: &C, conv: CanonAbi, _c_variadic: bool) -> Self {
70 Self { conv }
71 }
72
73 fn compute_ret_abi(&mut self, _cx: &C, _ret: &mut ArgAbi<'a, Ty>) {
74 }
76
77 fn compute_arg_abi(&mut self, cx: &C, arg: &mut ArgAbi<'a, Ty>, _is_vararg: bool) {
78 if self.conv == CanonAbi::GpuKernel {
81 if arg.layout.is_aggregate() {
82 if let Some(uniform) = single_element_struct_to_reg(cx, arg.layout) {
83 arg.cast_to(uniform);
85 } else {
86 arg.pass_amdgpu_kernel_arg(Some(AddressSpace::GPU_CONSTANT));
88 }
89 }
90 } else {
91 }
93 }
94}