22use gccjit:: FnAttribute ;
33use gccjit:: Function ;
44use rustc_attr:: InstructionSetAttr ;
5+ #[ cfg( feature="master" ) ]
6+ use rustc_attr:: InlineAttr ;
57use rustc_codegen_ssa:: target_features:: tied_target_features;
68use rustc_data_structures:: fx:: FxHashMap ;
79use rustc_middle:: ty;
10+ #[ cfg( feature="master" ) ]
11+ use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
812use rustc_session:: Session ;
913use rustc_span:: symbol:: sym;
1014use smallvec:: { smallvec, SmallVec } ;
@@ -67,6 +71,24 @@ fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
6771 }
6872}
6973
74+ /// Get GCC attribute for the provided inline heuristic.
75+ #[ cfg( feature="master" ) ]
76+ #[ inline]
77+ fn inline_attr < ' gcc , ' tcx > ( cx : & CodegenCx < ' gcc , ' tcx > , inline : InlineAttr ) -> Option < FnAttribute < ' gcc > > {
78+ match inline {
79+ InlineAttr :: Hint => Some ( FnAttribute :: Inline ) ,
80+ InlineAttr :: Always => Some ( FnAttribute :: AlwaysInline ) ,
81+ InlineAttr :: Never => {
82+ if cx. sess ( ) . target . arch != "amdgpu" {
83+ Some ( FnAttribute :: NoInline )
84+ } else {
85+ None
86+ }
87+ }
88+ InlineAttr :: None => None ,
89+ }
90+ }
91+
7092/// Composite function which sets GCC attributes for function depending on its AST (`#[attribute]`)
7193/// attributes.
7294pub fn from_fn_attrs < ' gcc , ' tcx > (
@@ -77,6 +99,23 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
7799) {
78100 let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
79101
102+ #[ cfg( feature="master" ) ]
103+ {
104+ let inline =
105+ if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: NAKED ) {
106+ InlineAttr :: Never
107+ }
108+ else if codegen_fn_attrs. inline == InlineAttr :: None && instance. def . requires_inline ( cx. tcx ) {
109+ InlineAttr :: Hint
110+ }
111+ else {
112+ codegen_fn_attrs. inline
113+ } ;
114+ if let Some ( attr) = inline_attr ( cx, inline) {
115+ func. add_attribute ( attr) ;
116+ }
117+ }
118+
80119 let function_features =
81120 codegen_fn_attrs. target_features . iter ( ) . map ( |features| features. as_str ( ) ) . collect :: < Vec < & str > > ( ) ;
82121
0 commit comments