]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_target/src/abi/call/nvptx64.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / compiler / rustc_target / src / abi / call / nvptx64.rs
CommitLineData
04454e1e
FG
1use crate::abi::call::{ArgAbi, FnAbi, PassMode, Reg, Size, Uniform};
2use crate::abi::{HasDataLayout, TyAbiInterface};
32a655c1 3
60c5eb7d 4fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
ff7c6d11
XL
5 if ret.layout.is_aggregate() && ret.layout.size.bits() > 64 {
6 ret.make_indirect();
32a655c1
SL
7 }
8}
9
60c5eb7d 10fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
ff7c6d11
XL
11 if arg.layout.is_aggregate() && arg.layout.size.bits() > 64 {
12 arg.make_indirect();
04454e1e
FG
13 }
14}
15
16fn classify_arg_kernel<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>)
17where
18 Ty: TyAbiInterface<'a, C> + Copy,
19 C: HasDataLayout,
20{
21 if matches!(arg.mode, PassMode::Pair(..)) && (arg.layout.is_adt() || arg.layout.is_tuple()) {
22 let align_bytes = arg.layout.align.abi.bytes();
23
24 let unit = match align_bytes {
25 1 => Reg::i8(),
26 2 => Reg::i16(),
27 4 => Reg::i32(),
28 8 => Reg::i64(),
29 16 => Reg::i128(),
30 _ => unreachable!("Align is given as power of 2 no larger than 16 bytes"),
31 };
32 arg.cast_to(Uniform { unit, total: Size::from_bytes(2 * align_bytes) });
32a655c1
SL
33 }
34}
35
60c5eb7d
XL
36pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
37 if !fn_abi.ret.is_ignore() {
38 classify_ret(&mut fn_abi.ret);
32a655c1
SL
39 }
40
f2b60f7d 41 for arg in fn_abi.args.iter_mut() {
32a655c1
SL
42 if arg.is_ignore() {
43 continue;
44 }
60c5eb7d 45 classify_arg(arg);
32a655c1
SL
46 }
47}
04454e1e
FG
48
49pub fn compute_ptx_kernel_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
50where
51 Ty: TyAbiInterface<'a, C> + Copy,
52 C: HasDataLayout,
53{
54 if !fn_abi.ret.layout.is_unit() && !fn_abi.ret.layout.is_never() {
55 panic!("Kernels should not return anything other than () or !");
56 }
57
f2b60f7d 58 for arg in fn_abi.args.iter_mut() {
04454e1e
FG
59 if arg.is_ignore() {
60 continue;
61 }
62 classify_arg_kernel(cx, arg);
63 }
64}