From e4b5d910dc0d5df159a5b9205ded878dfa57664c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 27 Jun 2011 15:38:04 -0700 Subject: [PATCH] rustc: Directly emit calls to glue if possible --- src/comp/middle/trans.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index e77fab450bb..b5f255a7b02 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2893,13 +2893,38 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field, fn call_tydesc_glue_full(&@block_ctxt cx, ValueRef v, ValueRef tydesc, int field, &option::t[@tydesc_info] static_ti) { lazily_emit_tydesc_glue(cx, field, static_ti); + + auto static_glue_fn = none; + alt (static_ti) { + case (none) { /* no-op */ } + case (some(?sti)) { + if (field == abi::tydesc_field_take_glue) { + static_glue_fn = sti.take_glue; + } else if (field == abi::tydesc_field_drop_glue) { + static_glue_fn = sti.drop_glue; + } else if (field == abi::tydesc_field_free_glue) { + static_glue_fn = sti.free_glue; + } else if (field == abi::tydesc_field_cmp_glue) { + static_glue_fn = sti.cmp_glue; + } + } + } + auto llrawptr = cx.build.BitCast(v, T_ptr(T_i8())); auto lltydescs = cx.build.GEP(tydesc, [C_int(0), C_int(abi::tydesc_field_first_param)]); lltydescs = cx.build.Load(lltydescs); - auto llfnptr = cx.build.GEP(tydesc, [C_int(0), C_int(field)]); - auto llfn = cx.build.Load(llfnptr); + + auto llfn; + alt (static_glue_fn) { + case (none) { + auto llfnptr = cx.build.GEP(tydesc, [C_int(0), C_int(field)]); + llfn = cx.build.Load(llfnptr); + } + case (some(?sgf)) { llfn = sgf; } + } + cx.build.Call(llfn, [C_null(T_ptr(T_nil())), cx.fcx.lltaskptr, C_null(T_ptr(T_nil())), lltydescs, llrawptr]);