@@ -41,20 +41,13 @@ pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: &str) {
4141}
4242
4343/// Get LLVM attribute for the provided inline heuristic.
44- pub ( crate ) fn inline_attr < ' ll , ' tcx > (
44+ #[ inline]
45+ fn inline_attr < ' ll > (
4546 cx : & SimpleCx < ' ll > ,
46- tcx : TyCtxt < ' tcx > ,
47- instance : ty :: Instance < ' tcx > ,
47+ sess : & Session ,
48+ inline : InlineAttr ,
4849) -> Option < & ' ll Attribute > {
49- // `optnone` requires `noinline`
50- let codegen_fn_attrs = tcx. codegen_fn_attrs ( instance. def_id ( ) ) ;
51- let inline = match ( codegen_fn_attrs. inline , & codegen_fn_attrs. optimize ) {
52- ( _, OptimizeAttr :: DoNotOptimize ) => InlineAttr :: Never ,
53- ( InlineAttr :: None , _) if instance. def . requires_inline ( tcx) => InlineAttr :: Hint ,
54- ( inline, _) => inline,
55- } ;
56-
57- if !tcx. sess . opts . unstable_opts . inline_llvm {
50+ if !sess. opts . unstable_opts . inline_llvm {
5851 // disable LLVM inlining
5952 return Some ( AttributeKind :: NoInline . create_attr ( cx. llcx ) ) ;
6053 }
@@ -64,7 +57,7 @@ pub(crate) fn inline_attr<'ll, 'tcx>(
6457 Some ( AttributeKind :: AlwaysInline . create_attr ( cx. llcx ) )
6558 }
6659 InlineAttr :: Never => {
67- if tcx . sess . target . arch != Arch :: AmdGpu {
60+ if sess. target . arch != Arch :: AmdGpu {
6861 Some ( AttributeKind :: NoInline . create_attr ( cx. llcx ) )
6962 } else {
7063 None
@@ -418,6 +411,17 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
418411 OptimizeAttr :: Speed => { }
419412 }
420413
414+ 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) ) ;
423+ }
424+
421425 if sess. must_emit_unwind_tables ( ) {
422426 to_add. push ( uwtable_attr ( cx. llcx , sess. opts . unstable_opts . use_sync_unwind ) ) ;
423427 }
@@ -568,16 +572,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
568572 let function_features =
569573 codegen_fn_attrs. target_features . iter ( ) . map ( |f| f. name . as_str ( ) ) . collect :: < Vec < & str > > ( ) ;
570574
571- // Apply function attributes as per usual if there are no user defined
572- // target features otherwise this will get applied at the callsite.
573- if function_features. is_empty ( ) {
574- if let Some ( instance) = instance
575- && let Some ( inline_attr) = inline_attr ( cx, tcx, instance)
576- {
577- to_add. push ( inline_attr) ;
578- }
579- }
580-
581575 let function_features = function_features
582576 . iter ( )
583577 // Convert to LLVMFeatures and filter out unavailable ones
0 commit comments