@@ -8,11 +8,12 @@ use rustc_middle::bug;
88use rustc_middle:: ty:: TyCtxt ;
99use rustc_session:: config:: { DebugInfo , OomStrategy } ;
1010use rustc_symbol_mangling:: mangle_internal_symbol;
11+ use smallvec:: SmallVec ;
1112
1213use crate :: builder:: SBuilder ;
1314use crate :: declare:: declare_simple_fn;
1415use crate :: llvm:: { self , False , True , Type , Value } ;
15- use crate :: { SimpleCx , attributes, debuginfo} ;
16+ use crate :: { SimpleCx , attributes, debuginfo, llvm_util } ;
1617
1718pub ( crate ) unsafe fn codegen (
1819 tcx : TyCtxt < ' _ > ,
@@ -147,6 +148,20 @@ fn create_wrapper_function(
147148 llvm:: Visibility :: from_generic ( tcx. sess . default_visibility ( ) ) ,
148149 ty,
149150 ) ;
151+
152+ let mut attrs = SmallVec :: < [ _ ; 2 ] > :: new ( ) ;
153+
154+ let target_cpu = llvm_util:: target_cpu ( tcx. sess ) ;
155+ let target_cpu_attr = llvm:: CreateAttrStringValue ( cx. llcx , "target-cpu" , target_cpu) ;
156+
157+ let tune_cpu_attr = llvm_util:: tune_cpu ( tcx. sess )
158+ . map ( |tune_cpu| llvm:: CreateAttrStringValue ( cx. llcx , "tune-cpu" , tune_cpu) ) ;
159+
160+ attrs. push ( target_cpu_attr) ;
161+ attrs. extend ( tune_cpu_attr) ;
162+
163+ attributes:: apply_to_llfn ( llfn, llvm:: AttributePlace :: Function , & attrs) ;
164+
150165 let no_return = if no_return {
151166 // -> ! DIFlagNoReturn
152167 let no_return = llvm:: AttributeKind :: NoReturn . create_attr ( cx. llcx ) ;
0 commit comments