@@ -28,12 +28,6 @@ pub fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
28
28
}
29
29
}
30
30
31
- pub fn remove_from_llfn ( llfn : & Value , idx : AttributePlace , attrs : & [ AttributeKind ] ) {
32
- if !attrs. is_empty ( ) {
33
- llvm:: RemoveFunctionAttributes ( llfn, idx, attrs) ;
34
- }
35
- }
36
-
37
31
pub fn apply_to_callsite ( callsite : & Value , idx : AttributePlace , attrs : & [ & Attribute ] ) {
38
32
if !attrs. is_empty ( ) {
39
33
llvm:: AddCallSiteAttributes ( callsite, idx, attrs) ;
@@ -217,38 +211,23 @@ pub fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute
217
211
}
218
212
}
219
213
220
- /// Returns attributes to remove and to add, respectively,
221
- /// to set the default optimizations attrs on a function.
214
+ /// Get the default optimizations attrs for a function.
222
215
#[ inline]
223
216
pub ( crate ) fn default_optimisation_attrs < ' ll > (
224
217
cx : & CodegenCx < ' ll , ' _ > ,
225
- ) -> (
226
- // Attributes to remove
227
- SmallVec < [ AttributeKind ; 3 ] > ,
228
- // Attributes to add
229
- SmallVec < [ & ' ll Attribute ; 2 ] > ,
230
- ) {
231
- let mut to_remove = SmallVec :: new ( ) ;
232
- let mut to_add = SmallVec :: new ( ) ;
218
+ ) -> SmallVec < [ & ' ll Attribute ; 2 ] > {
219
+ let mut attrs = SmallVec :: new ( ) ;
233
220
match cx. sess ( ) . opts . optimize {
234
221
OptLevel :: Size => {
235
- to_remove. push ( llvm:: AttributeKind :: MinSize ) ;
236
- to_add. push ( llvm:: AttributeKind :: OptimizeForSize . create_attr ( cx. llcx ) ) ;
237
- to_remove. push ( llvm:: AttributeKind :: OptimizeNone ) ;
222
+ attrs. push ( llvm:: AttributeKind :: OptimizeForSize . create_attr ( cx. llcx ) ) ;
238
223
}
239
224
OptLevel :: SizeMin => {
240
- to_add. push ( llvm:: AttributeKind :: MinSize . create_attr ( cx. llcx ) ) ;
241
- to_add. push ( llvm:: AttributeKind :: OptimizeForSize . create_attr ( cx. llcx ) ) ;
242
- to_remove. push ( llvm:: AttributeKind :: OptimizeNone ) ;
243
- }
244
- OptLevel :: No => {
245
- to_remove. push ( llvm:: AttributeKind :: MinSize ) ;
246
- to_remove. push ( llvm:: AttributeKind :: OptimizeForSize ) ;
247
- to_remove. push ( llvm:: AttributeKind :: OptimizeNone ) ;
225
+ attrs. push ( llvm:: AttributeKind :: MinSize . create_attr ( cx. llcx ) ) ;
226
+ attrs. push ( llvm:: AttributeKind :: OptimizeForSize . create_attr ( cx. llcx ) ) ;
248
227
}
249
228
_ => { }
250
229
}
251
- ( to_remove , to_add )
230
+ attrs
252
231
}
253
232
254
233
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
@@ -260,25 +239,17 @@ pub fn from_fn_attrs<'ll, 'tcx>(
260
239
) {
261
240
let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
262
241
263
- let mut to_remove = SmallVec :: < [ _ ; 4 ] > :: new ( ) ;
264
242
let mut to_add = SmallVec :: < [ _ ; 16 ] > :: new ( ) ;
265
243
266
244
match codegen_fn_attrs. optimize {
267
245
OptimizeAttr :: None => {
268
- let ( to_remove_opt, to_add_opt) = default_optimisation_attrs ( cx) ;
269
- to_remove. extend ( to_remove_opt) ;
270
- to_add. extend ( to_add_opt) ;
271
- }
272
- OptimizeAttr :: Speed => {
273
- to_remove. push ( llvm:: AttributeKind :: MinSize ) ;
274
- to_remove. push ( llvm:: AttributeKind :: OptimizeForSize ) ;
275
- to_remove. push ( llvm:: AttributeKind :: OptimizeNone ) ;
246
+ to_add. extend ( default_optimisation_attrs ( cx) ) ;
276
247
}
277
248
OptimizeAttr :: Size => {
278
249
to_add. push ( llvm:: AttributeKind :: MinSize . create_attr ( cx. llcx ) ) ;
279
250
to_add. push ( llvm:: AttributeKind :: OptimizeForSize . create_attr ( cx. llcx ) ) ;
280
- to_remove. push ( llvm:: AttributeKind :: OptimizeNone ) ;
281
251
}
252
+ OptimizeAttr :: Speed => { }
282
253
}
283
254
284
255
let inline = if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: NAKED ) {
@@ -425,7 +396,6 @@ pub fn from_fn_attrs<'ll, 'tcx>(
425
396
to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "target-features" ) , & val) ) ;
426
397
}
427
398
428
- attributes:: remove_from_llfn ( llfn, Function , & to_remove) ;
429
399
attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
430
400
}
431
401
0 commit comments