1
+ use std:: borrow:: Borrow ;
1
2
use std:: cmp;
2
3
3
4
use libc:: c_uint;
@@ -312,7 +313,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
312
313
pub ( crate ) trait FnAbiLlvmExt < ' ll , ' tcx > {
313
314
fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
314
315
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 ;
316
317
317
318
/// Apply attributes to a function declaration/definition.
318
319
fn apply_attrs_llfn (
@@ -404,8 +405,8 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
404
405
cx. type_ptr_ext ( cx. data_layout ( ) . instruction_address_space )
405
406
}
406
407
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 ( ) )
409
410
}
410
411
411
412
fn apply_attrs_llfn (
@@ -617,7 +618,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
617
618
}
618
619
}
619
620
620
- let cconv = self . llvm_cconv ( ) ;
621
+ let cconv = self . llvm_cconv ( & bx . cx ) ;
621
622
if cconv != llvm:: CCallConv {
622
623
llvm:: SetInstructionCallConv ( callsite, cconv) ;
623
624
}
@@ -655,8 +656,8 @@ impl<'tcx> AbiBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
655
656
}
656
657
}
657
658
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 {
660
661
match conv {
661
662
Conv :: C
662
663
| Conv :: Rust
@@ -666,6 +667,15 @@ impl From<Conv> for llvm::CallConv {
666
667
Conv :: Cold => llvm:: ColdCallConv ,
667
668
Conv :: PreserveMost => llvm:: PreserveMost ,
668
669
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
+ }
669
679
Conv :: AvrInterrupt => llvm:: AvrInterrupt ,
670
680
Conv :: AvrNonBlockingInterrupt => llvm:: AvrNonBlockingInterrupt ,
671
681
Conv :: ArmAapcs => llvm:: ArmAapcsCallConv ,
0 commit comments