@@ -28,12 +28,6 @@ pub fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) {
2828 }
2929}
3030
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-
3731pub fn apply_to_callsite ( callsite : & Value , idx : AttributePlace , attrs : & [ & Attribute ] ) {
3832 if !attrs. is_empty ( ) {
3933 llvm:: AddCallSiteAttributes ( callsite, idx, attrs) ;
@@ -217,38 +211,23 @@ pub fn non_lazy_bind_attr<'ll>(cx: &CodegenCx<'ll, '_>) -> Option<&'ll Attribute
217211 }
218212}
219213
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.
222215#[ inline]
223216pub ( crate ) fn default_optimisation_attrs < ' ll > (
224217 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 ( ) ;
233220 match cx. sess ( ) . opts . optimize {
234221 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 ) ) ;
238223 }
239224 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 ) ) ;
248227 }
249228 _ => { }
250229 }
251- ( to_remove , to_add )
230+ attrs
252231}
253232
254233/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
@@ -260,25 +239,17 @@ pub fn from_fn_attrs<'ll, 'tcx>(
260239) {
261240 let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
262241
263- let mut to_remove = SmallVec :: < [ _ ; 4 ] > :: new ( ) ;
264242 let mut to_add = SmallVec :: < [ _ ; 16 ] > :: new ( ) ;
265243
266244 match codegen_fn_attrs. optimize {
267245 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) ) ;
276247 }
277248 OptimizeAttr :: Size => {
278249 to_add. push ( llvm:: AttributeKind :: MinSize . create_attr ( cx. llcx ) ) ;
279250 to_add. push ( llvm:: AttributeKind :: OptimizeForSize . create_attr ( cx. llcx ) ) ;
280- to_remove. push ( llvm:: AttributeKind :: OptimizeNone ) ;
281251 }
252+ OptimizeAttr :: Speed => { }
282253 }
283254
284255 let inline = if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: NAKED ) {
@@ -425,7 +396,6 @@ pub fn from_fn_attrs<'ll, 'tcx>(
425396 to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , cstr ! ( "target-features" ) , & val) ) ;
426397 }
427398
428- attributes:: remove_from_llfn ( llfn, Function , & to_remove) ;
429399 attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
430400}
431401
0 commit comments