Auto merge of #135047 - Flakebi:amdgpu-kernel-cc, r=workingjubilee
Add gpu-kernel calling convention
The amdgpu-kernel calling convention was reverted in commit f6b21e90d1
(#120495 and https://github.com/rust-lang/rust-analyzer/pull/16463) due to inactivity in the amdgpu target.
Introduce a `gpu-kernel` calling convention that translates to `ptx_kernel` or `amdgpu_kernel`, depending on the target that rust compiles for.
Tracking issue: #135467
amdgpu target tracking issue: #135024
This commit is contained in:
commit
0c2c096e1a
29 changed files with 435 additions and 175 deletions
|
@ -1,3 +1,4 @@
|
|||
use std::borrow::Borrow;
|
||||
use std::cmp;
|
||||
|
||||
use libc::c_uint;
|
||||
|
@ -312,7 +313,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
|
||||
fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
|
||||
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
|
||||
fn llvm_cconv(&self) -> llvm::CallConv;
|
||||
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv;
|
||||
|
||||
/// Apply attributes to a function declaration/definition.
|
||||
fn apply_attrs_llfn(
|
||||
|
@ -404,8 +405,8 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
|
|||
cx.type_ptr_ext(cx.data_layout().instruction_address_space)
|
||||
}
|
||||
|
||||
fn llvm_cconv(&self) -> llvm::CallConv {
|
||||
self.conv.into()
|
||||
fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv {
|
||||
llvm::CallConv::from_conv(self.conv, cx.tcx.sess.target.arch.borrow())
|
||||
}
|
||||
|
||||
fn apply_attrs_llfn(
|
||||
|
@ -617,7 +618,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
|
|||
}
|
||||
}
|
||||
|
||||
let cconv = self.llvm_cconv();
|
||||
let cconv = self.llvm_cconv(&bx.cx);
|
||||
if cconv != llvm::CCallConv {
|
||||
llvm::SetInstructionCallConv(callsite, cconv);
|
||||
}
|
||||
|
@ -655,8 +656,8 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Conv> for llvm::CallConv {
|
||||
fn from(conv: Conv) -> Self {
|
||||
impl llvm::CallConv {
|
||||
pub fn from_conv(conv: Conv, arch: &str) -> Self {
|
||||
match conv {
|
||||
Conv::C
|
||||
| Conv::Rust
|
||||
|
@ -666,6 +667,15 @@ impl From<Conv> for llvm::CallConv {
|
|||
Conv::Cold => llvm::ColdCallConv,
|
||||
Conv::PreserveMost => llvm::PreserveMost,
|
||||
Conv::PreserveAll => llvm::PreserveAll,
|
||||
Conv::GpuKernel => {
|
||||
if arch == "amdgpu" {
|
||||
llvm::AmdgpuKernel
|
||||
} else if arch == "nvptx64" {
|
||||
llvm::PtxKernel
|
||||
} else {
|
||||
panic!("Architecture {arch} does not support GpuKernel calling convention");
|
||||
}
|
||||
}
|
||||
Conv::AvrInterrupt => llvm::AvrInterrupt,
|
||||
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
|
||||
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
|
||||
|
|
|
@ -741,7 +741,10 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
if self.get_declared_value(entry_name).is_none() {
|
||||
Some(self.declare_entry_fn(
|
||||
entry_name,
|
||||
self.sess().target.entry_abi.into(),
|
||||
llvm::CallConv::from_conv(
|
||||
self.sess().target.entry_abi,
|
||||
self.sess().target.arch.borrow(),
|
||||
),
|
||||
llvm::UnnamedAddr::Global,
|
||||
fn_type,
|
||||
))
|
||||
|
|
|
@ -125,7 +125,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
|
|||
let llfn = declare_raw_fn(
|
||||
self,
|
||||
name,
|
||||
fn_abi.llvm_cconv(),
|
||||
fn_abi.llvm_cconv(self),
|
||||
llvm::UnnamedAddr::Global,
|
||||
llvm::Visibility::Default,
|
||||
fn_abi.llvm_type(self),
|
||||
|
|
|
@ -120,6 +120,7 @@ pub enum CallConv {
|
|||
X86_Intr = 83,
|
||||
AvrNonBlockingInterrupt = 84,
|
||||
AvrInterrupt = 85,
|
||||
AmdgpuKernel = 91,
|
||||
}
|
||||
|
||||
/// Must match the layout of `LLVMLinkage`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue