2
2
use gccjit:: FnAttribute ;
3
3
use gccjit:: Function ;
4
4
use rustc_attr:: InstructionSetAttr ;
5
+ #[ cfg( feature="master" ) ]
6
+ use rustc_attr:: InlineAttr ;
5
7
use rustc_codegen_ssa:: target_features:: tied_target_features;
6
8
use rustc_data_structures:: fx:: FxHashMap ;
7
9
use rustc_middle:: ty;
10
+ #[ cfg( feature="master" ) ]
11
+ use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
8
12
use rustc_session:: Session ;
9
13
use rustc_span:: symbol:: sym;
10
14
use smallvec:: { smallvec, SmallVec } ;
@@ -67,6 +71,24 @@ fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
67
71
}
68
72
}
69
73
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
+
70
92
/// Composite function which sets GCC attributes for function depending on its AST (`#[attribute]`)
71
93
/// attributes.
72
94
pub fn from_fn_attrs < ' gcc , ' tcx > (
@@ -77,6 +99,23 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
77
99
) {
78
100
let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
79
101
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
+
80
119
let function_features =
81
120
codegen_fn_attrs. target_features . iter ( ) . map ( |features| features. as_str ( ) ) . collect :: < Vec < & str > > ( ) ;
82
121
0 commit comments