1
Fork 0

Rollup merge of #131010 - RalfJung:target-cpu-native, r=jieyouxu

extend comment in global_llvm_features regarding target-cpu=native

Based on the description in https://github.com/rust-lang/rust/pull/83084 by `@nagisa` -- seems better to have this in the code, where it is easier to find.
This commit is contained in:
Guillaume Gomez 2024-09-29 12:37:53 +02:00 committed by GitHub
commit e9c9307d36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -536,6 +536,11 @@ pub(crate) fn global_llvm_features(
// -Ctarget-cpu=native // -Ctarget-cpu=native
match sess.opts.cg.target_cpu { match sess.opts.cg.target_cpu {
Some(ref s) if s == "native" => { Some(ref s) if s == "native" => {
// We have already figured out the actual CPU name with `LLVMRustGetHostCPUName` and set
// that for LLVM, so the features implied by that CPU name will be available everywhere.
// However, that is not sufficient: e.g. `skylake` alone is not sufficient to tell if
// some of the instructions are available or not. So we have to also explicitly ask for
// the exact set of features available on the host, and enable all of them.
let features_string = unsafe { let features_string = unsafe {
let ptr = llvm::LLVMGetHostCPUFeatures(); let ptr = llvm::LLVMGetHostCPUFeatures();
let features_string = if !ptr.is_null() { let features_string = if !ptr.is_null() {