Skip to content

Commit 906fc5c

Browse files
authored
Rollup merge of #141569 - workingjubilee:canonicalize-abi, r=bjorn3
Replace ad-hoc ABI "adjustments" with an `AbiMap` to `CanonAbi` Our `conv_from_spec_abi`, `adjust_abi`, and `is_abi_supported` combine to give us a very confusing way of reasoning about what _actual_ calling convention we want to lower our code to and whether we want to compile the resulting code at all. Instead of leaving this code as a miniature adventure game in which someone tries to combine stateful mutations into a Rube Goldberg machine that will let them escape the maze and arrive at the promised land of codegen, we let `AbiMap` devour this complexity. Once you have an `AbiMap`, you can answer which `ExternAbi`s will lower to what `CanonAbi`s (and whether they will lower at all). Removed: - `conv_from_spec_abi` replaced by `AbiMap::canonize_abi` - `adjust_abi` replaced by same - `Conv::PreserveAll` as unused - `Conv::Cold` as unused - `enum Conv` replaced by `enum CanonAbi` target-spec.json changes: - If you have a target-spec.json then now your "entry-abi" key will be specified in terms of one of the `"{abi}"` strings Rust recognizes, e.g. ```json "entry-abi": "C", "entry-abi": "win64", "entry-abi": "aapcs", ```
2 parents 9eced6c + 0f7ec70 commit 906fc5c

File tree

2 files changed

+31
-48
lines changed

2 files changed

+31
-48
lines changed

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;
@@ -238,29 +236,16 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
238236
}
239237

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

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)