Skip to content

Commit f8c54d2

Browse files
committed
Remove inherent methods from llvm::CallConv::from_conv
1 parent 3831b60 commit f8c54d2

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::borrow::Borrow;
21
use std::cmp;
32

43
use libc::c_uint;
@@ -13,7 +12,7 @@ use rustc_codegen_ssa::traits::*;
1312
use rustc_middle::ty::Ty;
1413
use rustc_middle::ty::layout::LayoutOf;
1514
use rustc_middle::{bug, ty};
16-
use rustc_session::config;
15+
use rustc_session::{Session, config};
1716
use 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
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_symbol_mangling::mangle_internal_symbol;
3131
use rustc_target::spec::{HasTargetSpec, RelocModel, SmallDataThresholdSupport, Target, TlsModel};
3232
use smallvec::SmallVec;
3333

34+
use crate::abi::to_llvm_calling_convention;
3435
use crate::back::write::to_llvm_code_model;
3536
use crate::callee::get_fn;
3637
use crate::debuginfo::metadata::apply_vcall_visibility_metadata;
@@ -901,10 +902,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
901902
if self.get_declared_value(entry_name).is_none() {
902903
let llfn = self.declare_entry_fn(
903904
entry_name,
904-
llvm::CallConv::from_conv(
905-
self.sess().target.entry_abi,
906-
self.sess().target.arch.borrow(),
907-
),
905+
to_llvm_calling_convention(self.sess(), self.sess().target.entry_abi),
908906
llvm::UnnamedAddr::Global,
909907
fn_type,
910908
);

0 commit comments

Comments
 (0)