add support for the cold
function attribute
This allows a function to marked as infrequently called, resulting in any branch calling it to be considered colder.
This commit is contained in:
parent
d664ca2635
commit
541e5f84d7
@ -693,6 +693,8 @@ pub fn LLVMGetOrInsertFunction(M: ModuleRef,
|
||||
pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
|
||||
pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
|
||||
|
||||
pub fn LLVMAddColdAttribute(Fn: ValueRef);
|
||||
|
||||
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
|
||||
PA: c_ulonglong,
|
||||
HighPA: c_ulonglong);
|
||||
|
@ -202,19 +202,21 @@ pub fn get_extern_fn(externs: &mut ExternMap, llmod: ModuleRef, name: &str,
|
||||
f
|
||||
}
|
||||
|
||||
pub fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
|
||||
name: &str) -> ValueRef {
|
||||
fn get_extern_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
|
||||
name: &str, did: ast::DefId) -> ValueRef {
|
||||
match ccx.externs.find_equiv(&name) {
|
||||
Some(n) => return *n,
|
||||
None => ()
|
||||
}
|
||||
let f = decl_rust_fn(ccx, inputs, output, name);
|
||||
do csearch::get_item_attrs(ccx.tcx.cstore, did) |meta_items| {
|
||||
set_llvm_fn_attrs(meta_items.iter().map(|&x| attr::mk_attr(x)).to_owned_vec(), f)
|
||||
}
|
||||
ccx.externs.insert(name.to_owned(), f);
|
||||
f
|
||||
}
|
||||
|
||||
pub fn decl_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t,
|
||||
name: &str) -> ValueRef {
|
||||
fn decl_rust_fn(ccx: &mut CrateContext, inputs: &[ty::t], output: ty::t, name: &str) -> ValueRef {
|
||||
let llfty = type_of_rust_fn(ccx, inputs, output);
|
||||
let llfn = decl_cdecl_fn(ccx.llmod, name, llfty);
|
||||
|
||||
@ -481,6 +483,10 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
|
||||
if contains_name(attrs, "no_split_stack") {
|
||||
set_no_split_stack(llfn);
|
||||
}
|
||||
|
||||
if contains_name(attrs, "cold") {
|
||||
unsafe { llvm::LLVMAddColdAttribute(llfn) }
|
||||
}
|
||||
}
|
||||
|
||||
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) ->
|
||||
ty::ty_bare_fn(ref fn_ty) => {
|
||||
match fn_ty.abis.for_arch(ccx.sess.targ_cfg.arch) {
|
||||
Some(Rust) | Some(RustIntrinsic) => {
|
||||
get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name)
|
||||
get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name, did)
|
||||
}
|
||||
Some(*) | None => {
|
||||
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) ->
|
||||
}
|
||||
}
|
||||
ty::ty_closure(ref f) => {
|
||||
get_extern_rust_fn(ccx, f.sig.inputs, f.sig.output, name)
|
||||
get_extern_rust_fn(ccx, f.sig.inputs, f.sig.output, name, did)
|
||||
}
|
||||
_ => {
|
||||
let llty = type_of(ccx, t);
|
||||
|
@ -57,6 +57,7 @@ pub fn clear_task_borrow_list() {
|
||||
let _ = try_take_task_borrow_list();
|
||||
}
|
||||
|
||||
#[cold]
|
||||
unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) -> ! {
|
||||
debug_borrow("fail_borrowed: ", box, 0, 0, file, line);
|
||||
|
||||
|
@ -16,11 +16,13 @@
|
||||
use rt::task;
|
||||
use rt::borrowck;
|
||||
|
||||
#[cold]
|
||||
#[lang="fail_"]
|
||||
pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
|
||||
task::begin_unwind(expr, file, line);
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[lang="fail_bounds_check"]
|
||||
pub fn fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t) -> ! {
|
||||
let msg = format!("index out of bounds: the len is {} but the index is {}",
|
||||
|
@ -365,6 +365,11 @@ extern "C" void LLVMRemoveReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) {
|
||||
AttributeSet::get(A->getContext(), AttributeSet::ReturnIndex, B));
|
||||
}
|
||||
|
||||
extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {
|
||||
Function *A = unwrap<Function>(Fn);
|
||||
A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
|
||||
LLVMValueRef source,
|
||||
const char* Name,
|
||||
|
@ -629,3 +629,4 @@ LLVMRustAddAlwaysInlinePass
|
||||
LLVMAddReturnAttribute
|
||||
LLVMRemoveReturnAttribute
|
||||
LLVMTypeToString
|
||||
LLVMAddColdAttribute
|
||||
|
Loading…
Reference in New Issue
Block a user