Skip to content

Commit 26b0560

Browse files
committed
rustc_target: allow unenumerated architectures
1 parent 0c8533d commit 26b0560

File tree

19 files changed

+169
-67
lines changed

19 files changed

+169
-67
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ pub(crate) fn codegen_drop<'tcx>(
788788
pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam {
789789
let param = AbiParam::new(ty);
790790
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() {
791-
match (tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) {
791+
match (&tcx.sess.target.arch, tcx.sess.target.vendor.as_ref()) {
792792
(Arch::X86_64, _) | (Arch::AArch64, "apple") => match (ty, is_signed) {
793793
(types::I8 | types::I16, true) => param.sext(),
794794
(types::I8 | types::I16, false) => param.uext(),

compiler/rustc_codegen_gcc/src/abi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
235235

236236
#[cfg(feature = "master")]
237237
fn gcc_cconv(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Option<FnAttribute<'gcc>> {
238-
conv_to_fn_attribute(self.conv, cx.tcx.sess.target.arch)
238+
conv_to_fn_attribute(self.conv, &cx.tcx.sess.target.arch)
239239
}
240240
}
241241

242242
#[cfg(feature = "master")]
243-
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: Arch) -> Option<FnAttribute<'gcc>> {
243+
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &Arch) -> Option<FnAttribute<'gcc>> {
244244
let attribute = match conv {
245245
CanonAbi::C | CanonAbi::Rust => return None,
246246
CanonAbi::RustCold => FnAttribute::Cold,
@@ -254,8 +254,8 @@ pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: Arch) -> Option<FnAttrib
254254
ArmCall::Aapcs => FnAttribute::ArmPcs("aapcs"),
255255
},
256256
CanonAbi::GpuKernel => match arch {
257-
Arch::AmdGpu => FnAttribute::GcnAmdGpuHsaKernel,
258-
Arch::Nvptx64 => FnAttribute::NvptxKernel,
257+
&Arch::AmdGpu => FnAttribute::GcnAmdGpuHsaKernel,
258+
&Arch::Nvptx64 => FnAttribute::NvptxKernel,
259259
arch => panic!("Arch {arch} does not support GpuKernel calling convention"),
260260
},
261261
// TODO(antoyo): check if those AVR attributes are mapped correctly.

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
487487
let entry_name = self.sess().target.entry_name.as_ref();
488488
if !self.functions.borrow().contains_key(entry_name) {
489489
#[cfg(feature = "master")]
490-
let conv = conv_to_fn_attribute(self.sess().target.entry_abi, self.sess().target.arch);
490+
let conv = conv_to_fn_attribute(self.sess().target.entry_abi, &self.sess().target.arch);
491491
#[cfg(not(feature = "master"))]
492492
let conv = None;
493493
Some(self.declare_entry_fn(entry_name, fn_type, conv))

compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,46 +67,46 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
6767
// To find a list of GCC's names, check https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
6868
pub fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
6969
// cSpell:disable
70-
match (sess.target.arch, s) {
70+
match (&sess.target.arch, s) {
7171
// FIXME: seems like x87 does not exist?
72-
(Arch::X86 | Arch::X86_64, "x87") => smallvec![],
73-
(Arch::X86 | Arch::X86_64, "sse4.2") => smallvec!["sse4.2", "crc32"],
74-
(Arch::X86 | Arch::X86_64, "pclmulqdq") => smallvec!["pclmul"],
75-
(Arch::X86 | Arch::X86_64, "rdrand") => smallvec!["rdrnd"],
76-
(Arch::X86 | Arch::X86_64, "bmi1") => smallvec!["bmi"],
77-
(Arch::X86 | Arch::X86_64, "cmpxchg16b") => smallvec!["cx16"],
78-
(Arch::X86 | Arch::X86_64, "avx512vaes") => smallvec!["vaes"],
79-
(Arch::X86 | Arch::X86_64, "avx512gfni") => smallvec!["gfni"],
80-
(Arch::X86 | Arch::X86_64, "avx512vpclmulqdq") => smallvec!["vpclmulqdq"],
72+
(&Arch::X86 | &Arch::X86_64, "x87") => smallvec![],
73+
(&Arch::X86 | &Arch::X86_64, "sse4.2") => smallvec!["sse4.2", "crc32"],
74+
(&Arch::X86 | &Arch::X86_64, "pclmulqdq") => smallvec!["pclmul"],
75+
(&Arch::X86 | &Arch::X86_64, "rdrand") => smallvec!["rdrnd"],
76+
(&Arch::X86 | &Arch::X86_64, "bmi1") => smallvec!["bmi"],
77+
(&Arch::X86 | &Arch::X86_64, "cmpxchg16b") => smallvec!["cx16"],
78+
(&Arch::X86 | &Arch::X86_64, "avx512vaes") => smallvec!["vaes"],
79+
(&Arch::X86 | &Arch::X86_64, "avx512gfni") => smallvec!["gfni"],
80+
(&Arch::X86 | &Arch::X86_64, "avx512vpclmulqdq") => smallvec!["vpclmulqdq"],
8181
// NOTE: seems like GCC requires 'avx512bw' for 'avx512vbmi2'.
82-
(Arch::X86 | Arch::X86_64, "avx512vbmi2") => {
82+
(&Arch::X86 | &Arch::X86_64, "avx512vbmi2") => {
8383
smallvec!["avx512vbmi2", "avx512bw"]
8484
}
8585
// NOTE: seems like GCC requires 'avx512bw' for 'avx512bitalg'.
86-
(Arch::X86 | Arch::X86_64, "avx512bitalg") => {
86+
(&Arch::X86 | &Arch::X86_64, "avx512bitalg") => {
8787
smallvec!["avx512bitalg", "avx512bw"]
8888
}
89-
(Arch::AArch64, "rcpc2") => smallvec!["rcpc-immo"],
90-
(Arch::AArch64, "dpb") => smallvec!["ccpp"],
91-
(Arch::AArch64, "dpb2") => smallvec!["ccdp"],
92-
(Arch::AArch64, "frintts") => smallvec!["fptoint"],
93-
(Arch::AArch64, "fcma") => smallvec!["complxnum"],
94-
(Arch::AArch64, "pmuv3") => smallvec!["perfmon"],
95-
(Arch::AArch64, "paca") => smallvec!["pauth"],
96-
(Arch::AArch64, "pacg") => smallvec!["pauth"],
89+
(&Arch::AArch64, "rcpc2") => smallvec!["rcpc-immo"],
90+
(&Arch::AArch64, "dpb") => smallvec!["ccpp"],
91+
(&Arch::AArch64, "dpb2") => smallvec!["ccdp"],
92+
(&Arch::AArch64, "frintts") => smallvec!["fptoint"],
93+
(&Arch::AArch64, "fcma") => smallvec!["complxnum"],
94+
(&Arch::AArch64, "pmuv3") => smallvec!["perfmon"],
95+
(&Arch::AArch64, "paca") => smallvec!["pauth"],
96+
(&Arch::AArch64, "pacg") => smallvec!["pauth"],
9797
// Rust ties fp and neon together. In GCC neon implicitly enables fp,
9898
// but we manually enable neon when a feature only implicitly enables fp
99-
(Arch::AArch64, "f32mm") => smallvec!["f32mm", "neon"],
100-
(Arch::AArch64, "f64mm") => smallvec!["f64mm", "neon"],
101-
(Arch::AArch64, "fhm") => smallvec!["fp16fml", "neon"],
102-
(Arch::AArch64, "fp16") => smallvec!["fullfp16", "neon"],
103-
(Arch::AArch64, "jsconv") => smallvec!["jsconv", "neon"],
104-
(Arch::AArch64, "sve") => smallvec!["sve", "neon"],
105-
(Arch::AArch64, "sve2") => smallvec!["sve2", "neon"],
106-
(Arch::AArch64, "sve2-aes") => smallvec!["sve2-aes", "neon"],
107-
(Arch::AArch64, "sve2-sm4") => smallvec!["sve2-sm4", "neon"],
108-
(Arch::AArch64, "sve2-sha3") => smallvec!["sve2-sha3", "neon"],
109-
(Arch::AArch64, "sve2-bitperm") => smallvec!["sve2-bitperm", "neon"],
99+
(&Arch::AArch64, "f32mm") => smallvec!["f32mm", "neon"],
100+
(&Arch::AArch64, "f64mm") => smallvec!["f64mm", "neon"],
101+
(&Arch::AArch64, "fhm") => smallvec!["fp16fml", "neon"],
102+
(&Arch::AArch64, "fp16") => smallvec!["fullfp16", "neon"],
103+
(&Arch::AArch64, "jsconv") => smallvec!["jsconv", "neon"],
104+
(&Arch::AArch64, "sve") => smallvec!["sve", "neon"],
105+
(&Arch::AArch64, "sve2") => smallvec!["sve2", "neon"],
106+
(&Arch::AArch64, "sve2-aes") => smallvec!["sve2-aes", "neon"],
107+
(&Arch::AArch64, "sve2-sm4") => smallvec!["sve2-sm4", "neon"],
108+
(&Arch::AArch64, "sve2-sha3") => smallvec!["sve2-sha3", "neon"],
109+
(&Arch::AArch64, "sve2-bitperm") => smallvec!["sve2-bitperm", "neon"],
110110
(_, s) => smallvec![s],
111111
}
112112
// cSpell:enable

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ pub(crate) fn to_llvm_calling_convention(sess: &Session, abi: CanonAbi) -> llvm:
698698
// possible to declare an `extern "custom"` block, so the backend still needs a calling
699699
// convention for declaring foreign functions.
700700
CanonAbi::Custom => llvm::CCallConv,
701-
CanonAbi::GpuKernel => match sess.target.arch {
701+
CanonAbi::GpuKernel => match &sess.target.arch {
702702
Arch::AmdGpu => llvm::AmdgpuKernel,
703703
Arch::Nvptx64 => llvm::PtxKernel,
704704
arch => panic!("Architecture {arch} does not support GpuKernel calling convention"),

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ pub(crate) fn target_config(sess: &Session) -> TargetConfig {
342342

343343
/// Determine whether or not experimental float types are reliable based on known bugs.
344344
fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
345-
let target_arch = sess.target.arch;
345+
let target_arch = &sess.target.arch;
346346
let target_os = sess.target.options.os.as_ref();
347347
let target_env = sess.target.options.env.as_ref();
348348
let target_abi = sess.target.options.abi.as_ref();

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub trait ArchiveBuilderBuilder {
118118

119119
let exports =
120120
items.into_iter().map(|item| item.into_coff_short_export(sess)).collect::<Vec<_>>();
121-
let machine = match sess.target.arch {
121+
let machine = match &sess.target.arch {
122122
Arch::X86_64 => MachineTypes::AMD64,
123123
Arch::X86 => MachineTypes::I386,
124124
Arch::AArch64 => MachineTypes::ARM64,
@@ -224,7 +224,7 @@ fn create_mingw_dll_import_lib(
224224
};
225225
// dlltool target architecture args from:
226226
// https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
227-
let (dlltool_target_arch, dlltool_target_bitness) = match sess.target.arch {
227+
let (dlltool_target_arch, dlltool_target_bitness) = match &sess.target.arch {
228228
Arch::X86_64 => ("i386:x86-64", "--64"),
229229
Arch::X86 => ("i386", "--32"),
230230
Arch::AArch64 => ("arm64", "--64"),

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl CrateInfo {
983983
// by the compiler, but that's ok because all this stuff is unstable anyway.
984984
let target = &tcx.sess.target;
985985
if !are_upstream_rust_objects_already_included(tcx.sess) {
986-
let add_prefix = match (target.is_like_windows, target.arch) {
986+
let add_prefix = match (target.is_like_windows, &target.arch) {
987987
(true, Arch::X86) => |name: String, _: SymbolExportKind| format!("_{name}"),
988988
(true, Arch::Arm64EC) => {
989989
// Only functions are decorated for arm64ec.

compiler/rustc_session/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ pub fn build_session(
11121112
_ => CtfeBacktrace::Disabled,
11131113
});
11141114

1115-
let asm_arch = if target.allow_asm { InlineAsmArch::from_arch(target.arch) } else { None };
1115+
let asm_arch = if target.allow_asm { InlineAsmArch::from_arch(&target.arch) } else { None };
11161116
let target_filesearch =
11171117
filesearch::FileSearch::new(&sopts.search_paths, &target_tlib_path, &target);
11181118
let host_filesearch = filesearch::FileSearch::new(&sopts.search_paths, &host_tlib_path, &host);

compiler/rustc_target/src/asm/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub enum InlineAsmArch {
245245
}
246246

247247
impl InlineAsmArch {
248-
pub fn from_arch(arch: Arch) -> Option<Self> {
248+
pub fn from_arch(arch: &Arch) -> Option<Self> {
249249
match arch {
250250
Arch::X86 => Some(Self::X86),
251251
Arch::X86_64 => Some(Self::X86_64),
@@ -273,7 +273,7 @@ impl InlineAsmArch {
273273
Arch::Msp430 => Some(Self::Msp430),
274274
Arch::M68k => Some(Self::M68k),
275275
Arch::CSky => Some(Self::CSKY),
276-
Arch::AmdGpu | Arch::Xtensa => None,
276+
Arch::AmdGpu | Arch::Xtensa | Arch::Unknown(_) => None,
277277
}
278278
}
279279
}

0 commit comments

Comments
 (0)