Skip to content

Commit 87fa1ea

Browse files
cg_gcc: convert to CanonAbi
1 parent 0d8959f commit 87fa1ea

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(feature = "master")]
22
use gccjit::FnAttribute;
33
use gccjit::{ToLValue, ToRValue, Type};
4-
use rustc_abi::{Reg, RegKind};
4+
use rustc_abi::{ArmCall, CanonAbi, InterruptKind, Reg, RegKind, X86Call};
55
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeCodegenMethods};
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::bug;
@@ -10,8 +10,6 @@ use rustc_middle::ty::layout::LayoutOf;
1010
#[cfg(feature = "master")]
1111
use rustc_session::config;
1212
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
13-
#[cfg(feature = "master")]
14-
use rustc_target::callconv::{Conv, RiscvInterruptKind};
1513

1614
use crate::builder::Builder;
1715
use crate::context::CodegenCx;
@@ -239,29 +237,16 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
239237
}
240238

241239
#[cfg(feature = "master")]
242-
pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<'gcc>> {
240+
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &str) -> Option<FnAttribute<'gcc>> {
243241
let attribute = match conv {
244-
Conv::C | Conv::Rust => return None,
245-
Conv::CCmseNonSecureCall => {
246-
if arch == "arm" {
247-
FnAttribute::ArmCmseNonsecureCall
248-
} else {
249-
return None;
250-
}
251-
}
252-
Conv::CCmseNonSecureEntry => {
253-
if arch == "arm" {
254-
FnAttribute::ArmCmseNonsecureEntry
255-
} else {
256-
return None;
257-
}
258-
}
259-
Conv::Cold => FnAttribute::Cold,
260-
// NOTE: the preserve attributes are not yet implemented in GCC:
261-
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899
262-
Conv::PreserveMost => return None,
263-
Conv::PreserveAll => return None,
264-
Conv::GpuKernel => {
242+
CanonAbi::C | CanonAbi::Rust => return None,
243+
CanonAbi::Arm(arm_call) => match arm_call {
244+
ArmCall::CCmseNonSecureCall => FnAttribute::ArmCmseNonsecureCall,
245+
ArmCall::CCmseNonSecureEntry => FnAttribute::ArmCmseNonsecureEntry,
246+
ArmCall::Aapcs => FnAttribute::ArmPcs("aapcs"),
247+
},
248+
CanonAbi::RustCold => FnAttribute::Cold,
249+
CanonAbi::GpuKernel => {
265250
if arch == "amdgpu" {
266251
FnAttribute::GcnAmdGpuHsaKernel
267252
} else if arch == "nvptx64" {
@@ -271,26 +256,24 @@ pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<
271256
}
272257
}
273258
// TODO(antoyo): check if those AVR attributes are mapped correctly.
274-
Conv::AvrInterrupt => FnAttribute::AvrSignal,
275-
Conv::AvrNonBlockingInterrupt => FnAttribute::AvrInterrupt,
276-
Conv::ArmAapcs => FnAttribute::ArmPcs("aapcs"),
277-
Conv::Msp430Intr => FnAttribute::Msp430Interrupt,
278-
Conv::RiscvInterrupt { kind } => {
279-
let kind = match kind {
280-
RiscvInterruptKind::Machine => "machine",
281-
RiscvInterruptKind::Supervisor => "supervisor",
282-
};
283-
FnAttribute::RiscvInterrupt(kind)
284-
}
285-
Conv::X86Fastcall => FnAttribute::X86FastCall,
286-
Conv::X86Intr => FnAttribute::X86Interrupt,
287-
Conv::X86Stdcall => FnAttribute::X86Stdcall,
288-
Conv::X86ThisCall => FnAttribute::X86ThisCall,
289-
// NOTE: the vectorcall calling convention is not yet implemented in GCC:
290-
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
291-
Conv::X86VectorCall => return None,
292-
Conv::X86_64SysV => FnAttribute::X86SysvAbi,
293-
Conv::X86_64Win64 => FnAttribute::X86MsAbi,
259+
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
260+
InterruptKind::Avr => FnAttribute::AvrSignal,
261+
InterruptKind::AvrNonBlocking => FnAttribute::AvrInterrupt,
262+
InterruptKind::Msp430 => FnAttribute::Msp430Interrupt,
263+
InterruptKind::RiscvMachine => FnAttribute::RiscvInterrupt("machine"),
264+
InterruptKind::RiscvSupervisor => FnAttribute::RiscvInterrupt("supervisor"),
265+
InterruptKind::X86 => FnAttribute::X86Interrupt,
266+
},
267+
CanonAbi::X86(x86_call) => match x86_call {
268+
X86Call::Fastcall => FnAttribute::X86FastCall,
269+
X86Call::Stdcall => FnAttribute::X86Stdcall,
270+
X86Call::Thiscall => FnAttribute::X86ThisCall,
271+
// // NOTE: the vectorcall calling convention is not yet implemented in GCC:
272+
// // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
273+
X86Call::Vectorcall => return None,
274+
X86Call::SysV64 => FnAttribute::X86SysvAbi,
275+
X86Call::Win64 => FnAttribute::X86MsAbi,
276+
},
294277
};
295278
Some(attribute)
296279
}

compiler/rustc_codegen_gcc/src/int.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
//! 128-bit integers on 32-bit platforms and thus require to be handled manually.
44
55
use gccjit::{BinaryOp, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp};
6-
use rustc_abi::{Endian, ExternAbi};
6+
use rustc_abi::{CanonAbi, Endian, ExternAbi};
77
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
88
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
99
use rustc_middle::ty::{self, Ty};
10-
use rustc_target::callconv::{ArgAbi, ArgAttributes, Conv, FnAbi, PassMode};
10+
use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
1111

1212
use crate::builder::{Builder, ToGccComp};
1313
use crate::common::{SignType, TypeReflection};
@@ -397,7 +397,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
397397
ret: arg_abi,
398398
c_variadic: false,
399399
fixed_count: 3,
400-
conv: Conv::C,
400+
conv: CanonAbi::C,
401401
can_unwind: false,
402402
};
403403
fn_abi.adjust_for_foreign_abi(self.cx, ExternAbi::C { unwind: false });

0 commit comments

Comments
 (0)