@@ -202,19 +202,21 @@ pub fn get_extern_fn(externs: &mut ExternMap, llmod: ModuleRef, name: &str,
202
202
f
203
203
}
204
204
205
- pub fn get_extern_rust_fn ( ccx : & mut CrateContext , inputs : & [ ty:: t ] , output : ty:: t ,
206
- name : & str ) -> ValueRef {
205
+ fn get_extern_rust_fn ( ccx : & mut CrateContext , inputs : & [ ty:: t ] , output : ty:: t ,
206
+ name : & str , did : ast :: DefId ) -> ValueRef {
207
207
match ccx. externs . find_equiv ( & name) {
208
208
Some ( n) => return * n,
209
209
None => ( )
210
210
}
211
211
let f = decl_rust_fn ( ccx, inputs, output, name) ;
212
+ do csearch:: get_item_attrs ( ccx. tcx . cstore , did) |meta_items| {
213
+ set_llvm_fn_attrs ( meta_items. iter ( ) . map ( |& x| attr:: mk_attr ( x) ) . to_owned_vec ( ) , f)
214
+ }
212
215
ccx. externs . insert ( name. to_owned ( ) , f) ;
213
216
f
214
217
}
215
218
216
- pub fn decl_rust_fn ( ccx : & mut CrateContext , inputs : & [ ty:: t ] , output : ty:: t ,
217
- name : & str ) -> ValueRef {
219
+ fn decl_rust_fn ( ccx : & mut CrateContext , inputs : & [ ty:: t ] , output : ty:: t , name : & str ) -> ValueRef {
218
220
let llfty = type_of_rust_fn ( ccx, inputs, output) ;
219
221
let llfn = decl_cdecl_fn ( ccx. llmod , name, llfty) ;
220
222
@@ -481,6 +483,10 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
481
483
if contains_name ( attrs, "no_split_stack" ) {
482
484
set_no_split_stack ( llfn) ;
483
485
}
486
+
487
+ if contains_name ( attrs, "cold" ) {
488
+ unsafe { llvm:: LLVMAddColdAttribute ( llfn) }
489
+ }
484
490
}
485
491
486
492
pub fn set_always_inline ( f : ValueRef ) {
@@ -840,7 +846,7 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
840
846
ty::ty_bare_fn(ref fn_ty) => {
841
847
match fn_ty.abis.for_arch(ccx.sess.targ_cfg.arch) {
842
848
Some(Rust) | Some(RustIntrinsic) => {
843
- get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name)
849
+ get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name, did )
844
850
}
845
851
Some(*) | None => {
846
852
let c = foreign::llvm_calling_convention(ccx, fn_ty.abis);
@@ -851,7 +857,7 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
851
857
}
852
858
}
853
859
ty::ty_closure(ref f) => {
854
- get_extern_rust_fn(ccx, f.sig.inputs, f.sig.output, name)
860
+ get_extern_rust_fn(ccx, f.sig.inputs, f.sig.output, name, did )
855
861
}
856
862
_ => {
857
863
let llty = type_of(ccx, t);
0 commit comments