Skip to content

Commit 582ad1f

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 99e783d + 12be26f commit 582ad1f

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

src/abi/mod.rs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::mem;
1010
use cranelift_codegen::ir::{ArgumentPurpose, SigRef};
1111
use cranelift_codegen::isa::CallConv;
1212
use cranelift_module::ModuleError;
13-
use rustc_abi::ExternAbi;
13+
use rustc_abi::{CanonAbi, ExternAbi, X86Call};
1414
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
1515
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
1616
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -19,7 +19,7 @@ use rustc_middle::ty::layout::FnAbiOf;
1919
use rustc_middle::ty::print::with_no_trimmed_paths;
2020
use rustc_session::Session;
2121
use rustc_span::source_map::Spanned;
22-
use rustc_target::callconv::{Conv, FnAbi, PassMode};
22+
use rustc_target::callconv::{FnAbi, PassMode};
2323
use smallvec::SmallVec;
2424

2525
use self::pass_mode::*;
@@ -42,32 +42,27 @@ fn clif_sig_from_fn_abi<'tcx>(
4242
Signature { params, returns, call_conv }
4343
}
4444

45-
pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: CallConv) -> CallConv {
45+
pub(crate) fn conv_to_call_conv(
46+
sess: &Session,
47+
c: CanonAbi,
48+
default_call_conv: CallConv,
49+
) -> CallConv {
4650
match c {
47-
Conv::Rust | Conv::C => default_call_conv,
48-
Conv::Cold | Conv::PreserveMost | Conv::PreserveAll => CallConv::Cold,
49-
Conv::X86_64SysV => CallConv::SystemV,
50-
Conv::X86_64Win64 => CallConv::WindowsFastcall,
51-
52-
// Should already get a back compat warning
53-
Conv::X86Fastcall | Conv::X86Stdcall | Conv::X86ThisCall | Conv::X86VectorCall => {
54-
default_call_conv
55-
}
56-
57-
Conv::X86Intr | Conv::RiscvInterrupt { .. } => {
58-
sess.dcx().fatal(format!("interrupt call conv {c:?} not yet implemented"))
51+
CanonAbi::Rust | CanonAbi::C => default_call_conv,
52+
CanonAbi::RustCold => CallConv::Cold,
53+
54+
CanonAbi::X86(x86_call) => match x86_call {
55+
X86Call::SysV64 => CallConv::SystemV,
56+
X86Call::Win64 => CallConv::WindowsFastcall,
57+
// Should already get a back compat warning
58+
_ => default_call_conv,
59+
},
60+
61+
CanonAbi::Interrupt(_) | CanonAbi::Arm(_) => {
62+
sess.dcx().fatal("call conv {c:?} is not yet implemented")
5963
}
60-
61-
Conv::ArmAapcs => sess.dcx().fatal("aapcs call conv not yet implemented"),
62-
Conv::CCmseNonSecureCall => {
63-
sess.dcx().fatal("C-cmse-nonsecure-call call conv is not yet implemented");
64-
}
65-
Conv::CCmseNonSecureEntry => {
66-
sess.dcx().fatal("C-cmse-nonsecure-entry call conv is not yet implemented");
67-
}
68-
69-
Conv::Msp430Intr | Conv::GpuKernel | Conv::AvrInterrupt | Conv::AvrNonBlockingInterrupt => {
70-
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target");
64+
CanonAbi::GpuKernel => {
65+
unreachable!("tried to use {c:?} call conv which only exists on an unsupported target")
7166
}
7267
}
7368
}
@@ -610,7 +605,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
610605
target: CallTarget,
611606
call_args: &mut Vec<Value>,
612607
) {
613-
if fn_abi.conv != Conv::C {
608+
if fn_abi.conv != CanonAbi::C {
614609
fx.tcx.dcx().span_fatal(
615610
source_info.span,
616611
format!("Variadic call for non-C abi {:?}", fn_abi.conv),

0 commit comments

Comments
 (0)