@@ -306,26 +306,34 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
306306pub ( crate ) fn target_config ( sess : & Session ) -> TargetConfig {
307307 let target_machine = create_informational_target_machine ( sess, true ) ;
308308
309- let ( unstable_target_features, target_features) = cfg_target_feature ( sess, |feature| {
310- // This closure determines whether the target CPU has the feature according to LLVM. We do
311- // *not* consider the `-Ctarget-feature`s here, as that will be handled later in
312- // `cfg_target_feature`.
313- if let Some ( feat) = to_llvm_features ( sess, feature) {
314- // All the LLVM features this expands to must be enabled.
315- for llvm_feature in feat {
316- let cstr = SmallCStr :: new ( llvm_feature) ;
317- // `LLVMRustHasFeature` is moderately expensive. On targets with many
318- // features (e.g. x86) these calls take a non-trivial fraction of runtime
319- // when compiling very small programs.
320- if !unsafe { llvm:: LLVMRustHasFeature ( target_machine. raw ( ) , cstr. as_ptr ( ) ) } {
321- return false ;
309+ let ( unstable_target_features, target_features) = cfg_target_feature (
310+ sess,
311+ |feature| {
312+ to_llvm_features ( sess, feature)
313+ . map ( |f| SmallVec :: < [ & str ; 2 ] > :: from_iter ( f. into_iter ( ) ) )
314+ . unwrap_or_default ( )
315+ } ,
316+ |feature| {
317+ // This closure determines whether the target CPU has the feature according to LLVM. We do
318+ // *not* consider the `-Ctarget-feature`s here, as that will be handled later in
319+ // `cfg_target_feature`.
320+ if let Some ( feat) = to_llvm_features ( sess, feature) {
321+ // All the LLVM features this expands to must be enabled.
322+ for llvm_feature in feat {
323+ let cstr = SmallCStr :: new ( llvm_feature) ;
324+ // `LLVMRustHasFeature` is moderately expensive. On targets with many
325+ // features (e.g. x86) these calls take a non-trivial fraction of runtime
326+ // when compiling very small programs.
327+ if !unsafe { llvm:: LLVMRustHasFeature ( target_machine. raw ( ) , cstr. as_ptr ( ) ) } {
328+ return false ;
329+ }
322330 }
331+ true
332+ } else {
333+ false
323334 }
324- true
325- } else {
326- false
327- }
328- } ) ;
335+ } ,
336+ ) ;
329337
330338 let mut cfg = TargetConfig {
331339 target_features,
@@ -630,11 +638,7 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {
630638
631639/// The list of LLVM features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
632640/// `--target` and similar).
633- pub ( crate ) fn global_llvm_features (
634- sess : & Session ,
635- diagnostics : bool ,
636- only_base_features : bool ,
637- ) -> Vec < String > {
641+ pub ( crate ) fn global_llvm_features ( sess : & Session , only_base_features : bool ) -> Vec < String > {
638642 // Features that come earlier are overridden by conflicting features later in the string.
639643 // Typically we'll want more explicit settings to override the implicit ones, so:
640644 //
@@ -694,39 +698,27 @@ pub(crate) fn global_llvm_features(
694698
695699 // -Ctarget-features
696700 if !only_base_features {
697- target_features:: flag_to_backend_features (
698- sess,
699- diagnostics,
700- |feature| {
701- to_llvm_features ( sess, feature)
702- . map ( |f| SmallVec :: < [ & str ; 2 ] > :: from_iter ( f. into_iter ( ) ) )
703- . unwrap_or_default ( )
704- } ,
705- |feature, enable| {
706- let enable_disable = if enable { '+' } else { '-' } ;
707- // We run through `to_llvm_features` when
708- // passing requests down to LLVM. This means that all in-language
709- // features also work on the command line instead of having two
710- // different names when the LLVM name and the Rust name differ.
711- let Some ( llvm_feature) = to_llvm_features ( sess, feature) else { return } ;
712-
713- features. extend (
714- std:: iter:: once ( format ! (
715- "{}{}" ,
716- enable_disable, llvm_feature. llvm_feature_name
717- ) )
718- . chain ( llvm_feature. dependencies . into_iter ( ) . filter_map (
719- move |feat| match ( enable, feat) {
701+ target_features:: flag_to_backend_features ( sess, |feature, enable| {
702+ let enable_disable = if enable { '+' } else { '-' } ;
703+ // We run through `to_llvm_features` when
704+ // passing requests down to LLVM. This means that all in-language
705+ // features also work on the command line instead of having two
706+ // different names when the LLVM name and the Rust name differ.
707+ let Some ( llvm_feature) = to_llvm_features ( sess, feature) else { return } ;
708+
709+ features. extend (
710+ std:: iter:: once ( format ! ( "{}{}" , enable_disable, llvm_feature. llvm_feature_name) )
711+ . chain ( llvm_feature. dependencies . into_iter ( ) . filter_map ( move |feat| {
712+ match ( enable, feat) {
720713 ( _, TargetFeatureFoldStrength :: Both ( f) )
721714 | ( true , TargetFeatureFoldStrength :: EnableOnly ( f) ) => {
722715 Some ( format ! ( "{enable_disable}{f}" ) )
723716 }
724717 _ => None ,
725- } ,
726- ) ) ,
727- )
728- } ,
729- ) ;
718+ }
719+ } ) ) ,
720+ )
721+ } ) ;
730722 }
731723
732724 // We add this in the "base target" so that these show up in `sess.unstable_target_features`.
0 commit comments