1
1
#[ cfg( feature="master" ) ]
2
2
use gccjit:: FnAttribute ;
3
3
use gccjit:: Function ;
4
- use rustc_attr:: InstructionSetAttr ;
4
+ use rustc_attr:: { InlineAttr , InstructionSetAttr } ;
5
5
use rustc_codegen_ssa:: target_features:: tied_target_features;
6
6
use rustc_data_structures:: fx:: FxHashMap ;
7
7
use rustc_middle:: ty;
8
+ use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
8
9
use rustc_session:: Session ;
9
10
use rustc_span:: symbol:: sym;
10
11
use smallvec:: { smallvec, SmallVec } ;
@@ -67,6 +68,23 @@ fn to_gcc_features<'a>(sess: &Session, s: &'a str) -> SmallVec<[&'a str; 2]> {
67
68
}
68
69
}
69
70
71
+ /// Get GCC attribute for the provided inline heuristic.
72
+ #[ inline]
73
+ fn inline_attr < ' gcc , ' tcx > ( cx : & CodegenCx < ' gcc , ' tcx > , inline : InlineAttr ) -> Option < FnAttribute < ' gcc > > {
74
+ match inline {
75
+ InlineAttr :: Hint => Some ( FnAttribute :: Inline ) ,
76
+ InlineAttr :: Always => Some ( FnAttribute :: AlwaysInline ) ,
77
+ InlineAttr :: Never => {
78
+ if cx. sess ( ) . target . arch != "amdgpu" {
79
+ Some ( FnAttribute :: NoInline )
80
+ } else {
81
+ None
82
+ }
83
+ }
84
+ InlineAttr :: None => None ,
85
+ }
86
+ }
87
+
70
88
/// Composite function which sets GCC attributes for function depending on its AST (`#[attribute]`)
71
89
/// attributes.
72
90
pub fn from_fn_attrs < ' gcc , ' tcx > (
@@ -77,6 +95,21 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
77
95
) {
78
96
let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
79
97
98
+ // TODO: disable for libgccjit12?
99
+ let inline =
100
+ if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: NAKED ) {
101
+ InlineAttr :: Never
102
+ }
103
+ else if codegen_fn_attrs. inline == InlineAttr :: None && instance. def . requires_inline ( cx. tcx ) {
104
+ InlineAttr :: Hint
105
+ }
106
+ else {
107
+ codegen_fn_attrs. inline
108
+ } ;
109
+ if let Some ( attr) = inline_attr ( cx, inline) {
110
+ func. add_attribute ( attr) ;
111
+ }
112
+
80
113
let function_features =
81
114
codegen_fn_attrs. target_features . iter ( ) . map ( |features| features. as_str ( ) ) . collect :: < Vec < & str > > ( ) ;
82
115
0 commit comments