@@ -296,6 +296,19 @@ pub(crate) fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribu
296296 . map ( |tune_cpu| llvm:: CreateAttrStringValue ( cx. llcx , "tune-cpu" , tune_cpu) )
297297}
298298
299+ /// Get the `target-features` LLVM attribute.
300+ pub ( crate ) fn target_features_attr < ' ll > (
301+ cx : & CodegenCx < ' ll , ' _ > ,
302+ function_features : Vec < String > ,
303+ ) -> Option < & ' ll Attribute > {
304+ let global_features = cx. tcx . global_backend_features ( ( ) ) . iter ( ) . map ( String :: as_str) ;
305+ let function_features = function_features. iter ( ) . map ( String :: as_str) ;
306+ let target_features =
307+ global_features. chain ( function_features) . intersperse ( "," ) . collect :: < String > ( ) ;
308+ ( !target_features. is_empty ( ) )
309+ . then ( || llvm:: CreateAttrStringValue ( cx. llcx , "target-features" , & target_features) )
310+ }
311+
299312/// Get the `NonLazyBind` LLVM attribute,
300313/// if the codegen options allow skipping the PLT.
301314pub ( crate ) fn non_lazy_bind_attr < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> Option < & ' ll Attribute > {
@@ -523,14 +536,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
523536 }
524537 }
525538
526- let global_features = cx. tcx . global_backend_features ( ( ) ) . iter ( ) . map ( |s| s. as_str ( ) ) ;
527- let function_features = function_features. iter ( ) . map ( |s| s. as_str ( ) ) ;
528- let target_features: String =
529- global_features. chain ( function_features) . intersperse ( "," ) . collect ( ) ;
530-
531- if !target_features. is_empty ( ) {
532- to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , "target-features" , & target_features) ) ;
533- }
539+ to_add. extend ( target_features_attr ( cx, function_features) ) ;
534540
535541 attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
536542}
0 commit comments