NVPTX: Avoid PassMode::Direct for C ABI

This commit is contained in:
Kjetil Kjeka 2024-05-31 22:45:27 +02:00
parent bf8fff783f
commit 14348d9519
3 changed files with 42 additions and 16 deletions

View File

@ -1,23 +1,54 @@
use crate::abi::call::{ArgAbi, FnAbi, PassMode, Reg, Size, Uniform}; use crate::abi::call::{ArgAbi, FnAbi, PassMode, Reg, Size, Uniform};
use crate::abi::{HasDataLayout, TyAbiInterface}; use crate::abi::{HasDataLayout, TyAbiInterface};
use super::{ArgAttribute, ArgAttributes, ArgExtension, CastTarget};
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) { fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
if ret.layout.is_aggregate() && ret.layout.size.bits() > 64 { if ret.layout.is_aggregate() && ret.layout.is_sized() {
ret.make_indirect(); classify_aggregate(ret)
} else { } else if ret.layout.size.bits() < 32 && ret.layout.is_sized() {
// FIXME: this is wrong! Need to decide which ABI we really want here. ret.extend_integer_width_to(32);
ret.make_direct_deprecated();
} }
} }
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) { fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
if arg.layout.is_aggregate() { if arg.layout.is_aggregate() && arg.layout.is_sized() {
arg.make_indirect_byval(None); classify_aggregate(arg)
} else if arg.layout.size.bits() < 32 { } else if arg.layout.size.bits() < 32 && arg.layout.is_sized() {
arg.extend_integer_width_to(32); arg.extend_integer_width_to(32);
} }
} }
/// the pass mode used for aggregates in arg and ret position
fn classify_aggregate<Ty>(arg: &mut ArgAbi<'_, Ty>) {
let align_bytes = arg.layout.align.abi.bytes();
let size = arg.layout.size;
let reg = match align_bytes {
1 => Reg::i8(),
2 => Reg::i16(),
4 => Reg::i32(),
8 => Reg::i64(),
16 => Reg::i128(),
_ => unreachable!("Align is given as power of 2 no larger than 16 bytes"),
};
if align_bytes == size.bytes() {
arg.cast_to(CastTarget {
prefix: [Some(reg), None, None, None, None, None, None, None],
rest: Uniform::new(Reg::i8(), Size::from_bytes(0)),
attrs: ArgAttributes {
regular: ArgAttribute::default(),
arg_ext: ArgExtension::None,
pointee_size: Size::ZERO,
pointee_align: None,
},
});
} else {
arg.cast_to(Uniform::new(reg, size));
}
}
fn classify_arg_kernel<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>) fn classify_arg_kernel<'a, Ty, C>(_cx: &C, arg: &mut ArgAbi<'a, Ty>)
where where
Ty: TyAbiInterface<'a, C> + Copy, Ty: TyAbiInterface<'a, C> + Copy,

View File

@ -1,7 +1,6 @@
//@ assembly-output: ptx-linker //@ assembly-output: ptx-linker
//@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc //@ compile-flags: --crate-type cdylib -C target-cpu=sm_86 -Z unstable-options -Clinker-flavor=llbc
//@ only-nvptx64 //@ only-nvptx64
//@ ignore-nvptx64
// The PTX ABI stability is tied to major versions of the PTX ISA // The PTX ABI stability is tied to major versions of the PTX ISA
// These tests assume major version 7 // These tests assume major version 7

View File

@ -55,13 +55,9 @@
//@ revisions: csky //@ revisions: csky
//@[csky] compile-flags: --target csky-unknown-linux-gnuabiv2 //@[csky] compile-flags: --target csky-unknown-linux-gnuabiv2
//@[csky] needs-llvm-components: csky //@[csky] needs-llvm-components: csky
//@ revisions: nvptx64
// FIXME: disabled on nvptx64 since the target ABI fails the sanity check //@[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
// see https://github.com/rust-lang/rust/issues/117480 //@[nvptx64] needs-llvm-components: nvptx
/* revisions: nvptx64
[nvptx64] compile-flags: --target nvptx64-nvidia-cuda
[nvptx64] needs-llvm-components: nvptx
*/
#![feature(rustc_attrs, unsized_fn_params, transparent_unions)] #![feature(rustc_attrs, unsized_fn_params, transparent_unions)]
#![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)] #![cfg_attr(not(host), feature(no_core, lang_items), no_std, no_core)]
#![allow(unused, improper_ctypes_definitions, internal_features)] #![allow(unused, improper_ctypes_definitions, internal_features)]