Skip to content

Commit

Permalink
Use LLVMGetHostCPUFeatures instead of stdsimd
Browse files Browse the repository at this point in the history
  • Loading branch information
as-com committed Jan 8, 2021
1 parent bf80159 commit bc4c5ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_codegen_llvm/src/lib.rs
Expand Up @@ -12,7 +12,6 @@
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(stdsimd)]
#![recursion_limit = "256"]

use back::write::{create_informational_target_machine, create_target_machine};
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Expand Up @@ -1708,6 +1708,10 @@ extern "C" {
PM: &PassManager<'_>,
);

pub fn LLVMGetHostCPUFeatures() -> *mut c_char;

pub fn LLVMDisposeMessage(message: *mut c_char);

// Stuff that's in llvm-wrapper/ because it's not upstream yet.

/// Opens an object file.
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Expand Up @@ -8,9 +8,8 @@ use rustc_session::config::PrintRequest;
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use std::ffi::CString;
use std::ffi::{CStr, CString};

use std::detect;
use std::slice;
use std::str;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down Expand Up @@ -223,19 +222,20 @@ pub fn target_cpu(sess: &Session) -> &str {
}

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()
let ptr = unsafe { llvm::LLVMGetHostCPUFeatures() };
let str = unsafe { CStr::from_ptr(ptr).to_string_lossy() };

let features = str.split(",").map(|s| s.to_owned()).collect();

unsafe { llvm::LLVMDisposeMessage(ptr) };

features
}
None => vec![],
}
Expand Down

0 comments on commit bc4c5ba

Please sign in to comment.