Skip to content

Commit cc2ebfc

Browse files
committed
set LLVM inline hint for all #[inline] methods, whether CC or local
1 parent e400733 commit cc2ebfc

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

src/rustc/front/attr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import driver::session::session;
77
export attr_meta;
88
export attr_metas;
99
export find_linkage_metas;
10+
export should_inline;
1011
export find_attrs_by_name;
1112
export attrs_contains_name;
1213
export find_meta_items_by_name;
@@ -43,6 +44,11 @@ fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
4344
ret metas;
4445
}
4546

47+
// True if something like #[inline] is found in the list of attrs.
48+
fn should_inline(attrs: [ast::attribute]) -> bool {
49+
attr::attrs_contains_name(attrs, "inline")
50+
}
51+
4652
// Search a list of attributes and return only those with a specific name
4753
fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) ->
4854
[ast::attribute] {

src/rustc/metadata/encoder.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
2929

3030
type encode_ctxt = {ccx: crate_ctxt, type_abbrevs: abbrev_map};
3131

32-
fn should_inline(_path: ast_map::path, attrs: [attribute]) -> bool {
33-
attr::attrs_contains_name(attrs, "inline")
34-
}
35-
3632
// Path table encoding
3733
fn encode_name(ebml_w: ebml::writer, name: str) {
3834
ebml_w.wr_tagged_str(tag_paths_data_name, name);
@@ -343,7 +339,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
343339
encode_type(ecx, ebml_w, node_id_to_type(tcx, item.id));
344340
encode_symbol(ecx, ebml_w, item.id);
345341
encode_path(ebml_w, path, ast_map::path_name(item.ident));
346-
if should_inline(path, item.attrs) {
342+
if attr::should_inline(item.attrs) {
347343
astencode::encode_inlined_item(ecx, ebml_w, path, ii_item(item));
348344
}
349345
ebml_w.end_tag();
@@ -446,7 +442,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
446442
encode_name(ebml_w, m.ident);
447443
encode_symbol(ecx, ebml_w, m.id);
448444
encode_path(ebml_w, impl_path, ast_map::path_name(m.ident));
449-
if should_inline(path, m.attrs) {
445+
if attr::should_inline(m.attrs) {
450446
astencode::encode_inlined_item(
451447
ecx, ebml_w, impl_path,
452448
ii_method(local_def(item.id), m));

src/rustc/middle/trans/base.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,19 @@ fn set_uwtable(f: ValueRef) {
646646
0u as c_uint);
647647
}
648648

649+
fn set_inline_hint(f: ValueRef) {
650+
llvm::LLVMAddFunctionAttr(f, lib::llvm::InlineHintAttribute as c_uint,
651+
0u as c_uint);
652+
}
653+
654+
fn set_inline_hint_if_appr(ccx: crate_ctxt,
655+
attrs: [ast::attribute],
656+
id: ast::node_id) {
657+
if attr::should_inline(attrs) {
658+
set_inline_hint(ccx.item_ids.get(id));
659+
}
660+
}
661+
649662
fn set_always_inline(f: ValueRef) {
650663
llvm::LLVMAddFunctionAttr(f, lib::llvm::AlwaysInlineAttribute as c_uint,
651664
0u as c_uint);
@@ -4696,13 +4709,17 @@ fn collect_item(ccx: crate_ctxt, abi: @mutable option<ast::native_abi>,
46964709
} else {
46974710
native::register_crust_fn(ccx, i.span, my_path, i.id);
46984711
}
4712+
4713+
set_inline_hint_if_appr(ccx, i.attrs, i.id);
46994714
}
47004715
ast::item_impl(tps, _, _, methods) {
47014716
let path = my_path + [path_name(int::str(i.id))];
47024717
for m in methods {
47034718
register_fn(ccx, i.span,
47044719
path + [path_name(m.ident)],
47054720
"impl_method", tps + m.tps, m.id);
4721+
4722+
set_inline_hint_if_appr(ccx, m.attrs, m.id);
47064723
}
47074724
}
47084725
ast::item_res(_, tps, _, dtor_id, ctor_id) {
@@ -4749,12 +4766,6 @@ fn collect_inlined_items(ccx: crate_ctxt, inline_map: inline::inline_map) {
47494766
alt ii {
47504767
ast::ii_item(item) {
47514768
collect_item(ccx, abi, item);
4752-
alt item.node {
4753-
ast::item_fn(_, _, _) {
4754-
set_always_inline(ccx.item_ids.get(item.id));
4755-
}
4756-
_ { /* fallthrough */ }
4757-
}
47584769
}
47594770

47604771
ast::ii_method(impl_did, m) {
@@ -4763,6 +4774,7 @@ fn collect_inlined_items(ccx: crate_ctxt, inline_map: inline::inline_map) {
47634774
let mthd_ty = ty::node_id_to_type(ccx.tcx, m.id);
47644775
register_fn_full(ccx, m.span, m_path, "impl_method",
47654776
m_bounds, m.id, mthd_ty);
4777+
set_inline_hint_if_appr(ccx, m.attrs, m.id);
47664778
}
47674779
}
47684780
}

0 commit comments

Comments
 (0)