Skip to content

Commit 2b82fad

Browse files
committed
enum-ify llvm_abiname
1 parent 14d38a4 commit 2b82fad

File tree

83 files changed

+332
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+332
-253
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub(crate) fn target_machine_factory(
233233
let triple = SmallCStr::new(&versioned_llvm_target(sess));
234234
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
235235
let features = CString::new(target_features.join(",")).unwrap();
236-
let abi = SmallCStr::new(&sess.target.llvm_abiname);
236+
let abi = SmallCStr::new(sess.target.llvm_abiname.desc());
237237
let trap_unreachable =
238238
sess.opts.unstable_opts.trap_unreachable.unwrap_or(sess.target.trap_unreachable);
239239
let emit_stack_size_section = sess.opts.unstable_opts.emit_stack_sizes;

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,13 @@ pub(crate) unsafe fn create_module<'ll>(
525525
// to workaround lld as the LTO plugin not
526526
// correctly setting target-abi for the LTO object
527527
// FIXME: https://github.com/llvm/llvm-project/issues/50591
528-
// If llvm_abiname is empty, emit nothing.
529528
let llvm_abiname = &sess.target.options.llvm_abiname;
530-
if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) && !llvm_abiname.is_empty() {
529+
if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) {
531530
llvm::add_module_flag_str(
532531
llmod,
533532
llvm::ModuleFlagMergeBehavior::Error,
534533
"target-abi",
535-
llvm_abiname,
534+
llvm_abiname.desc(),
536535
);
537536
}
538537

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_codegen_ssa::traits::{
88
use rustc_middle::bug;
99
use rustc_middle::ty::Ty;
1010
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
11-
use rustc_target::spec::{Arch, Env, RustcAbi};
11+
use rustc_target::spec::{Arch, Env, LlvmAbi, RustcAbi};
1212

1313
use crate::builder::Builder;
1414
use crate::llvm::{Type, Value};
@@ -1077,7 +1077,7 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
10771077
AllowHigherAlign::Yes,
10781078
ForceRightAdjust::Yes,
10791079
),
1080-
Arch::RiscV32 if target.llvm_abiname == "ilp32e" => {
1080+
Arch::RiscV32 if target.llvm_abiname == LlvmAbi::Ilp32e => {
10811081
// FIXME: clang manually adjusts the alignment for this ABI. It notes:
10821082
//
10831083
// > To be compatible with GCC's behaviors, we force arguments with

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_metadata::fs::METADATA_FILENAME;
2020
use rustc_middle::bug;
2121
use rustc_session::Session;
2222
use rustc_span::sym;
23-
use rustc_target::spec::{CfgAbi, Os, RelocModel, Target, ef_avr_arch};
23+
use rustc_target::spec::{CfgAbi, LlvmAbi, Os, RelocModel, Target, ef_avr_arch};
2424
use tracing::debug;
2525

2626
use super::apple;
@@ -295,10 +295,10 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
295295
};
296296

297297
// Use the explicitly given ABI.
298-
match sess.target.options.llvm_abiname.as_ref() {
299-
"o32" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
300-
"n32" if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
301-
"n64" if !is_32bit => {}
298+
match &sess.target.options.llvm_abiname {
299+
LlvmAbi::O32 if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
300+
LlvmAbi::N32 if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
301+
LlvmAbi::N64 if !is_32bit => {}
302302
// The rest is invalid (which is already ensured by the target spec check).
303303
s => bug!("invalid LLVM ABI `{}` for MIPS target", s),
304304
};
@@ -336,12 +336,12 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
336336

337337
// Set the appropriate flag based on ABI
338338
// This needs to match LLVM `RISCVELFStreamer.cpp`
339-
match &*sess.target.llvm_abiname {
340-
"ilp32" | "lp64" => (),
341-
"ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
342-
"ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
339+
match &sess.target.llvm_abiname {
340+
LlvmAbi::Ilp32 | LlvmAbi::Lp64 => (),
341+
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
342+
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
343343
// Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI.
344-
"ilp32e" | "lp64e" => e_flags |= elf::EF_RISCV_RVE,
344+
LlvmAbi::Ilp32e | LlvmAbi::Lp64e => e_flags |= elf::EF_RISCV_RVE,
345345
_ => bug!("unknown RISC-V ABI name"),
346346
}
347347

@@ -353,10 +353,10 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
353353

354354
// Set the appropriate flag based on ABI
355355
// This needs to match LLVM `LoongArchELFStreamer.cpp`
356-
match &*sess.target.llvm_abiname {
357-
"ilp32s" | "lp64s" => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT,
358-
"ilp32f" | "lp64f" => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT,
359-
"ilp32d" | "lp64d" => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT,
356+
match &sess.target.llvm_abiname {
357+
LlvmAbi::Ilp32s | LlvmAbi::Lp64s => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT,
358+
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT,
359+
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT,
360360
_ => bug!("unknown LoongArch ABI name"),
361361
}
362362

@@ -383,14 +383,14 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
383383
const EF_PPC64_ABI_ELF_V1: u32 = 1;
384384
const EF_PPC64_ABI_ELF_V2: u32 = 2;
385385

386-
match sess.target.options.llvm_abiname.as_ref() {
386+
match sess.target.options.llvm_abiname {
387387
// If the flags do not correctly indicate the ABI,
388388
// linkers such as ld.lld assume that the ppc64 object files are always ELFv2
389389
// which leads to broken binaries if ELFv1 is used for the object files.
390-
"elfv1" => EF_PPC64_ABI_ELF_V1,
391-
"elfv2" => EF_PPC64_ABI_ELF_V2,
392-
"" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
393-
bug!("No ABI specified for this PPC64 ELF target");
390+
LlvmAbi::ElfV1 => EF_PPC64_ABI_ELF_V1,
391+
LlvmAbi::ElfV2 => EF_PPC64_ABI_ELF_V2,
392+
_ if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
393+
bug!("invalid ABI specified for this PPC64 ELF target");
394394
}
395395
// Fall back
396396
_ => EF_PPC64_ABI_UNKNOWN,

compiler/rustc_target/src/callconv/loongarch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::{
44
};
55

66
use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform};
7-
use crate::spec::HasTargetSpec;
7+
use crate::spec::{HasTargetSpec, LlvmAbi};
88

99
#[derive(Copy, Clone)]
1010
enum RegPassKind {
@@ -415,9 +415,9 @@ where
415415
C: HasDataLayout + HasTargetSpec,
416416
{
417417
let xlen = cx.data_layout().pointer_size().bits();
418-
let flen = match &cx.target_spec().llvm_abiname[..] {
419-
"ilp32f" | "lp64f" => 32,
420-
"ilp32d" | "lp64d" => 64,
418+
let flen = match &cx.target_spec().llvm_abiname {
419+
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => 32,
420+
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => 64,
421421
_ => 0,
422422
};
423423

compiler/rustc_target/src/callconv/powerpc64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use rustc_abi::{Endian, HasDataLayout, TyAbiInterface};
66

77
use crate::callconv::{Align, ArgAbi, FnAbi, Reg, RegKind, Uniform};
8-
use crate::spec::{HasTargetSpec, Os};
8+
use crate::spec::{HasTargetSpec, LlvmAbi, Os};
99

1010
#[derive(Debug, Clone, Copy, PartialEq)]
1111
enum ABI {
@@ -106,9 +106,9 @@ where
106106
Ty: TyAbiInterface<'a, C> + Copy,
107107
C: HasDataLayout + HasTargetSpec,
108108
{
109-
let abi = if cx.target_spec().options.llvm_abiname == "elfv2" {
109+
let abi = if cx.target_spec().options.llvm_abiname == LlvmAbi::ElfV2 {
110110
ELFv2
111-
} else if cx.target_spec().options.llvm_abiname == "elfv1" {
111+
} else if cx.target_spec().options.llvm_abiname == LlvmAbi::ElfV1 {
112112
ELFv1
113113
} else if cx.target_spec().os == Os::Aix {
114114
AIX

compiler/rustc_target/src/callconv/riscv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_abi::{
1010
};
1111

1212
use crate::callconv::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Uniform};
13-
use crate::spec::HasTargetSpec;
13+
use crate::spec::{HasTargetSpec, LlvmAbi};
1414

1515
#[derive(Copy, Clone)]
1616
enum RegPassKind {
@@ -419,9 +419,9 @@ where
419419
Ty: TyAbiInterface<'a, C> + Copy,
420420
C: HasDataLayout + HasTargetSpec,
421421
{
422-
let flen = match &cx.target_spec().llvm_abiname[..] {
423-
"ilp32f" | "lp64f" => 32,
424-
"ilp32d" | "lp64d" => 64,
422+
let flen = match &cx.target_spec().llvm_abiname {
423+
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => 32,
424+
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => 64,
425425
_ => 0,
426426
};
427427
let xlen = cx.data_layout().pointer_size().bits();

compiler/rustc_target/src/spec/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{
1212
TargetKind, TargetOptions, TargetWarnings, TlsModel,
1313
};
1414
use crate::json::{Json, ToJson};
15-
use crate::spec::AbiMap;
15+
use crate::spec::{AbiMap, LlvmAbi};
1616

1717
impl Target {
1818
/// Loads a target descriptor from a JSON object.
@@ -611,7 +611,7 @@ struct TargetSpecJson {
611611
#[serde(rename = "target-mcount")]
612612
mcount: Option<StaticCow<str>>,
613613
llvm_mcount_intrinsic: Option<StaticCow<str>>,
614-
llvm_abiname: Option<StaticCow<str>>,
614+
llvm_abiname: Option<LlvmAbi>,
615615
llvm_floatabi: Option<FloatAbi>,
616616
rustc_abi: Option<RustcAbi>,
617617
relax_elf_relocations: Option<bool>,

0 commit comments

Comments
 (0)