Skip to content

Commit 920154e

Browse files
compiler: change Conv to CanonAbi
1 parent ecfb051 commit 920154e

File tree

8 files changed

+64
-65
lines changed

8 files changed

+64
-65
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::hash_map::Entry::*;
22

3+
use rustc_abi::{CanonAbi, X86Call};
34
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE, global_fn_name};
45
use rustc_data_structures::unord::UnordMap;
56
use rustc_hir::def::DefKind;
@@ -14,7 +15,6 @@ use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolNam
1415
use rustc_middle::util::Providers;
1516
use rustc_session::config::{CrateType, OomStrategy};
1617
use rustc_symbol_mangling::mangle_internal_symbol;
17-
use rustc_target::callconv::Conv;
1818
use rustc_target::spec::{SanitizerSet, TlsModel};
1919
use tracing::debug;
2020

@@ -652,7 +652,7 @@ pub(crate) fn symbol_name_for_instance_in_crate<'tcx>(
652652
fn calling_convention_for_symbol<'tcx>(
653653
tcx: TyCtxt<'tcx>,
654654
symbol: ExportedSymbol<'tcx>,
655-
) -> (Conv, &'tcx [rustc_target::callconv::ArgAbi<'tcx, Ty<'tcx>>]) {
655+
) -> (CanonAbi, &'tcx [rustc_target::callconv::ArgAbi<'tcx, Ty<'tcx>>]) {
656656
let instance = match symbol {
657657
ExportedSymbol::NonGeneric(def_id) | ExportedSymbol::Generic(def_id, _)
658658
if tcx.is_static(def_id) =>
@@ -683,7 +683,7 @@ fn calling_convention_for_symbol<'tcx>(
683683
})
684684
.map(|fnabi| (fnabi.conv, &fnabi.args[..]))
685685
// FIXME(workingjubilee): why don't we know the convention here?
686-
.unwrap_or((Conv::Rust, &[]))
686+
.unwrap_or((CanonAbi::Rust, &[]))
687687
}
688688

689689
/// This is the symbol name of the given instance as seen by the linker.
@@ -717,14 +717,14 @@ pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
717717
_ => return undecorated,
718718
};
719719

720-
let (conv, args) = calling_convention_for_symbol(tcx, symbol);
720+
let (callconv, args) = calling_convention_for_symbol(tcx, symbol);
721721

722722
// Decorate symbols with prefixes, suffixes and total number of bytes of arguments.
723723
// Reference: https://docs.microsoft.com/en-us/cpp/build/reference/decorated-names?view=msvc-170
724-
let (prefix, suffix) = match conv {
725-
Conv::X86Fastcall => ("@", "@"),
726-
Conv::X86Stdcall => ("_", "@"),
727-
Conv::X86VectorCall => ("", "@@"),
724+
let (prefix, suffix) = match callconv {
725+
CanonAbi::X86(X86Call::Fastcall) => ("@", "@"),
726+
CanonAbi::X86(X86Call::Stdcall) => ("_", "@"),
727+
CanonAbi::X86(X86Call::Vectorcall) => ("", "@@"),
728728
_ => {
729729
if let Some(prefix) = prefix {
730730
undecorated.insert(0, prefix);
@@ -758,9 +758,9 @@ pub(crate) fn extend_exported_symbols<'tcx>(
758758
symbol: ExportedSymbol<'tcx>,
759759
instantiating_crate: CrateNum,
760760
) {
761-
let (conv, _) = calling_convention_for_symbol(tcx, symbol);
761+
let (callconv, _) = calling_convention_for_symbol(tcx, symbol);
762762

763-
if conv != Conv::GpuKernel || tcx.sess.target.os != "amdhsa" {
763+
if callconv != CanonAbi::GpuKernel || tcx.sess.target.os != "amdhsa" {
764764
return;
765765
}
766766

compiler/rustc_const_eval/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const_eval_frame_note_inner = inside {$where_ ->
118118
const_eval_frame_note_last = the failure occurred here
119119
120120
const_eval_incompatible_calling_conventions =
121-
calling a function with calling convention {$callee_conv} using calling convention {$caller_conv}
121+
calling a function with calling convention "{$callee_conv}" using calling convention "{$caller_conv}"
122122
123123
const_eval_incompatible_return_types =
124124
calling a function with return type {$callee_ty} passing return place of type {$caller_ty}

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! This module ensures that if a function's ABI requires a particular target feature,
22
//! that target feature is enabled both on the callee and all callers.
3-
use rustc_abi::{BackendRepr, RegKind};
3+
use rustc_abi::{BackendRepr, CanonAbi, RegKind, X86Call};
44
use rustc_hir::{CRATE_HIR_ID, HirId};
55
use rustc_middle::mir::{self, Location, traversal};
66
use rustc_middle::ty::layout::LayoutCx;
77
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt, TypingEnv};
88
use rustc_session::lint::builtin::WASM_C_ABI;
99
use rustc_span::def_id::DefId;
1010
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
11-
use rustc_target::callconv::{ArgAbi, Conv, FnAbi, PassMode};
11+
use rustc_target::callconv::{ArgAbi, FnAbi, PassMode};
1212
use rustc_target::spec::{HasWasmCAbiOpt, WasmCAbi};
1313

1414
use crate::errors;
@@ -72,7 +72,7 @@ fn do_check_simd_vector_abi<'tcx>(
7272
}
7373
}
7474
// The `vectorcall` ABI is special in that it requires SSE2 no matter which types are being passed.
75-
if abi.conv == Conv::X86VectorCall && !have_feature(sym::sse2) {
75+
if abi.conv == CanonAbi::X86(X86Call::Vectorcall) && !have_feature(sym::sse2) {
7676
let (span, _hir_id) = loc();
7777
tcx.dcx().emit_err(errors::AbiRequiredTargetFeature {
7878
span,
@@ -128,7 +128,7 @@ fn do_check_wasm_abi<'tcx>(
128128
if !(tcx.sess.target.arch == "wasm32"
129129
&& tcx.sess.target.os == "unknown"
130130
&& tcx.wasm_c_abi_opt() == WasmCAbi::Legacy { with_lint: true }
131-
&& abi.conv == Conv::C)
131+
&& abi.conv == CanonAbi::C)
132132
{
133133
return;
134134
}

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
//! For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler,
55
//! see design document in the tracking issue #89653.
66
7+
use rustc_abi::CanonAbi;
78
use rustc_data_structures::fx::FxHashMap;
89
use rustc_middle::bug;
910
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
10-
use rustc_target::callconv::{Conv, FnAbi, PassMode};
11+
use rustc_target::callconv::{FnAbi, PassMode};
1112
use tracing::instrument;
1213

1314
mod encode;
@@ -45,7 +46,7 @@ pub fn typeid_for_fnabi<'tcx>(
4546
let mut encode_ty_options = EncodeTyOptions::from_bits(options.bits())
4647
.unwrap_or_else(|| bug!("typeid_for_fnabi: invalid option(s) `{:?}`", options.bits()));
4748
match fn_abi.conv {
48-
Conv::C => {
49+
CanonAbi::C => {
4950
encode_ty_options.insert(EncodeTyOptions::GENERALIZE_REPR_C);
5051
}
5152
_ => {

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![allow(rustc::usage_of_qualified_ty)]
44

5+
use rustc_abi::{ArmCall, CanonAbi, InterruptKind, X86Call};
56
use rustc_middle::ty;
67
use rustc_target::callconv::{self, Conv};
78
use stable_mir::abi::{
@@ -69,7 +70,7 @@ impl<'tcx> Stable<'tcx> for callconv::FnAbi<'tcx, ty::Ty<'tcx>> {
6970

7071
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
7172
assert!(self.args.len() >= self.fixed_count as usize);
72-
assert!(!self.c_variadic || matches!(self.conv, Conv::C));
73+
assert!(!self.c_variadic || matches!(self.conv, CanonAbi::C));
7374
FnAbi {
7475
args: self.args.as_ref().stable(tables),
7576
ret: self.ret.stable(tables),
@@ -121,6 +122,41 @@ impl<'tcx> Stable<'tcx> for callconv::Conv {
121122
}
122123
}
123124

125+
impl<'tcx> Stable<'tcx> for CanonAbi {
126+
type T = CallConvention;
127+
128+
fn stable(&self, _tables: &mut Tables<'_>) -> Self::T {
129+
match self {
130+
CanonAbi::C => CallConvention::C,
131+
CanonAbi::Rust => CallConvention::Rust,
132+
CanonAbi::RustCold => CallConvention::Cold,
133+
CanonAbi::Arm(arm_call) => match arm_call {
134+
ArmCall::Aapcs => CallConvention::ArmAapcs,
135+
ArmCall::CCmseNonSecureCall => CallConvention::CCmseNonSecureCall,
136+
ArmCall::CCmseNonSecureEntry => CallConvention::CCmseNonSecureEntry,
137+
},
138+
CanonAbi::GpuKernel => CallConvention::GpuKernel,
139+
CanonAbi::Interrupt(interrupt_kind) => match interrupt_kind {
140+
InterruptKind::Avr => CallConvention::AvrInterrupt,
141+
InterruptKind::AvrNonBlocking => CallConvention::AvrNonBlockingInterrupt,
142+
InterruptKind::Msp430 => CallConvention::Msp430Intr,
143+
InterruptKind::RiscvMachine | InterruptKind::RiscvSupervisor => {
144+
CallConvention::RiscvInterrupt
145+
}
146+
InterruptKind::X86 => CallConvention::X86Intr,
147+
},
148+
CanonAbi::X86(x86_call) => match x86_call {
149+
X86Call::Fastcall => CallConvention::X86Fastcall,
150+
X86Call::Stdcall => CallConvention::X86Stdcall,
151+
X86Call::SysV64 => CallConvention::X86_64SysV,
152+
X86Call::Thiscall => CallConvention::X86ThisCall,
153+
X86Call::Vectorcall => CallConvention::X86VectorCall,
154+
X86Call::Win64 => CallConvention::X86_64Win64,
155+
},
156+
}
157+
}
158+
}
159+
124160
impl<'tcx> Stable<'tcx> for callconv::PassMode {
125161
type T = PassMode;
126162

compiler/rustc_target/src/callconv/arm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use rustc_abi::{HasDataLayout, TyAbiInterface};
1+
use rustc_abi::{ArmCall, CanonAbi, HasDataLayout, TyAbiInterface};
22

3-
use crate::callconv::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform};
3+
use crate::callconv::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
44
use crate::spec::HasTargetSpec;
55

66
fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
@@ -90,7 +90,7 @@ where
9090
// If this is a target with a hard-float ABI, and the function is not explicitly
9191
// `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates.
9292
let vfp = cx.target_spec().llvm_target.ends_with("hf")
93-
&& fn_abi.conv != Conv::ArmAapcs
93+
&& fn_abi.conv != CanonAbi::Arm(ArmCall::Aapcs)
9494
&& !fn_abi.c_variadic;
9595

9696
if !fn_abi.ret.is_ignore() {

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::str::FromStr;
33
use std::{fmt, iter};
44

55
use rustc_abi::{
6-
AddressSpace, Align, BackendRepr, ExternAbi, HasDataLayout, Primitive, Reg, RegKind, Scalar,
7-
Size, TyAbiInterface, TyAndLayout,
6+
AddressSpace, Align, BackendRepr, CanonAbi, ExternAbi, HasDataLayout, Primitive, Reg, RegKind,
7+
Scalar, Size, TyAbiInterface, TyAndLayout,
88
};
99
use rustc_macros::HashStable_Generic;
1010

@@ -606,7 +606,7 @@ pub struct FnAbi<'a, Ty> {
606606
/// This can be used to know whether an argument is variadic or not.
607607
pub fixed_count: u32,
608608
/// The calling convention of this function.
609-
pub conv: Conv,
609+
pub conv: CanonAbi,
610610
/// Indicates if an unwind may happen across a call to this function.
611611
pub can_unwind: bool,
612612
}

compiler/rustc_ty_utils/src/abi.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt};
1313
use rustc_session::config::OptLevel;
1414
use rustc_span::def_id::DefId;
1515
use rustc_target::callconv::{
16-
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, RiscvInterruptKind,
16+
AbiMap, ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, FnAbi, PassMode,
1717
};
1818
use tracing::debug;
1919

@@ -240,45 +240,6 @@ fn fn_sig_for_fn_abi<'tcx>(
240240
}
241241
}
242242

243-
#[inline]
244-
fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: ExternAbi, c_variadic: bool) -> Conv {
245-
use rustc_abi::ExternAbi::*;
246-
match tcx.sess.target.adjust_abi(abi, c_variadic) {
247-
Rust | RustCall => Conv::Rust,
248-
249-
// This is intentionally not using `Conv::Cold`, as that has to preserve
250-
// even SIMD registers, which is generally not a good trade-off.
251-
RustCold => Conv::PreserveMost,
252-
253-
// It's the ABI's job to select this, not ours.
254-
System { .. } => bug!("system abi should be selected elsewhere"),
255-
EfiApi => bug!("eficall abi should be selected elsewhere"),
256-
257-
Stdcall { .. } => Conv::X86Stdcall,
258-
Fastcall { .. } => Conv::X86Fastcall,
259-
Vectorcall { .. } => Conv::X86VectorCall,
260-
Thiscall { .. } => Conv::X86ThisCall,
261-
C { .. } => Conv::C,
262-
Unadjusted => Conv::C,
263-
Win64 { .. } => Conv::X86_64Win64,
264-
SysV64 { .. } => Conv::X86_64SysV,
265-
Aapcs { .. } => Conv::ArmAapcs,
266-
CCmseNonSecureCall => Conv::CCmseNonSecureCall,
267-
CCmseNonSecureEntry => Conv::CCmseNonSecureEntry,
268-
PtxKernel => Conv::GpuKernel,
269-
Msp430Interrupt => Conv::Msp430Intr,
270-
X86Interrupt => Conv::X86Intr,
271-
GpuKernel => Conv::GpuKernel,
272-
AvrInterrupt => Conv::AvrInterrupt,
273-
AvrNonBlockingInterrupt => Conv::AvrNonBlockingInterrupt,
274-
RiscvInterruptM => Conv::RiscvInterrupt { kind: RiscvInterruptKind::Machine },
275-
RiscvInterruptS => Conv::RiscvInterrupt { kind: RiscvInterruptKind::Supervisor },
276-
277-
// These API constants ought to be more specific...
278-
Cdecl { .. } => Conv::C,
279-
}
280-
}
281-
282243
fn fn_abi_of_fn_ptr<'tcx>(
283244
tcx: TyCtxt<'tcx>,
284245
query: ty::PseudoCanonicalInput<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
@@ -529,7 +490,8 @@ fn fn_abi_new_uncached<'tcx>(
529490
};
530491
let sig = tcx.normalize_erasing_regions(cx.typing_env, sig);
531492

532-
let conv = conv_from_spec_abi(cx.tcx(), sig.abi, sig.c_variadic);
493+
let abi_map = AbiMap::from_target(&tcx.sess.target);
494+
let conv = abi_map.canonize_abi(sig.abi, sig.c_variadic).unwrap();
533495

534496
let mut inputs = sig.inputs();
535497
let extra_args = if sig.abi == ExternAbi::RustCall {

0 commit comments

Comments
 (0)