Skip to content

Commit bc4c5ba

Browse files
committed
Use LLVMGetHostCPUFeatures instead of stdsimd
1 parent bf80159 commit bc4c5ba

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

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

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

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,10 @@ extern "C" {
17081708
PM: &PassManager<'_>,
17091709
);
17101710

1711+
pub fn LLVMGetHostCPUFeatures() -> *mut c_char;
1712+
1713+
pub fn LLVMDisposeMessage(message: *mut c_char);
1714+
17111715
// Stuff that's in llvm-wrapper/ because it's not upstream yet.
17121716

17131717
/// Opens an object file.

compiler/rustc_codegen_llvm/src/llvm_util.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use rustc_session::config::PrintRequest;
88
use rustc_session::Session;
99
use rustc_span::symbol::Symbol;
1010
use rustc_target::spec::{MergeFunctions, PanicStrategy};
11-
use std::ffi::CString;
11+
use std::ffi::{CStr, CString};
1212

13-
use std::detect;
1413
use std::slice;
1514
use std::str;
1615
use std::sync::atomic::{AtomicBool, Ordering};
@@ -223,19 +222,20 @@ pub fn target_cpu(sess: &Session) -> &str {
223222
}
224223

225224
pub fn handle_native_features(sess: &Session) -> Vec<String> {
226-
const LLVM_NOT_RECOGNIZED: &[&str] = &["tsc"];
227-
228225
match sess.opts.cg.target_cpu {
229226
Some(ref s) => {
230227
if s != "native" {
231228
return vec![];
232229
}
233230

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()
231+
let ptr = unsafe { llvm::LLVMGetHostCPUFeatures() };
232+
let str = unsafe { CStr::from_ptr(ptr).to_string_lossy() };
233+
234+
let features = str.split(",").map(|s| s.to_owned()).collect();
235+
236+
unsafe { llvm::LLVMDisposeMessage(ptr) };
237+
238+
features
239239
}
240240
None => vec![],
241241
}

0 commit comments

Comments
 (0)