Skip to content

Commit

Permalink
arm: use target.abi over soft-float target feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 28, 2024
1 parent 5c6ed53 commit 958f3f3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
10 changes: 9 additions & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3168,14 +3168,22 @@ impl Target {
self.llvm_abiname,
);
}
"aarch64" => {
"aarch64" | "arm64ec" => {
check_matches!(
&*self.abi,
"softfloat" | "uwp" | "llvm" | "macabi" | "sim" | "ilp32" | "",
"invalid aarch64 ABI name: {}",
self.abi,
)
}
"arm" => {
check_matches!(
&*self.abi,
"eabi" | "eabihf" | "uwp" | "macabi" | "sim" | "",
"invalid aarch64 ABI name: {}",
self.abi,
)
}
_ => {}
}

Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("flagm", Stable, &[]),
// FEAT_FLAGM2
("flagm2", Unstable(sym::aarch64_unstable_target_feature), &[]),
// We forbid directly toggling just `fp-armv8`; it must be toggled with `neon`.
("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]),
// FEAT_FP16
// Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
Expand Down Expand Up @@ -758,6 +759,7 @@ impl Target {
match &*self.arch {
"x86" => {
// We support 2 ABIs, hardfloat (default) and softfloat.
// x86 has no sane ABI indicator so we have to use the target feature.
if self.has_feature("soft-float") {
NOTHING
} else {
Expand All @@ -767,6 +769,7 @@ impl Target {
}
"x86_64" => {
// We support 2 ABIs, hardfloat (default) and softfloat.
// x86 has no sane ABI indicator so we have to use the target feature.
if self.has_feature("soft-float") {
NOTHING
} else {
Expand All @@ -775,20 +778,20 @@ impl Target {
}
}
"arm" => {
// We support 2 ABIs, hardfloat (default) and softfloat.
if self.has_feature("soft-float") {
NOTHING
} else {
// Hardfloat ABI. x87 must be enabled.
(&["fpregs"], &[])
// It's unclear how the `abi` and the `soft-float` target feature interact.
// We use the `abi` as our primary signal, and force `soft-float` to match.
match &*self.abi {
"eabi" => (&["soft-float"], &[]),
"eabihf" | "uwp" | "macabi" | "sim" | "" => (&["fpregs"], &["soft-float"]),
_ => unreachable!(),
}
}
"aarch64" | "arm64ec" => {
match &*self.abi {
"softfloat" => {
// This is not fully correct, LLVM actually doesn't let us enforce the softfloat
// ABI properly... see <https://github.com/rust-lang/rust/issues/134375>.
// FIXME: should be forbid "neon" here? But that would be a breaking change.
// FIXME: should we forbid "neon" here? But that would be a breaking change.
NOTHING
}
"uwp" | "llvm" | "macabi" | "sim" | "ilp32" | "" => {
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/tied-features-strength.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ignore-tidy-linelength
//@ revisions: ENABLE_SVE DISABLE_SVE ENABLE_NEON
//@ revisions: ENABLE_SVE DISABLE_SVE DISABLE_NEON ENABLE_NEON
//@ compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu
//@ needs-llvm-components: aarch64

Expand All @@ -13,9 +13,9 @@
//@ [DISABLE_SVE] compile-flags: -C target-feature=-sve -Copt-level=0
// DISABLE_SVE: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(-sve,?)|(\+neon,?)|(\+fp-armv8,?))*}}" }

// The DISABLE_NEON is disabled since neon is a required target feature for this targt, it cannot be disabled.
// it would have: compile-flags: -C target-feature=-neon -Copt-level=0
// DISABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(-fp-armv8,?)|(-neon,?))*}}" }
//@ [DISABLE_NEON] compile-flags: -C target-feature=-neon -Copt-level=0
// `neon` and `fp-armv8` get enabled as target base features, but then disabled again at the end of the list.
// DISABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fp-armv8,?)|(\+neon,?))*}},-neon,-fp-armv8{{(,\+fpmr)?}}" }

//@ [ENABLE_NEON] compile-flags: -C target-feature=+neon -Copt-level=0
// ENABLE_NEON: attributes #0 = { {{.*}} "target-features"="{{((\+outline-atomics,?)|(\+v8a,?)|(\+fpmr,?)?|(\+fp-armv8,?)|(\+neon,?))*}}" }
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/simd-ffi/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() {
.target(&target)
.emit("llvm-ir,asm")
.input("simd.rs")
.arg("-Ctarget-feature=+neon,+sse")
.arg("-Ctarget-feature=-soft-float,+neon,+sse")
.arg(&format!("-Cextra-filename=-{target}"))
.run();
}
Expand Down

0 comments on commit 958f3f3

Please sign in to comment.