Skip to content

Commit f38e850

Browse files
committed
Avoid using make_direct_deprecated() in extern "ptx-kernel"
This method will be removed in the future as it produces a broken ABI that depends on cg_llvm implementation details. After this PR wasm32-unknown-unknown is the only remaining user of make_direct_deprecated().
1 parent 8922d30 commit f38e850

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed

compiler/rustc_target/src/callconv/nvptx64.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{ArgAttribute, ArgAttributes, ArgExtension, CastTarget};
2-
use crate::abi::call::{ArgAbi, FnAbi, PassMode, Reg, Size, Uniform};
2+
use crate::abi::call::{ArgAbi, FnAbi, Reg, Size, Uniform};
33
use crate::abi::{HasDataLayout, TyAbiInterface};
44

55
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
@@ -53,22 +53,29 @@ where
5353
Ty: TyAbiInterface<'a, C> + Copy,
5454
C: HasDataLayout,
5555
{
56-
if matches!(arg.mode, PassMode::Pair(..)) && (arg.layout.is_adt() || arg.layout.is_tuple()) {
57-
let align_bytes = arg.layout.align.abi.bytes();
58-
59-
let unit = match align_bytes {
60-
1 => Reg::i8(),
61-
2 => Reg::i16(),
62-
4 => Reg::i32(),
63-
8 => Reg::i64(),
64-
16 => Reg::i128(),
65-
_ => unreachable!("Align is given as power of 2 no larger than 16 bytes"),
66-
};
67-
arg.cast_to(Uniform::new(unit, Size::from_bytes(2 * align_bytes)));
68-
} else {
69-
// FIXME: find a better way to do this. See https://github.com/rust-lang/rust/issues/117271.
70-
arg.make_direct_deprecated();
56+
match arg.mode {
57+
super::PassMode::Ignore | super::PassMode::Direct(_) => return,
58+
super::PassMode::Pair(_, _) => {}
59+
super::PassMode::Cast { .. } => unreachable!(),
60+
super::PassMode::Indirect { .. } => {}
7161
}
62+
63+
// FIXME only allow structs and wide pointers here
64+
// panic!(
65+
// "`extern \"ptx-kernel\"` doesn't allow passing types other than primitives and structs"
66+
// );
67+
68+
let align_bytes = arg.layout.align.abi.bytes();
69+
70+
let unit = match align_bytes {
71+
1 => Reg::i8(),
72+
2 => Reg::i16(),
73+
4 => Reg::i32(),
74+
8 => Reg::i64(),
75+
16 => Reg::i128(),
76+
_ => unreachable!("Align is given as power of 2 no larger than 16 bytes"),
77+
};
78+
arg.cast_to(Uniform::new(unit, arg.layout.size));
7279
}
7380

7481
pub(crate) fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {

compiler/rustc_ty_utils/src/abi.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -477,16 +477,11 @@ fn fn_abi_sanity_check<'tcx>(
477477
// have to allow it -- but we absolutely shouldn't let any more targets do
478478
// that. (Also see <https://github.com/rust-lang/rust/issues/115666>.)
479479
//
480-
// The unstable abi `PtxKernel` also uses Direct for now.
481-
// It needs to switch to something else before stabilization can happen.
482-
// (See issue: https://github.com/rust-lang/rust/issues/117271)
483-
//
484-
// And finally the unadjusted ABI is ill specified and uses Direct for all
485-
// args, but unfortunately we need it for calling certain LLVM intrinsics.
480+
// The unadjusted ABI also uses Direct for all args and is ill-specified,
481+
// but unfortunately we need it for calling certain LLVM intrinsics.
486482

487483
match spec_abi {
488484
ExternAbi::Unadjusted => {}
489-
ExternAbi::PtxKernel => {}
490485
ExternAbi::C { unwind: _ }
491486
if matches!(&*tcx.sess.target.arch, "wasm32" | "wasm64") => {}
492487
_ => {

tests/assembly/nvptx-kernel-abi/nvptx-kernel-args-abi-v7.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub unsafe extern "ptx-kernel" fn f_f32_arg(_a: f32) {}
166166
pub unsafe extern "ptx-kernel" fn f_f64_arg(_a: f64) {}
167167

168168
// CHECK: .visible .entry f_single_u8_arg(
169-
// CHECK: .param .align 1 .b8 f_single_u8_arg_param_0[1]
169+
// CHECK: .param .u8 f_single_u8_arg_param_0
170170
#[no_mangle]
171171
pub unsafe extern "ptx-kernel" fn f_single_u8_arg(_a: SingleU8) {}
172172

@@ -242,22 +242,6 @@ pub unsafe extern "ptx-kernel" fn f_float_array_arg(_a: [f32; 5]) {}
242242
//pub unsafe extern "ptx-kernel" fn f_u128_array_arg(_a: [u128; 5]) {}
243243

244244
// CHECK: .visible .entry f_u32_slice_arg(
245-
// CHECK: .param .u64 f_u32_slice_arg_param_0
246-
// CHECK: .param .u64 f_u32_slice_arg_param_1
245+
// CHECK: .param .align 8 .b8 f_u32_slice_arg_param_0[16]
247246
#[no_mangle]
248247
pub unsafe extern "ptx-kernel" fn f_u32_slice_arg(_a: &[u32]) {}
249-
250-
// CHECK: .visible .entry f_tuple_u8_u8_arg(
251-
// CHECK: .param .align 1 .b8 f_tuple_u8_u8_arg_param_0[2]
252-
#[no_mangle]
253-
pub unsafe extern "ptx-kernel" fn f_tuple_u8_u8_arg(_a: (u8, u8)) {}
254-
255-
// CHECK: .visible .entry f_tuple_u32_u32_arg(
256-
// CHECK: .param .align 4 .b8 f_tuple_u32_u32_arg_param_0[8]
257-
#[no_mangle]
258-
pub unsafe extern "ptx-kernel" fn f_tuple_u32_u32_arg(_a: (u32, u32)) {}
259-
260-
// CHECK: .visible .entry f_tuple_u8_u8_u32_arg(
261-
// CHECK: .param .align 4 .b8 f_tuple_u8_u8_u32_arg_param_0[8]
262-
#[no_mangle]
263-
pub unsafe extern "ptx-kernel" fn f_tuple_u8_u8_u32_arg(_a: (u8, u8, u32)) {}

0 commit comments

Comments
 (0)