1+ use std:: borrow:: Borrow ;
12use std:: cmp;
23
34use libc:: c_uint;
@@ -312,7 +313,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
312313pub ( 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,6 +667,15 @@ impl From<Conv> for llvm::CallConv {
666667 Conv :: Cold => llvm:: ColdCallConv ,
667668 Conv :: PreserveMost => llvm:: PreserveMost ,
668669 Conv :: PreserveAll => llvm:: PreserveAll ,
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+ }
669679 Conv :: AvrInterrupt => llvm:: AvrInterrupt ,
670680 Conv :: AvrNonBlockingInterrupt => llvm:: AvrNonBlockingInterrupt ,
671681 Conv :: ArmAapcs => llvm:: ArmAapcsCallConv ,
0 commit comments