@@ -286,6 +286,19 @@ pub(crate) fn tune_cpu_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribu
286
286
. map ( |tune_cpu| llvm:: CreateAttrStringValue ( cx. llcx , "tune-cpu" , tune_cpu) )
287
287
}
288
288
289
+ /// Get the `target-features` LLVM attribute.
290
+ pub ( crate ) fn target_features_attr < ' ll > (
291
+ cx : & CodegenCx < ' ll , ' _ > ,
292
+ function_features : Vec < String > ,
293
+ ) -> Option < & ' ll Attribute > {
294
+ let global_features = cx. tcx . global_backend_features ( ( ) ) . iter ( ) . map ( String :: as_str) ;
295
+ let function_features = function_features. iter ( ) . map ( String :: as_str) ;
296
+ let target_features =
297
+ global_features. chain ( function_features) . intersperse ( "," ) . collect :: < String > ( ) ;
298
+ ( !target_features. is_empty ( ) )
299
+ . then ( || llvm:: CreateAttrStringValue ( cx. llcx , "target-features" , & target_features) )
300
+ }
301
+
289
302
/// Get the `NonLazyBind` LLVM attribute,
290
303
/// if the codegen options allow skipping the PLT.
291
304
pub ( crate ) fn non_lazy_bind_attr < ' ll > ( cx : & CodegenCx < ' ll , ' _ > ) -> Option < & ' ll Attribute > {
@@ -513,13 +526,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
513
526
}
514
527
}
515
528
516
- let global_features = cx. tcx . global_backend_features ( ( ) ) . iter ( ) . map ( |s| s. as_str ( ) ) ;
517
- let function_features = function_features. iter ( ) . map ( |s| s. as_str ( ) ) ;
518
- let target_features: String =
519
- global_features. chain ( function_features) . intersperse ( "," ) . collect ( ) ;
520
- if !target_features. is_empty ( ) {
521
- to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , "target-features" , & target_features) ) ;
522
- }
529
+ to_add. extend ( target_features_attr ( cx, function_features) ) ;
523
530
524
531
attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
525
532
}
0 commit comments