Skip to content

Commit e0b07a8

Browse files
cg_llvm: convert to CanonAbi
1 parent 72ecde2 commit e0b07a8

File tree

1 file changed

+40
-29
lines changed
  • compiler/rustc_codegen_llvm/src

1 file changed

+40
-29
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::borrow::Borrow;
22
use std::cmp;
33

44
use libc::c_uint;
5-
use rustc_abi::{BackendRepr, HasDataLayout, Primitive, Reg, RegKind, Size};
5+
use rustc_abi::{
6+
ArmCall, BackendRepr, CanonAbi, HasDataLayout, InterruptKind, Primitive, Reg, RegKind, Size,
7+
X86Call,
8+
};
69
use rustc_codegen_ssa::MemFlags;
710
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
811
use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
@@ -12,7 +15,7 @@ use rustc_middle::ty::layout::LayoutOf;
1215
use rustc_middle::{bug, ty};
1316
use rustc_session::config;
1417
use rustc_target::callconv::{
15-
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, Conv, FnAbi, PassMode,
18+
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, CastTarget, FnAbi, PassMode,
1619
};
1720
use rustc_target::spec::SanitizerSet;
1821
use smallvec::SmallVec;
@@ -419,11 +422,17 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
419422
if !self.can_unwind {
420423
func_attrs.push(llvm::AttributeKind::NoUnwind.create_attr(cx.llcx));
421424
}
422-
if let Conv::RiscvInterrupt { kind } = self.conv {
423-
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", kind.as_str()));
424-
}
425-
if let Conv::CCmseNonSecureEntry = self.conv {
426-
func_attrs.push(llvm::CreateAttrString(cx.llcx, "cmse_nonsecure_entry"))
425+
match self.conv {
426+
CanonAbi::Interrupt(InterruptKind::RiscvMachine) => {
427+
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", "machine"))
428+
}
429+
CanonAbi::Interrupt(InterruptKind::RiscvSupervisor) => {
430+
func_attrs.push(llvm::CreateAttrStringValue(cx.llcx, "interrupt", "supervisor"))
431+
}
432+
CanonAbi::Arm(ArmCall::CCmseNonSecureEntry) => {
433+
func_attrs.push(llvm::CreateAttrString(cx.llcx, "cmse_nonsecure_entry"))
434+
}
435+
_ => (),
427436
}
428437
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &{ func_attrs });
429438

@@ -610,7 +619,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
610619
llvm::SetInstructionCallConv(callsite, cconv);
611620
}
612621

613-
if self.conv == Conv::CCmseNonSecureCall {
622+
if self.conv == CanonAbi::Arm(ArmCall::CCmseNonSecureCall) {
614623
// This will probably get ignored on all targets but those supporting the TrustZone-M
615624
// extension (thumbv8m targets).
616625
let cmse_nonsecure_call = llvm::CreateAttrString(bx.cx.llcx, "cmse_nonsecure_call");
@@ -646,17 +655,11 @@ impl AbiBuilderMethods for Builder<'_, '_, '_> {
646655
}
647656

648657
impl llvm::CallConv {
649-
pub(crate) fn from_conv(conv: Conv, arch: &str) -> Self {
658+
pub(crate) fn from_conv(conv: CanonAbi, arch: &str) -> Self {
650659
match conv {
651-
Conv::C
652-
| Conv::Rust
653-
| Conv::CCmseNonSecureCall
654-
| Conv::CCmseNonSecureEntry
655-
| Conv::RiscvInterrupt { .. } => llvm::CCallConv,
656-
Conv::Cold => llvm::ColdCallConv,
657-
Conv::PreserveMost => llvm::PreserveMost,
658-
Conv::PreserveAll => llvm::PreserveAll,
659-
Conv::GpuKernel => {
660+
CanonAbi::C | CanonAbi::Rust => llvm::CCallConv,
661+
CanonAbi::RustCold => llvm::PreserveMost,
662+
CanonAbi::GpuKernel => {
660663
if arch == "amdgpu" {
661664
llvm::AmdgpuKernel
662665
} else if arch == "nvptx64" {
@@ -665,17 +668,25 @@ impl llvm::CallConv {
665668
panic!("Architecture {arch} does not support GpuKernel calling convention");
666669
}
667670
}
668-
Conv::AvrInterrupt => llvm::AvrInterrupt,
669-
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
670-
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
671-
Conv::Msp430Intr => llvm::Msp430Intr,
672-
Conv::X86Fastcall => llvm::X86FastcallCallConv,
673-
Conv::X86Intr => llvm::X86_Intr,
674-
Conv::X86Stdcall => llvm::X86StdcallCallConv,
675-
Conv::X86ThisCall => llvm::X86_ThisCall,
676-
Conv::X86VectorCall => llvm::X86_VectorCall,
677-
Conv::X86_64SysV => llvm::X86_64_SysV,
678-
Conv::X86_64Win64 => llvm::X86_64_Win64,
671+
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
672+
InterruptKind::Avr => llvm::AvrInterrupt,
673+
InterruptKind::AvrNonBlocking => llvm::AvrNonBlockingInterrupt,
674+
InterruptKind::Msp430 => llvm::Msp430Intr,
675+
InterruptKind::RiscvMachine | InterruptKind::RiscvSupervisor => llvm::CCallConv,
676+
InterruptKind::X86 => llvm::X86_Intr,
677+
},
678+
CanonAbi::Arm(arm_call) => match arm_call {
679+
ArmCall::Aapcs => llvm::ArmAapcsCallConv,
680+
ArmCall::CCmseNonSecureCall | ArmCall::CCmseNonSecureEntry => llvm::CCallConv,
681+
},
682+
CanonAbi::X86(x86_call) => match x86_call {
683+
X86Call::Fastcall => llvm::X86FastcallCallConv,
684+
X86Call::Stdcall => llvm::X86StdcallCallConv,
685+
X86Call::SysV64 => llvm::X86_64_SysV,
686+
X86Call::Thiscall => llvm::X86_ThisCall,
687+
X86Call::Vectorcall => llvm::X86_VectorCall,
688+
X86Call::Win64 => llvm::X86_64_Win64,
689+
},
679690
}
680691
}
681692
}

0 commit comments

Comments
 (0)