@@ -328,7 +328,7 @@ fn create_alloc_family_attr(llcx: &llvm::Context) -> &llvm::Attribute {
328
328
329
329
/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
330
330
/// attributes.
331
- pub fn from_fn_attrs < ' ll , ' tcx > (
331
+ pub fn llfn_attrs_from_fn < ' ll , ' tcx > (
332
332
cx : & CodegenCx < ' ll , ' tcx > ,
333
333
llfn : & ' ll Value ,
334
334
instance : ty:: Instance < ' tcx > ,
@@ -410,48 +410,6 @@ pub fn from_fn_attrs<'ll, 'tcx>(
410
410
// Need this for AArch64.
411
411
to_add. push ( llvm:: CreateAttrStringValue ( cx. llcx , "branch-target-enforcement" , "false" ) ) ;
412
412
}
413
- if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: ALLOCATOR )
414
- || codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: ALLOCATOR_ZEROED )
415
- {
416
- to_add. push ( create_alloc_family_attr ( cx. llcx ) ) ;
417
- // apply to argument place instead of function
418
- let alloc_align = AttributeKind :: AllocAlign . create_attr ( cx. llcx ) ;
419
- attributes:: apply_to_llfn ( llfn, AttributePlace :: Argument ( 1 ) , & [ alloc_align] ) ;
420
- to_add. push ( llvm:: CreateAllocSizeAttr ( cx. llcx , 0 ) ) ;
421
- let mut flags = AllocKindFlags :: Alloc | AllocKindFlags :: Aligned ;
422
- if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: ALLOCATOR ) {
423
- flags |= AllocKindFlags :: Uninitialized ;
424
- } else {
425
- flags |= AllocKindFlags :: Zeroed ;
426
- }
427
- to_add. push ( llvm:: CreateAllocKindAttr ( cx. llcx , flags) ) ;
428
- // apply to return place instead of function (unlike all other attributes applied in this function)
429
- let no_alias = AttributeKind :: NoAlias . create_attr ( cx. llcx ) ;
430
- attributes:: apply_to_llfn ( llfn, AttributePlace :: ReturnValue , & [ no_alias] ) ;
431
- }
432
- if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: REALLOCATOR ) {
433
- to_add. push ( create_alloc_family_attr ( cx. llcx ) ) ;
434
- to_add. push ( llvm:: CreateAllocKindAttr (
435
- cx. llcx ,
436
- AllocKindFlags :: Realloc | AllocKindFlags :: Aligned ,
437
- ) ) ;
438
- // applies to argument place instead of function place
439
- let allocated_pointer = AttributeKind :: AllocatedPointer . create_attr ( cx. llcx ) ;
440
- attributes:: apply_to_llfn ( llfn, AttributePlace :: Argument ( 0 ) , & [ allocated_pointer] ) ;
441
- // apply to argument place instead of function
442
- let alloc_align = AttributeKind :: AllocAlign . create_attr ( cx. llcx ) ;
443
- attributes:: apply_to_llfn ( llfn, AttributePlace :: Argument ( 2 ) , & [ alloc_align] ) ;
444
- to_add. push ( llvm:: CreateAllocSizeAttr ( cx. llcx , 3 ) ) ;
445
- let no_alias = AttributeKind :: NoAlias . create_attr ( cx. llcx ) ;
446
- attributes:: apply_to_llfn ( llfn, AttributePlace :: ReturnValue , & [ no_alias] ) ;
447
- }
448
- if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: DEALLOCATOR ) {
449
- to_add. push ( create_alloc_family_attr ( cx. llcx ) ) ;
450
- to_add. push ( llvm:: CreateAllocKindAttr ( cx. llcx , AllocKindFlags :: Free ) ) ;
451
- // applies to argument place instead of function place
452
- let allocated_pointer = AttributeKind :: AllocatedPointer . create_attr ( cx. llcx ) ;
453
- attributes:: apply_to_llfn ( llfn, AttributePlace :: Argument ( 0 ) , & [ allocated_pointer] ) ;
454
- }
455
413
if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: CMSE_NONSECURE_ENTRY ) {
456
414
to_add. push ( llvm:: CreateAttrString ( cx. llcx , "cmse_nonsecure_entry" ) ) ;
457
415
}
@@ -530,6 +488,64 @@ pub fn from_fn_attrs<'ll, 'tcx>(
530
488
attributes:: apply_to_llfn ( llfn, Function , & to_add) ;
531
489
}
532
490
491
+ pub fn callsite_attrs_from_fn < ' ll , ' tcx > (
492
+ cx : & CodegenCx < ' ll , ' tcx > ,
493
+ callsite : & ' ll Value ,
494
+ instance : ty:: Instance < ' tcx > ,
495
+ ) {
496
+ let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
497
+
498
+ let mut to_add = SmallVec :: < [ _ ; 16 ] > :: new ( ) ;
499
+
500
+ if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: ALLOCATOR )
501
+ || codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: ALLOCATOR_ZEROED )
502
+ {
503
+ to_add. push ( create_alloc_family_attr ( cx. llcx ) ) ;
504
+ // apply to argument place instead of function
505
+ let alloc_align = AttributeKind :: AllocAlign . create_attr ( cx. llcx ) ;
506
+ //attributes::apply_to_callsite(callsite, AttributePlace::Argument(1), &[alloc_align]);
507
+ to_add. push ( llvm:: CreateAllocSizeAttr ( cx. llcx , 0 ) ) ;
508
+ let mut flags = AllocKindFlags :: Alloc | AllocKindFlags :: Aligned ;
509
+ if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: ALLOCATOR ) {
510
+ flags |= AllocKindFlags :: Uninitialized ;
511
+ } else {
512
+ flags |= AllocKindFlags :: Zeroed ;
513
+ }
514
+ to_add. push ( llvm:: CreateAllocKindAttr ( cx. llcx , flags) ) ;
515
+ // apply to return place instead of function (unlike all other attributes applied in this function)
516
+ let no_alias = AttributeKind :: NoAlias . create_attr ( cx. llcx ) ;
517
+ //attributes::apply_to_callsite(callsite, AttributePlace::ReturnValue, &[no_alias]);
518
+ }
519
+ if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: REALLOCATOR ) {
520
+ to_add. push ( create_alloc_family_attr ( cx. llcx ) ) ;
521
+ to_add. push ( llvm:: CreateAllocKindAttr (
522
+ cx. llcx ,
523
+ AllocKindFlags :: Realloc | AllocKindFlags :: Aligned ,
524
+ ) ) ;
525
+ // applies to argument place instead of function place
526
+ let allocated_pointer = AttributeKind :: AllocatedPointer . create_attr ( cx. llcx ) ;
527
+ //attributes::apply_to_callsite(callsite, AttributePlace::Argument(0), &[allocated_pointer]);
528
+ // apply to argument place instead of function
529
+ let alloc_align = AttributeKind :: AllocAlign . create_attr ( cx. llcx ) ;
530
+ //attributes::apply_to_callsite(callsite, AttributePlace::Argument(2), &[alloc_align]);
531
+ to_add. push ( llvm:: CreateAllocSizeAttr ( cx. llcx , 3 ) ) ;
532
+ let no_alias = AttributeKind :: NoAlias . create_attr ( cx. llcx ) ;
533
+ //attributes::apply_to_callsite(callsite, AttributePlace::ReturnValue, &[no_alias]);
534
+ }
535
+ if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: DEALLOCATOR ) {
536
+ to_add. push ( create_alloc_family_attr ( cx. llcx ) ) ;
537
+ to_add. push ( llvm:: CreateAllocKindAttr ( cx. llcx , AllocKindFlags :: Free ) ) ;
538
+ // applies to argument place instead of function place
539
+ let allocated_pointer = AttributeKind :: AllocatedPointer . create_attr ( cx. llcx ) ;
540
+ //attributes::apply_to_callsite(callsite, AttributePlace::Argument(0), &[allocated_pointer]);
541
+ }
542
+
543
+ if !to_add. is_empty ( ) {
544
+ eprintln ! ( "applying attributes to call of {instance:?}" ) ;
545
+ }
546
+ attributes:: apply_to_callsite ( callsite, Function , & to_add) ;
547
+ }
548
+
533
549
fn wasm_import_module ( tcx : TyCtxt < ' _ > , id : DefId ) -> Option < & String > {
534
550
tcx. wasm_import_module_map ( id. krate ) . get ( & id)
535
551
}
0 commit comments