Skip to content

Commit 2351a3e

Browse files
compiler: simplify TargetOptions ABI functions
`adjust_abi` is not needed and `is_abi_supported` can be a 1-liner.
1 parent 2ad64b4 commit 2351a3e

File tree

2 files changed

+2
-108
lines changed

2 files changed

+2
-108
lines changed

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ impl<'a, Ty> FnAbi<'a, Ty> {
697697
"sparc" => sparc::compute_abi_info(cx, self),
698698
"sparc64" => sparc64::compute_abi_info(cx, self),
699699
"nvptx64" => {
700-
let abi = cx.target_spec().adjust_abi(abi, self.c_variadic);
701700
if abi == ExternAbi::PtxKernel || abi == ExternAbi::GpuKernel {
702701
nvptx64::compute_ptx_kernel_abi_info(cx, self)
703702
} else {

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,114 +2915,9 @@ impl DerefMut for Target {
29152915
}
29162916

29172917
impl Target {
2918-
/// Given a function ABI, turn it into the correct ABI for this target.
2919-
pub fn adjust_abi(&self, abi: ExternAbi, c_variadic: bool) -> ExternAbi {
2920-
use ExternAbi::*;
2921-
match abi {
2922-
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
2923-
// `__stdcall` only applies on x86 and on non-variadic functions:
2924-
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
2925-
System { unwind } => {
2926-
if self.is_like_windows && self.arch == "x86" && !c_variadic {
2927-
Stdcall { unwind }
2928-
} else {
2929-
C { unwind }
2930-
}
2931-
}
2932-
2933-
EfiApi => {
2934-
if self.arch == "arm" {
2935-
Aapcs { unwind: false }
2936-
} else if self.arch == "x86_64" {
2937-
Win64 { unwind: false }
2938-
} else {
2939-
C { unwind: false }
2940-
}
2941-
}
2942-
2943-
// See commentary in `is_abi_supported`.
2944-
Stdcall { unwind } | Thiscall { unwind } | Fastcall { unwind } => {
2945-
if self.arch == "x86" { abi } else { C { unwind } }
2946-
}
2947-
Vectorcall { unwind } => {
2948-
if ["x86", "x86_64"].contains(&&*self.arch) {
2949-
abi
2950-
} else {
2951-
C { unwind }
2952-
}
2953-
}
2954-
2955-
// The Windows x64 calling convention we use for `extern "Rust"`
2956-
// <https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions#register-volatility-and-preservation>
2957-
// expects the callee to save `xmm6` through `xmm15`, but `PreserveMost`
2958-
// (that we use by default for `extern "rust-cold"`) doesn't save any of those.
2959-
// So to avoid bloating callers, just use the Rust convention here.
2960-
RustCold if self.is_like_windows && self.arch == "x86_64" => Rust,
2961-
2962-
abi => abi,
2963-
}
2964-
}
2965-
29662918
pub fn is_abi_supported(&self, abi: ExternAbi) -> bool {
2967-
use ExternAbi::*;
2968-
match abi {
2969-
Rust | C { .. } | System { .. } | RustCall | Unadjusted | Cdecl { .. } | RustCold => {
2970-
true
2971-
}
2972-
EfiApi => {
2973-
["arm", "aarch64", "riscv32", "riscv64", "x86", "x86_64"].contains(&&self.arch[..])
2974-
}
2975-
X86Interrupt => ["x86", "x86_64"].contains(&&self.arch[..]),
2976-
Aapcs { .. } => "arm" == self.arch,
2977-
CCmseNonSecureCall | CCmseNonSecureEntry => {
2978-
["thumbv8m.main-none-eabi", "thumbv8m.main-none-eabihf", "thumbv8m.base-none-eabi"]
2979-
.contains(&&self.llvm_target[..])
2980-
}
2981-
Win64 { .. } | SysV64 { .. } => self.arch == "x86_64",
2982-
PtxKernel => self.arch == "nvptx64",
2983-
GpuKernel => ["amdgpu", "nvptx64"].contains(&&self.arch[..]),
2984-
Msp430Interrupt => self.arch == "msp430",
2985-
RiscvInterruptM | RiscvInterruptS => ["riscv32", "riscv64"].contains(&&self.arch[..]),
2986-
AvrInterrupt | AvrNonBlockingInterrupt => self.arch == "avr",
2987-
Thiscall { .. } => self.arch == "x86",
2988-
// On windows these fall-back to platform native calling convention (C) when the
2989-
// architecture is not supported.
2990-
//
2991-
// This is I believe a historical accident that has occurred as part of Microsoft
2992-
// striving to allow most of the code to "just" compile when support for 64-bit x86
2993-
// was added and then later again, when support for ARM architectures was added.
2994-
//
2995-
// This is well documented across MSDN. Support for this in Rust has been added in
2996-
// #54576. This makes much more sense in context of Microsoft's C++ than it does in
2997-
// Rust, but there isn't much leeway remaining here to change it back at the time this
2998-
// comment has been written.
2999-
//
3000-
// Following are the relevant excerpts from the MSDN documentation.
3001-
//
3002-
// > The __vectorcall calling convention is only supported in native code on x86 and
3003-
// x64 processors that include Streaming SIMD Extensions 2 (SSE2) and above.
3004-
// > ...
3005-
// > On ARM machines, __vectorcall is accepted and ignored by the compiler.
3006-
//
3007-
// -- https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-160
3008-
//
3009-
// > On ARM and x64 processors, __stdcall is accepted and ignored by the compiler;
3010-
//
3011-
// -- https://docs.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-160
3012-
//
3013-
// > In most cases, keywords or compiler switches that specify an unsupported
3014-
// > convention on a particular platform are ignored, and the platform default
3015-
// > convention is used.
3016-
//
3017-
// -- https://docs.microsoft.com/en-us/cpp/cpp/argument-passing-and-naming-conventions
3018-
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } if self.is_like_windows => true,
3019-
// Outside of Windows we want to only support these calling conventions for the
3020-
// architectures for which these calling conventions are actually well defined.
3021-
Stdcall { .. } | Fastcall { .. } if self.arch == "x86" => true,
3022-
Vectorcall { .. } if ["x86", "x86_64"].contains(&&self.arch[..]) => true,
3023-
// Reject these calling conventions everywhere else.
3024-
Stdcall { .. } | Fastcall { .. } | Vectorcall { .. } => false,
3025-
}
2919+
let abi_map = AbiMap::from_target(self);
2920+
abi_map.canonize_abi(abi, false).is_mapped()
30262921
}
30272922

30282923
/// Minimum integer size in bits that this target can perform atomic

0 commit comments

Comments
 (0)