Skip to content

Commit 102a5d8

Browse files
committed
Print all features with --print target-features, including aliases and tied features
1 parent c5d82ed commit 102a5d8

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,33 @@ fn llvm_target_features(tm: &llvm::TargetMachine) -> Vec<(&str, &str)> {
292292
}
293293

294294
fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
295-
let mut target_features = llvm_target_features(tm);
295+
let mut llvm_target_features = llvm_target_features(tm);
296+
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
296297
let mut rustc_target_features = supported_target_features(sess)
297298
.iter()
298-
.filter_map(|(feature, _gate)| {
299-
for llvm_feature in to_llvm_features(sess, *feature) {
299+
.map(|(feature, _gate)| {
300+
let desc = if let Some(llvm_feature) = to_llvm_features(sess, *feature).first() {
300301
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
301-
match target_features.binary_search_by_key(&llvm_feature, |(f, _d)| f).ok().map(
302-
|index| {
303-
let (_f, desc) = target_features.remove(index);
304-
(*feature, desc)
305-
},
306-
) {
307-
Some(v) => return Some(v),
308-
None => {}
302+
match llvm_target_features.binary_search_by_key(&llvm_feature, |(f, _d)| f).ok() {
303+
Some(index) => {
304+
known_llvm_target_features.insert(llvm_feature);
305+
llvm_target_features[index].1
306+
}
307+
None => "",
309308
}
310-
}
311-
None
309+
} else {
310+
""
311+
};
312+
(*feature, desc)
312313
})
313314
.collect::<Vec<_>>();
314315
rustc_target_features.extend_from_slice(&[(
315316
"crt-static",
316317
"Enables C Run-time Libraries to be statically linked",
317318
)]);
318-
let max_feature_len = target_features
319+
llvm_target_features.retain(|(f, _d)| !known_llvm_target_features.contains(f));
320+
321+
let max_feature_len = llvm_target_features
319322
.iter()
320323
.chain(rustc_target_features.iter())
321324
.map(|(feature, _desc)| feature.len())
@@ -327,10 +330,10 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
327330
println!(" {1:0$} - {2}.", max_feature_len, feature, desc);
328331
}
329332
println!("\nCode-generation features supported by LLVM for this target:");
330-
for (feature, desc) in &target_features {
333+
for (feature, desc) in &llvm_target_features {
331334
println!(" {1:0$} - {2}.", max_feature_len, feature, desc);
332335
}
333-
if target_features.is_empty() {
336+
if llvm_target_features.is_empty() {
334337
println!(" Target features listing is not supported by this LLVM version.");
335338
}
336339
println!("\nUse +feature to enable a feature, or -feature to disable it.");

0 commit comments

Comments
 (0)