Skip to content

Commit aab0757

Browse files
committed
Only disable folded features when it makes sense.
Some features that are tied together only make sense to be folded together when enabling the feature. For example on AArch64 sve and neon are tied together, however it doesn't make sense to disable neon when disabling sve.
1 parent 4cca436 commit aab0757

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+31-5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ pub fn time_trace_profiler_finish(file_name: &Path) {
147147
// Though note that Rust can also be build with an external precompiled version of LLVM
148148
// which might lead to failures if the oldest tested / supported LLVM version
149149
// doesn't yet support the relevant intrinsics
150+
//
151+
// Note: The first feature in the list that is returned is the mapping to the feature that is
152+
// provided from the `s` parameter.
150153
pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
151154
let arch = if sess.target.arch == "x86_64" { "x86" } else { &*sess.target.arch };
152155
match (arch, s) {
@@ -182,6 +185,23 @@ pub fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]
182185
}
183186
}
184187

188+
pub enum TargetFeatureFoldStrength {
189+
// The feature is only tied when enabling the feature, disabling
190+
// this feature shouldn't disable the tied feature.
191+
EnableOnly,
192+
// The feature is tied for both enabling and disabling this feature.
193+
Both,
194+
}
195+
196+
// Determines how the features are folded together, some features are
197+
// linked a lot more than some others.
198+
pub fn feature_fold_strength<'a>(feats: &SmallVec<[&'a str; 2]>) -> TargetFeatureFoldStrength {
199+
match (feats.get(0), feats.get(1)) {
200+
(Some(&"neon"), Some(&"fp-armv8")) => TargetFeatureFoldStrength::Both,
201+
_ => TargetFeatureFoldStrength::EnableOnly,
202+
}
203+
}
204+
185205
/// Given a map from target_features to whether they are enabled or disabled,
186206
/// ensure only valid combinations are allowed.
187207
pub fn check_tied_features(
@@ -471,11 +491,17 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
471491
// passing requests down to LLVM. This means that all in-language
472492
// features also work on the command line instead of having two
473493
// different names when the LLVM name and the Rust name differ.
474-
Some(
475-
to_llvm_features(sess, feature)
476-
.into_iter()
477-
.map(move |f| format!("{}{}", enable_disable, f)),
478-
)
494+
let llvm_features = to_llvm_features(sess, feature);
495+
Some(to_llvm_features(sess, feature).into_iter().enumerate().filter_map(
496+
move |(idx, f)| match (enable_disable, feature_fold_strength(&llvm_features)) {
497+
('-' | '+', TargetFeatureFoldStrength::Both)
498+
| ('+', TargetFeatureFoldStrength::EnableOnly) => {
499+
Some(format!("{}{}", enable_disable, f))
500+
}
501+
_ if idx == 0 => Some(format!("{}{}", enable_disable, f)),
502+
_ => None,
503+
},
504+
))
479505
})
480506
.flatten();
481507
features.extend(feats);
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ignore-tidy-linelength
2+
// revisions: ENABLE_SVE DISABLE_SVE DISABLE_NEON ENABLE_NEON
3+
// compile-flags: --crate-type=rlib --target=aarch64-unknown-linux-gnu
4+
// needs-llvm-components: aarch64
5+
6+
// [ENABLE_SVE] compile-flags: -C target-feature=+sve
7+
// ENABLE_SVE: attributes #0 = { {{.*}} "target-features"="+outline-atomics,+sve,+neon,+v8a" }
8+
9+
// [DISABLE_SVE] compile-flags: -C target-feature=-sve
10+
// DISABLE_SVE: attributes #0 = { {{.*}} "target-features"="+outline-atomics,-sve,+v8a" }
11+
12+
// [DISABLE_NEON] compile-flags: -C target-feature=-neon
13+
// DISABLE_NEON: attributes #0 = { {{.*}} "target-features"="+outline-atomics,-neon,-fp-armv8,+v8a" }
14+
15+
// [ENABLE_NEON] compile-flags: -C target-feature=+neon
16+
// ENABLE_NEON: attributes #0 = { {{.*}} "target-features"="+outline-atomics,+neon,+fp-armv8,+v8a" }
17+
18+
19+
#![feature(no_core, lang_items)]
20+
#![no_core]
21+
22+
#[lang = "sized"]
23+
trait Sized {}
24+
25+
pub fn test() {}

0 commit comments

Comments
 (0)