Skip to content

Commit 3557314

Browse files
committed
Remove silly legacy glue-offset encoding, predicate runtime adjustments by ABI. LLVM should inline most glue now.
1 parent 19ebc0f commit 3557314

File tree

3 files changed

+38
-54
lines changed

3 files changed

+38
-54
lines changed

src/comp/back/abi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ const int vec_elt_data = 4;
3232
const int tydesc_field_first_param = 0;
3333
const int tydesc_field_size = 1;
3434
const int tydesc_field_align = 2;
35-
const int tydesc_field_take_glue_off = 3;
36-
const int tydesc_field_drop_glue_off = 4;
37-
const int tydesc_field_free_glue_off = 5;
38-
const int tydesc_field_sever_glue_off = 6;
39-
const int tydesc_field_mark_glue_off = 7;
40-
const int tydesc_field_obj_drop_glue_off = 8;
35+
const int tydesc_field_take_glue = 3;
36+
const int tydesc_field_drop_glue = 4;
37+
const int tydesc_field_free_glue = 5;
38+
const int tydesc_field_sever_glue = 6;
39+
const int tydesc_field_mark_glue = 7;
40+
const int tydesc_field_obj_drop_glue = 8;
4141
const int tydesc_field_is_stateful = 9;
4242

4343

src/comp/middle/trans.rs

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn T_glue_fn(type_names tn) -> TypeRef {
331331
_vec.buf[TypeRef](tydesc_elts));
332332
auto t =
333333
llvm.LLVMGetElementType
334-
(tydesc_elts.(abi.tydesc_field_drop_glue_off));
334+
(tydesc_elts.(abi.tydesc_field_drop_glue));
335335
tn.associate(s, t);
336336
ret t;
337337
}
@@ -355,12 +355,12 @@ fn T_tydesc(type_names tn) -> TypeRef {
355355
auto tydesc = T_struct(vec(tydescpp, // first_param
356356
T_int(), // size
357357
T_int(), // align
358-
glue_fn_ty, // take_glue_off
359-
glue_fn_ty, // drop_glue_off
360-
glue_fn_ty, // free_glue_off
361-
glue_fn_ty, // sever_glue_off
362-
glue_fn_ty, // mark_glue_off
363-
glue_fn_ty, // obj_drop_glue_off
358+
glue_fn_ty, // take_glue
359+
glue_fn_ty, // drop_glue
360+
glue_fn_ty, // free_glue
361+
glue_fn_ty, // sever_glue
362+
glue_fn_ty, // mark_glue
363+
glue_fn_ty, // obj_drop_glue
364364
glue_fn_ty)); // is_stateful
365365

366366
llvm.LLVMRefineType(abs_tydesc, tydesc);
@@ -414,11 +414,11 @@ fn T_crate(type_names tn) -> TypeRef {
414414
T_int(), // size_t debug_abbrev_sz
415415
T_int(), // ptrdiff_t debug_info_off
416416
T_int(), // size_t debug_info_sz
417-
T_int(), // size_t activate_glue_off
418-
T_int(), // size_t yield_glue_off
419-
T_int(), // size_t unwind_glue_off
420-
T_int(), // size_t gc_glue_off
421-
T_int(), // size_t main_exit_task_glue_off
417+
T_int(), // size_t activate_glue
418+
T_int(), // size_t yield_glue
419+
T_int(), // size_t unwind_glue
420+
T_int(), // size_t gc_glue
421+
T_int(), // size_t main_exit_task_glue
422422
T_int(), // int n_rust_syms
423423
T_int(), // int n_c_syms
424424
T_int(), // int n_libs
@@ -1576,29 +1576,19 @@ fn declare_tydesc(@crate_ctxt cx, @ty.t t) {
15761576
}
15771577

15781578
auto glue_fn_ty = T_ptr(T_glue_fn(cx.tn));
1579-
1580-
// FIXME: this adjustment has to do with the ridiculous encoding of
1581-
// glue-pointer-constants in the tydesc records: They are tydesc-relative
1582-
// displacements. This is purely for compatibility with rustboot and
1583-
// should go when it is discarded.
1584-
fn off(ValueRef tydescp,
1585-
ValueRef gluefn) -> ValueRef {
1586-
ret i2p(llvm.LLVMConstSub(p2i(gluefn), p2i(tydescp)),
1587-
val_ty(gluefn));
1588-
}
1589-
1579+
15901580
auto name = sanitize(cx.names.next("tydesc_" + ty.ty_to_str(t)));
15911581
auto gvar = llvm.LLVMAddGlobal(cx.llmod, T_tydesc(cx.tn),
15921582
_str.buf(name));
15931583
auto tydesc = C_struct(vec(C_null(T_ptr(T_ptr(T_tydesc(cx.tn)))),
15941584
llsize,
15951585
llalign,
1596-
off(gvar, take_glue), // take_glue_off
1597-
off(gvar, drop_glue), // drop_glue_off
1598-
C_null(glue_fn_ty), // free_glue_off
1599-
C_null(glue_fn_ty), // sever_glue_off
1600-
C_null(glue_fn_ty), // mark_glue_off
1601-
C_null(glue_fn_ty), // obj_drop_glue_off
1586+
take_glue, // take_glue
1587+
drop_glue, // drop_glue
1588+
C_null(glue_fn_ty), // free_glue
1589+
C_null(glue_fn_ty), // sever_glue
1590+
C_null(glue_fn_ty), // mark_glue
1591+
C_null(glue_fn_ty), // obj_drop_glue
16021592
C_null(glue_fn_ty))); // is_stateful
16031593

16041594
llvm.LLVMSetInitializer(gvar, tydesc);
@@ -1789,7 +1779,7 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @ty.t t) -> result {
17891779
C_int(abi.obj_body_elt_tydesc)));
17901780

17911781
call_tydesc_glue_full(cx, body, cx.build.Load(tydescptr),
1792-
abi.tydesc_field_drop_glue_off);
1782+
abi.tydesc_field_drop_glue);
17931783

17941784
// Then free the body.
17951785
// FIXME: switch gc/non-gc on layer of the type.
@@ -1827,7 +1817,7 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @ty.t t) -> result {
18271817
C_int(abi.closure_elt_tydesc)));
18281818

18291819
call_tydesc_glue_full(cx, bindings, cx.build.Load(tydescptr),
1830-
abi.tydesc_field_drop_glue_off);
1820+
abi.tydesc_field_drop_glue);
18311821

18321822

18331823
// Then free the body.
@@ -2316,14 +2306,6 @@ fn call_tydesc_glue_full(@block_ctxt cx, ValueRef v,
23162306
auto llfnptr = cx.build.GEP(tydesc, vec(C_int(0), C_int(field)));
23172307
auto llfn = cx.build.Load(llfnptr);
23182308

2319-
// FIXME: this adjustment has to do with the ridiculous encoding of
2320-
// glue-pointer-constants in the tydesc records: They are tydesc-relative
2321-
// displacements. This is purely for compatibility with rustboot and
2322-
// should go when it is discarded.
2323-
llfn = vi2p(cx, cx.build.Add(vp2i(cx, llfn),
2324-
vp2i(cx, tydesc)),
2325-
val_ty(llfn));
2326-
23272309
cx.build.FastCall(llfn, vec(C_null(T_ptr(T_nil())),
23282310
cx.fcx.lltaskptr,
23292311
C_null(T_ptr(T_nil())),
@@ -2340,7 +2322,7 @@ fn take_ty(@block_ctxt cx,
23402322
ValueRef v,
23412323
@ty.t t) -> result {
23422324
if (!ty.type_is_scalar(t)) {
2343-
call_tydesc_glue(cx, v, t, abi.tydesc_field_take_glue_off);
2325+
call_tydesc_glue(cx, v, t, abi.tydesc_field_take_glue);
23442326
}
23452327
ret res(cx, C_nil());
23462328
}
@@ -2362,7 +2344,7 @@ fn drop_ty(@block_ctxt cx,
23622344
@ty.t t) -> result {
23632345

23642346
if (!ty.type_is_scalar(t)) {
2365-
call_tydesc_glue(cx, v, t, abi.tydesc_field_drop_glue_off);
2347+
call_tydesc_glue(cx, v, t, abi.tydesc_field_drop_glue);
23662348
}
23672349
ret res(cx, C_nil());
23682350
}
@@ -6939,7 +6921,7 @@ fn trans_vec_append_glue(@crate_ctxt cx) {
69396921
ValueRef dst, ValueRef src) -> result {
69406922
call_tydesc_glue_full(cx, src,
69416923
elt_tydesc,
6942-
abi.tydesc_field_take_glue_off);
6924+
abi.tydesc_field_take_glue);
69436925
ret res(cx, src);
69446926
}
69456927

src/rt/rust_crate_cache.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,14 @@ rust_crate_cache::get_type_desc(size_t size,
221221
// FIXME (issue #136): Below is a miscalculation.
222222
td->is_stateful |= descs[i]->is_stateful;
223223
}
224-
adjust_disp(td->copy_glue_off, descs[0], td);
225-
adjust_disp(td->drop_glue_off, descs[0], td);
226-
adjust_disp(td->free_glue_off, descs[0], td);
227-
adjust_disp(td->mark_glue_off, descs[0], td);
228-
adjust_disp(td->sever_glue_off, descs[0], td);
229-
adjust_disp(td->obj_drop_glue_off, descs[0], td);
224+
if (crate->abi_tag == ABI_X86_RUSTBOOT_CDECL) {
225+
adjust_disp(td->copy_glue_off, descs[0], td);
226+
adjust_disp(td->drop_glue_off, descs[0], td);
227+
adjust_disp(td->free_glue_off, descs[0], td);
228+
adjust_disp(td->mark_glue_off, descs[0], td);
229+
adjust_disp(td->sever_glue_off, descs[0], td);
230+
adjust_disp(td->obj_drop_glue_off, descs[0], td);
231+
}
230232
HASH_ADD(hh, this->type_descs, descs, keysz, td);
231233
return td;
232234
}

0 commit comments

Comments
 (0)