Skip to content

Commit bf80159

Browse files
committed
Make target-cpu=native detect individual features
1 parent 41601ef commit bf80159

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ pub fn target_machine_factory(
164164

165165
let code_model = to_llvm_code_model(sess.code_model());
166166

167-
let features = attributes::llvm_target_features(sess).collect::<Vec<_>>();
167+
let mut features = llvm_util::handle_native_features(sess);
168+
features.extend(attributes::llvm_target_features(sess).map(|s| s.to_owned()));
168169
let mut singlethread = sess.target.singlethread;
169170

170171
// On the wasm target once the `atomics` feature is enabled that means that

compiler/rustc_codegen_llvm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(in_band_lifetimes)]
1313
#![feature(nll)]
1414
#![feature(or_patterns)]
15+
#![feature(stdsimd)]
1516
#![recursion_limit = "256"]
1617

1718
use back::write::{create_informational_target_machine, create_target_machine};

compiler/rustc_codegen_llvm/src/llvm_util.rs

+20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_span::symbol::Symbol;
1010
use rustc_target::spec::{MergeFunctions, PanicStrategy};
1111
use std::ffi::CString;
1212

13+
use std::detect;
1314
use std::slice;
1415
use std::str;
1516
use std::sync::atomic::{AtomicBool, Ordering};
@@ -221,6 +222,25 @@ pub fn target_cpu(sess: &Session) -> &str {
221222
handle_native(name)
222223
}
223224

225+
pub fn handle_native_features(sess: &Session) -> Vec<String> {
226+
const LLVM_NOT_RECOGNIZED: &[&str] = &["tsc"];
227+
228+
match sess.opts.cg.target_cpu {
229+
Some(ref s) => {
230+
if s != "native" {
231+
return vec![];
232+
}
233+
234+
detect::features()
235+
.map(|(feature, support)| (to_llvm_feature(sess, feature), support))
236+
.filter(|(feature, _)| !LLVM_NOT_RECOGNIZED.contains(feature))
237+
.map(|(feature, support)| (if support { "+" } else { "-" }).to_owned() + feature)
238+
.collect()
239+
}
240+
None => vec![],
241+
}
242+
}
243+
224244
pub fn tune_cpu(sess: &Session) -> Option<&str> {
225245
match sess.opts.debugging_opts.tune_cpu {
226246
Some(ref s) => Some(handle_native(&**s)),

0 commit comments

Comments
 (0)