Skip to content

Commit 9d21cf3

Browse files
committed
rustc: Allocate tydescs on the stack when it's safe to do so. 60% compile speed increase.
1 parent aa25f22 commit 9d21cf3

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/comp/middle/trans.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,6 @@ fn T_tydesc(type_names tn) -> TypeRef {
417417
ret t;
418418
}
419419

420-
// A "fat tydesc" is a type descriptor plus an array of extra type descriptors
421-
// following it.
422-
fn T_fat_tydesc(type_names tn, uint n_subdescs) -> TypeRef {
423-
ret T_struct(vec(T_tydesc(tn), T_array(T_tydesc(tn), n_subdescs)));
424-
}
425-
426420
fn T_array(TypeRef t, uint n) -> TypeRef {
427421
ret llvm.LLVMArrayType(t, n);
428422
}
@@ -1589,6 +1583,27 @@ fn linearize_ty_params(@block_ctxt cx, ty.t t) ->
15891583
ret tup(x.defs, x.vals);
15901584
}
15911585

1586+
fn trans_stack_local_derived_tydesc(@block_ctxt cx, ValueRef llsz,
1587+
ValueRef llalign, ValueRef lltydescs) -> result {
1588+
auto lltydesc = alloca(cx, T_tydesc(cx.fcx.lcx.ccx.tn));
1589+
1590+
// By convention, desc 0 is the root descriptor.
1591+
auto llroottydesc = cx.build.Load(cx.build.GEP(lltydescs,
1592+
vec(C_int(0), C_int(0))));
1593+
llroottydesc = cx.build.Load(llroottydesc);
1594+
cx.build.Store(llroottydesc, lltydesc);
1595+
1596+
// Store a pointer to the rest of the descriptors.
1597+
auto llfirstparam = cx.build.GEP(lltydescs, vec(C_int(0), C_int(1)));
1598+
cx.build.Store(llfirstparam,
1599+
cx.build.GEP(lltydesc, vec(C_int(0), C_int(0))));
1600+
1601+
cx.build.Store(llsz, cx.build.GEP(lltydesc, vec(C_int(0), C_int(1))));
1602+
cx.build.Store(llalign, cx.build.GEP(lltydesc, vec(C_int(0), C_int(2))));
1603+
1604+
ret res(cx, lltydesc);
1605+
}
1606+
15921607
fn get_tydesc(&@block_ctxt cx, ty.t t, bool escapes) -> result {
15931608
// Is the supplied type a type param? If so, return the passed-in tydesc.
15941609
alt (ty.type_param(cx.fcx.lcx.ccx.tcx, t)) {
@@ -1627,12 +1642,18 @@ fn get_tydesc(&@block_ctxt cx, ty.t t, bool escapes) -> result {
16271642
auto align = align_of(bcx, t);
16281643
bcx = align.bcx;
16291644

1630-
auto v = trans_upcall(bcx, "upcall_get_type_desc",
1631-
vec(p2i(bcx.fcx.lcx.ccx.crate_ptr),
1632-
sz.val,
1633-
align.val,
1634-
C_int((1u + n_params) as int),
1635-
vp2i(bcx, tydescs)), true);
1645+
auto v;
1646+
if (escapes) {
1647+
v = trans_upcall(bcx, "upcall_get_type_desc",
1648+
vec(p2i(bcx.fcx.lcx.ccx.crate_ptr),
1649+
sz.val,
1650+
align.val,
1651+
C_int((1u + n_params) as int),
1652+
vp2i(bcx, tydescs)), true);
1653+
} else {
1654+
v = trans_stack_local_derived_tydesc(bcx, sz.val, align.val,
1655+
tydescs);
1656+
}
16361657

16371658
ret res(v.bcx, vi2p(v.bcx, v.val,
16381659
T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn))));

0 commit comments

Comments
 (0)