@@ -5,7 +5,7 @@ use rustc_hir::find_attr;
55use rustc_middle:: middle:: codegen_fn_attrs:: {
66 CodegenFnAttrFlags , CodegenFnAttrs , PatchableFunctionEntry , SanitizerFnAttrs , TargetFeature ,
77} ;
8- use rustc_middle:: ty:: { self , TyCtxt } ;
8+ use rustc_middle:: ty:: { self , Instance , TyCtxt } ;
99use rustc_session:: config:: { BranchProtection , FunctionReturn , OptLevel , PAuthKey , PacRet } ;
1010use rustc_span:: sym;
1111use rustc_symbol_mangling:: mangle_internal_symbol;
@@ -42,22 +42,31 @@ pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: &str) {
4242
4343/// Get LLVM attribute for the provided inline heuristic.
4444#[ inline]
45- fn inline_attr < ' ll > (
45+ pub ( crate ) fn inline_attr < ' tcx , ' ll > (
4646 cx : & SimpleCx < ' ll > ,
47- sess : & Session ,
48- inline : InlineAttr ,
47+ tcx : TyCtxt < ' tcx > ,
48+ instance : Instance < ' tcx > ,
49+ codegen_fn_attrs : & CodegenFnAttrs ,
4950) -> Option < & ' ll Attribute > {
50- if !sess. opts . unstable_opts . inline_llvm {
51+ if !tcx . sess . opts . unstable_opts . inline_llvm {
5152 // disable LLVM inlining
5253 return Some ( AttributeKind :: NoInline . create_attr ( cx. llcx ) ) ;
5354 }
55+
56+ // `optnone` requires `noinline`
57+ let inline = match ( codegen_fn_attrs. inline , & codegen_fn_attrs. optimize ) {
58+ ( _, OptimizeAttr :: DoNotOptimize ) => InlineAttr :: Never ,
59+ ( InlineAttr :: None , _) if instance. def . requires_inline ( tcx) => InlineAttr :: Hint ,
60+ ( inline, _) => inline,
61+ } ;
62+
5463 match inline {
5564 InlineAttr :: Hint => Some ( AttributeKind :: InlineHint . create_attr ( cx. llcx ) ) ,
5665 InlineAttr :: Always | InlineAttr :: Force { .. } => {
5766 Some ( AttributeKind :: AlwaysInline . create_attr ( cx. llcx ) )
5867 }
5968 InlineAttr :: Never => {
60- if sess. target . arch != Arch :: AmdGpu {
69+ if tcx . sess . target . arch != Arch :: AmdGpu {
6170 Some ( AttributeKind :: NoInline . create_attr ( cx. llcx ) )
6271 } else {
6372 None
@@ -412,14 +421,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
412421 }
413422
414423 if let Some ( instance) = instance {
415- // `optnone` requires `noinline`
416- let inline = match ( codegen_fn_attrs. inline , & codegen_fn_attrs. optimize ) {
417- ( _, OptimizeAttr :: DoNotOptimize ) => InlineAttr :: Never ,
418- ( InlineAttr :: None , _) if instance. def . requires_inline ( tcx) => InlineAttr :: Hint ,
419- ( inline, _) => inline,
420- } ;
421-
422- to_add. extend ( inline_attr ( cx, sess, inline) ) ;
424+ to_add. extend ( inline_attr ( cx, tcx, instance, codegen_fn_attrs) ) ;
423425 }
424426
425427 if sess. must_emit_unwind_tables ( ) {
0 commit comments