diff options
| author | Andrew Sun <me@andrewsun.com> | 2021-01-06 03:23:54 -0500 |
|---|---|---|
| committer | Andrew Sun <me@andrewsun.com> | 2021-01-06 03:23:54 -0500 |
| commit | bf801590503447cc5b1ddd520b39d2957d90368b (patch) | |
| tree | f56dd8a57494ba3938a46f40497ce1452c042c2e /compiler/rustc_codegen_llvm/src/llvm_util.rs | |
| parent | 41601ef39442bca19bc6ac8ef72e5d89335e92d7 (diff) | |
| download | rust-bf801590503447cc5b1ddd520b39d2957d90368b.tar.gz rust-bf801590503447cc5b1ddd520b39d2957d90368b.zip | |
Make target-cpu=native detect individual features
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm_util.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/llvm_util.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index a3139ce5a34..2da06e6babe 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -10,6 +10,7 @@ use rustc_span::symbol::Symbol; use rustc_target::spec::{MergeFunctions, PanicStrategy}; use std::ffi::CString; +use std::detect; use std::slice; use std::str; use std::sync::atomic::{AtomicBool, Ordering}; @@ -221,6 +222,25 @@ pub fn target_cpu(sess: &Session) -> &str { handle_native(name) } +pub fn handle_native_features(sess: &Session) -> Vec<String> { + const LLVM_NOT_RECOGNIZED: &[&str] = &["tsc"]; + + match sess.opts.cg.target_cpu { + Some(ref s) => { + if s != "native" { + return vec![]; + } + + detect::features() + .map(|(feature, support)| (to_llvm_feature(sess, feature), support)) + .filter(|(feature, _)| !LLVM_NOT_RECOGNIZED.contains(feature)) + .map(|(feature, support)| (if support { "+" } else { "-" }).to_owned() + feature) + .collect() + } + None => vec![], + } +} + pub fn tune_cpu(sess: &Session) -> Option<&str> { match sess.opts.debugging_opts.tune_cpu { Some(ref s) => Some(handle_native(&**s)), |
