Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2c4ee54

Browse files
committed
Introduce gpu-kernel instead of amdgpu-kernel
gpu-kernel translates to ptx_kernel or amdgpu_kernel, depending on the target.
1 parent 6805183 commit 2c4ee54

File tree

31 files changed

+253
-215
lines changed

31 files changed

+253
-215
lines changed

compiler/rustc_abi/src/extern_abi/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ pub enum ExternAbi {
4545
PtxKernel,
4646
Msp430Interrupt,
4747
X86Interrupt,
48-
AmdgpuKernel,
48+
/// An entry-point function called by the GPU's host
49+
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
50+
GpuKernel,
4951
EfiApi,
5052
AvrInterrupt,
5153
AvrNonBlockingInterrupt,
@@ -123,7 +125,7 @@ const AbiDatas: &[AbiData] = &[
123125
AbiData { abi: Abi::PtxKernel, name: "ptx-kernel" },
124126
AbiData { abi: Abi::Msp430Interrupt, name: "msp430-interrupt" },
125127
AbiData { abi: Abi::X86Interrupt, name: "x86-interrupt" },
126-
AbiData { abi: Abi::AmdgpuKernel, name: "amdgpu-kernel" },
128+
AbiData { abi: Abi::GpuKernel, name: "gpu-kernel" },
127129
AbiData { abi: Abi::EfiApi, name: "efiapi" },
128130
AbiData { abi: Abi::AvrInterrupt, name: "avr-interrupt" },
129131
AbiData { abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt" },
@@ -237,9 +239,9 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> {
237239
feature: sym::abi_x86_interrupt,
238240
explain: "x86-interrupt ABI is experimental and subject to change",
239241
}),
240-
"amdgpu-kernel" => Err(AbiDisabled::Unstable {
241-
feature: sym::abi_amdgpu_kernel,
242-
explain: "amdgpu-kernel ABI is experimental and subject to change",
242+
"gpu-kernel" => Err(AbiDisabled::Unstable {
243+
feature: sym::abi_gpu_kernel,
244+
explain: "gpu-kernel ABI is experimental and subject to change",
243245
}),
244246
"avr-interrupt" | "avr-non-blocking-interrupt" => Err(AbiDisabled::Unstable {
245247
feature: sym::abi_avr_interrupt,
@@ -295,7 +297,7 @@ impl Abi {
295297
PtxKernel => 19,
296298
Msp430Interrupt => 20,
297299
X86Interrupt => 21,
298-
AmdgpuKernel => 22,
300+
GpuKernel => 22,
299301
EfiApi => 23,
300302
AvrInterrupt => 24,
301303
AvrNonBlockingInterrupt => 25,

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
6767

6868
Conv::Msp430Intr
6969
| Conv::PtxKernel
70-
| Conv::AmdgpuKernel
70+
| Conv::GpuKernel
7171
| Conv::AvrInterrupt
7272
| Conv::AvrNonBlockingInterrupt => {
7373
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target");

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Borrow;
12
use std::cmp;
23

34
use libc::c_uint;
@@ -312,7 +313,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
312313
pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
313314
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
314315
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
315-
fn llvm_cconv(&self) -> llvm::CallConv;
316+
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv;
316317

317318
/// Apply attributes to a function declaration/definition.
318319
fn apply_attrs_llfn(
@@ -404,8 +405,8 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
404405
cx.type_ptr_ext(cx.data_layout().instruction_address_space)
405406
}
406407

407-
fn llvm_cconv(&self) -> llvm::CallConv {
408-
self.conv.into()
408+
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv {
409+
llvm::CallConv::from_conv(self.conv, cx.tcx.sess.target.arch.borrow())
409410
}
410411

411412
fn apply_attrs_llfn(
@@ -617,7 +618,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
617618
}
618619
}
619620

620-
let cconv = self.llvm_cconv();
621+
let cconv = self.llvm_cconv(&bx.cx);
621622
if cconv != llvm::CCallConv {
622623
llvm::SetInstructionCallConv(callsite, cconv);
623624
}
@@ -655,8 +656,8 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
655656
}
656657
}
657658

658-
impl From<Conv> for llvm::CallConv {
659-
fn from(conv: Conv) -> Self {
659+
impl llvm::CallConv {
660+
pub fn from_conv(conv: Conv, arch: &str) -> Self {
660661
match conv {
661662
Conv::C
662663
| Conv::Rust
@@ -666,7 +667,15 @@ impl From<Conv> for llvm::CallConv {
666667
Conv::Cold => llvm::ColdCallConv,
667668
Conv::PreserveMost => llvm::PreserveMost,
668669
Conv::PreserveAll => llvm::PreserveAll,
669-
Conv::AmdgpuKernel => llvm::AmdgpuKernel,
670+
Conv::GpuKernel => {
671+
if arch == "amdgpu" {
672+
llvm::AmdgpuKernel
673+
} else if arch == "nvptx64" {
674+
llvm::PtxKernel
675+
} else {
676+
panic!("Architecture {arch} does not support GpuKernel calling convention");
677+
}
678+
}
670679
Conv::AvrInterrupt => llvm::AvrInterrupt,
671680
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
672681
Conv::ArmAapcs => llvm::ArmAapcsCallConv,

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,10 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
741741
if self.get_declared_value(entry_name).is_none() {
742742
Some(self.declare_entry_fn(
743743
entry_name,
744-
self.sess().target.entry_abi.into(),
744+
llvm::CallConv::from_conv(
745+
self.sess().target.entry_abi,
746+
self.sess().target.arch.borrow(),
747+
),
745748
llvm::UnnamedAddr::Global,
746749
fn_type,
747750
))

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
125125
let llfn = declare_raw_fn(
126126
self,
127127
name,
128-
fn_abi.llvm_cconv(),
128+
fn_abi.llvm_cconv(self),
129129
llvm::UnnamedAddr::Global,
130130
llvm::Visibility::Default,
131131
fn_abi.llvm_type(self),

compiler/rustc_feature/src/removed.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ declare_features! (
3939
// (But not all features below do this properly; many indicate the
4040
// version they got originally added in.)
4141

42+
/// Allows using the `amdgpu-kernel` ABI.
43+
(removed, abi_amdgpu_kernel, "1.77.0", Some(51575), None),
4244
(removed, advanced_slice_patterns, "1.0.0", Some(62254),
4345
Some("merged into `#![feature(slice_patterns)]`")),
4446
(removed, allocator, "1.0.0", None, None),

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ declare_features! (
355355
// feature-group-start: actual feature gates
356356
// -------------------------------------------------------------------------
357357

358-
/// Allows `extern "amdgpu-kernel" fn()`.
359-
(unstable, abi_amdgpu_kernel, "CURRENT_RUSTC_VERSION", Some(135024)),
358+
/// Allows `extern "gpu-kernel" fn()`.
359+
(unstable, abi_gpu_kernel, "CURRENT_RUSTC_VERSION", Some(135467)),
360360
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
361361
(unstable, abi_avr_interrupt, "1.45.0", Some(69664)),
362362
/// Allows `extern "C-cmse-nonsecure-call" fn()`.

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
12401240
PtxKernel
12411241
| Msp430Interrupt
12421242
| X86Interrupt
1243-
| AmdgpuKernel
1243+
| GpuKernel
12441244
| EfiApi
12451245
| AvrInterrupt
12461246
| AvrNonBlockingInterrupt

compiler/rustc_smir/src/rustc_internal/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl RustcInternal for Abi {
472472
Abi::PtxKernel => rustc_abi::ExternAbi::PtxKernel,
473473
Abi::Msp430Interrupt => rustc_abi::ExternAbi::Msp430Interrupt,
474474
Abi::X86Interrupt => rustc_abi::ExternAbi::X86Interrupt,
475-
Abi::AmdgpuKernel => rustc_abi::ExternAbi::AmdgpuKernel,
475+
Abi::GpuKernel => rustc_abi::ExternAbi::GpuKernel,
476476
Abi::EfiApi => rustc_abi::ExternAbi::EfiApi,
477477
Abi::AvrInterrupt => rustc_abi::ExternAbi::AvrInterrupt,
478478
Abi::AvrNonBlockingInterrupt => rustc_abi::ExternAbi::AvrNonBlockingInterrupt,

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'tcx> Stable<'tcx> for callconv::Conv {
113113
Conv::X86VectorCall => CallConvention::X86VectorCall,
114114
Conv::X86_64SysV => CallConvention::X86_64SysV,
115115
Conv::X86_64Win64 => CallConvention::X86_64Win64,
116-
Conv::AmdgpuKernel => CallConvention::AmdgpuKernel,
116+
Conv::GpuKernel => CallConvention::GpuKernel,
117117
Conv::AvrInterrupt => CallConvention::AvrInterrupt,
118118
Conv::AvrNonBlockingInterrupt => CallConvention::AvrNonBlockingInterrupt,
119119
Conv::RiscvInterrupt { .. } => CallConvention::RiscvInterrupt,

0 commit comments

Comments
 (0)