1- use std:: borrow:: Borrow ;
21use std:: cmp;
32
43use libc:: c_uint;
@@ -13,7 +12,7 @@ use rustc_codegen_ssa::traits::*;
1312use rustc_middle:: ty:: Ty ;
1413use rustc_middle:: ty:: layout:: LayoutOf ;
1514use rustc_middle:: { bug, ty} ;
16- use rustc_session:: config;
15+ use rustc_session:: { Session , config} ;
1716use rustc_target:: callconv:: {
1817 ArgAbi , ArgAttribute , ArgAttributes , ArgExtension , CastTarget , FnAbi , PassMode ,
1918} ;
@@ -400,7 +399,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
400399 }
401400
402401 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 )
404403 }
405404
406405 fn apply_attrs_llfn (
@@ -663,43 +662,44 @@ impl AbiBuilderMethods for Builder<'_, '_, '_> {
663662 }
664663}
665664
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" ) ;
683683 }
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- } ,
703684 }
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+ } ,
704704 }
705705}
0 commit comments