Skip to content

Commit fa75703

Browse files
committed
Twiddle glue inlining heuristics. ~10% win on build time.
1 parent 67b8501 commit fa75703

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/comp/middle/trans.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,25 @@ fn get_static_tydesc(&@block_ctxt cx,
17771777
}
17781778
}
17791779

1780+
fn set_no_inline(ValueRef f) {
1781+
llvm::LLVMAddFunctionAttr(f, lib::llvm::LLVMNoInlineAttribute as
1782+
lib::llvm::llvm::Attribute);
1783+
}
1784+
1785+
fn set_always_inline(ValueRef f) {
1786+
llvm::LLVMAddFunctionAttr(f, lib::llvm::LLVMAlwaysInlineAttribute as
1787+
lib::llvm::llvm::Attribute);
1788+
}
1789+
1790+
fn set_glue_inlining(&@local_ctxt cx, ValueRef f, &ty::t t) {
1791+
if (ty::type_is_structural(cx.ccx.tcx, t)) {
1792+
set_no_inline(f);
1793+
} else {
1794+
set_always_inline(f);
1795+
}
1796+
}
1797+
1798+
17801799
// Generates the declaration for (but doesn't emit) a type descriptor.
17811800
fn declare_tydesc(&@local_ctxt cx, &ast::span sp, &ty::t t,
17821801
vec[uint] ty_params) -> @tydesc_info {
@@ -1838,6 +1857,7 @@ fn declare_generic_glue(&@local_ctxt cx,
18381857
fn_nm = mangle_name_by_seq(cx.ccx, cx.path, "glue_" + name);
18391858
}
18401859
auto llfn = decl_fastcall_fn(cx.ccx.llmod, fn_nm, llfnty);
1860+
set_glue_inlining(cx, llfn, t);
18411861
ret llfn;
18421862
}
18431863

@@ -2916,10 +2936,6 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
29162936
declare_generic_glue(lcx, ti.ty,
29172937
T_glue_fn(lcx.ccx.tn),
29182938
"free");
2919-
// Don't inline free glue; it's cold.
2920-
llvm::LLVMAddFunctionAttr(glue_fn,
2921-
lib::llvm::LLVMNoInlineAttribute as
2922-
lib::llvm::llvm::Attribute);
29232939

29242940
ti.free_glue = some[ValueRef](glue_fn);
29252941
auto dg = make_free_glue;
@@ -2976,10 +2992,10 @@ fn call_tydesc_glue_full(&@block_ctxt cx, ValueRef v,
29762992
}
29772993

29782994
fn call_tydesc_glue(&@block_ctxt cx, ValueRef v,
2979-
&ty::t t, bool escapes, int field) -> result {
2995+
&ty::t t, int field) -> result {
29802996

29812997
let option::t[@tydesc_info] ti = none[@tydesc_info];
2982-
auto td = get_tydesc(cx, t, escapes, ti);
2998+
auto td = get_tydesc(cx, t, false, ti);
29832999

29843000
call_tydesc_glue_full(td.bcx,
29853001
spill_if_immediate(td.bcx, v, t),
@@ -3054,7 +3070,7 @@ fn call_cmp_glue(&@block_ctxt cx,
30543070

30553071
fn take_ty(&@block_ctxt cx, ValueRef v, ty::t t) -> result {
30563072
if (ty::type_has_pointers(cx.fcx.lcx.ccx.tcx, t)) {
3057-
ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_take_glue);
3073+
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_take_glue);
30583074
}
30593075
ret res(cx, C_nil());
30603076
}
@@ -3076,7 +3092,7 @@ fn drop_ty(&@block_ctxt cx,
30763092
ty::t t) -> result {
30773093

30783094
if (ty::type_has_pointers(cx.fcx.lcx.ccx.tcx, t)) {
3079-
ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_drop_glue);
3095+
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_drop_glue);
30803096
}
30813097
ret res(cx, C_nil());
30823098
}
@@ -3086,7 +3102,7 @@ fn free_ty(&@block_ctxt cx,
30863102
ty::t t) -> result {
30873103

30883104
if (ty::type_has_pointers(cx.fcx.lcx.ccx.tcx, t)) {
3089-
ret call_tydesc_glue(cx, v, t, false, abi::tydesc_field_free_glue);
3105+
ret call_tydesc_glue(cx, v, t, abi::tydesc_field_free_glue);
30903106
}
30913107
ret res(cx, C_nil());
30923108
}

0 commit comments

Comments
 (0)