1
- use std:: borrow:: Borrow ;
2
1
use std:: cmp;
3
2
4
3
use libc:: c_uint;
@@ -13,7 +12,7 @@ use rustc_codegen_ssa::traits::*;
13
12
use rustc_middle:: ty:: Ty ;
14
13
use rustc_middle:: ty:: layout:: LayoutOf ;
15
14
use rustc_middle:: { bug, ty} ;
16
- use rustc_session:: config;
15
+ use rustc_session:: { Session , config} ;
17
16
use rustc_target:: callconv:: {
18
17
ArgAbi , ArgAttribute , ArgAttributes , ArgExtension , CastTarget , FnAbi , PassMode ,
19
18
} ;
@@ -400,7 +399,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
400
399
}
401
400
402
401
fn llvm_cconv ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> llvm:: CallConv {
403
- llvm :: CallConv :: from_conv ( self . conv , cx. tcx . sess . target . arch . borrow ( ) )
402
+ to_llvm_calling_convention ( cx. tcx . sess , self . conv )
404
403
}
405
404
406
405
fn apply_attrs_llfn (
@@ -663,43 +662,44 @@ impl AbiBuilderMethods for Builder<'_, '_, '_> {
663
662
}
664
663
}
665
664
666
- impl llvm:: CallConv {
667
- pub ( crate ) fn from_conv ( conv : CanonAbi , arch : & str ) -> Self {
668
- match conv {
669
- CanonAbi :: C | CanonAbi :: Rust => llvm:: CCallConv ,
670
- CanonAbi :: RustCold => llvm:: PreserveMost ,
671
- // Functions with this calling convention can only be called from assembly, but it is
672
- // possible to declare an `extern "custom"` block, so the backend still needs a calling
673
- // convention for declaring foreign functions.
674
- CanonAbi :: Custom => llvm:: CCallConv ,
675
- CanonAbi :: GpuKernel => {
676
- if arch == "amdgpu" {
677
- llvm:: AmdgpuKernel
678
- } else if arch == "nvptx64" {
679
- llvm:: PtxKernel
680
- } else {
681
- panic ! ( "Architecture {arch} does not support GpuKernel calling convention" ) ;
682
- }
665
+ /// Determines the appropriate [`llvm::CallConv`] to use for a given function
666
+ /// ABI, for the current target.
667
+ pub ( crate ) fn to_llvm_calling_convention ( sess : & Session , abi : CanonAbi ) -> llvm:: CallConv {
668
+ match abi {
669
+ CanonAbi :: C | CanonAbi :: Rust => llvm:: CCallConv ,
670
+ CanonAbi :: RustCold => llvm:: PreserveMost ,
671
+ // Functions with this calling convention can only be called from assembly, but it is
672
+ // possible to declare an `extern "custom"` block, so the backend still needs a calling
673
+ // convention for declaring foreign functions.
674
+ CanonAbi :: Custom => llvm:: CCallConv ,
675
+ CanonAbi :: GpuKernel => {
676
+ let arch = sess. target . arch . as_ref ( ) ;
677
+ if arch == "amdgpu" {
678
+ llvm:: AmdgpuKernel
679
+ } else if arch == "nvptx64" {
680
+ llvm:: PtxKernel
681
+ } else {
682
+ panic ! ( "Architecture {arch} does not support GpuKernel calling convention" ) ;
683
683
}
684
- CanonAbi :: Interrupt ( interrupt_kind) => match interrupt_kind {
685
- InterruptKind :: Avr => llvm:: AvrInterrupt ,
686
- InterruptKind :: AvrNonBlocking => llvm:: AvrNonBlockingInterrupt ,
687
- InterruptKind :: Msp430 => llvm:: Msp430Intr ,
688
- InterruptKind :: RiscvMachine | InterruptKind :: RiscvSupervisor => llvm:: CCallConv ,
689
- InterruptKind :: X86 => llvm:: X86_Intr ,
690
- } ,
691
- CanonAbi :: Arm ( arm_call) => match arm_call {
692
- ArmCall :: Aapcs => llvm:: ArmAapcsCallConv ,
693
- ArmCall :: CCmseNonSecureCall | ArmCall :: CCmseNonSecureEntry => llvm:: CCallConv ,
694
- } ,
695
- CanonAbi :: X86 ( x86_call) => match x86_call {
696
- X86Call :: Fastcall => llvm:: X86FastcallCallConv ,
697
- X86Call :: Stdcall => llvm:: X86StdcallCallConv ,
698
- X86Call :: SysV64 => llvm:: X86_64_SysV ,
699
- X86Call :: Thiscall => llvm:: X86_ThisCall ,
700
- X86Call :: Vectorcall => llvm:: X86_VectorCall ,
701
- X86Call :: Win64 => llvm:: X86_64_Win64 ,
702
- } ,
703
684
}
685
+ CanonAbi :: Interrupt ( interrupt_kind) => match interrupt_kind {
686
+ InterruptKind :: Avr => llvm:: AvrInterrupt ,
687
+ InterruptKind :: AvrNonBlocking => llvm:: AvrNonBlockingInterrupt ,
688
+ InterruptKind :: Msp430 => llvm:: Msp430Intr ,
689
+ InterruptKind :: RiscvMachine | InterruptKind :: RiscvSupervisor => llvm:: CCallConv ,
690
+ InterruptKind :: X86 => llvm:: X86_Intr ,
691
+ } ,
692
+ CanonAbi :: Arm ( arm_call) => match arm_call {
693
+ ArmCall :: Aapcs => llvm:: ArmAapcsCallConv ,
694
+ ArmCall :: CCmseNonSecureCall | ArmCall :: CCmseNonSecureEntry => llvm:: CCallConv ,
695
+ } ,
696
+ CanonAbi :: X86 ( x86_call) => match x86_call {
697
+ X86Call :: Fastcall => llvm:: X86FastcallCallConv ,
698
+ X86Call :: Stdcall => llvm:: X86StdcallCallConv ,
699
+ X86Call :: SysV64 => llvm:: X86_64_SysV ,
700
+ X86Call :: Thiscall => llvm:: X86_ThisCall ,
701
+ X86Call :: Vectorcall => llvm:: X86_VectorCall ,
702
+ X86Call :: Win64 => llvm:: X86_64_Win64 ,
703
+ } ,
704
704
}
705
705
}
0 commit comments