Skip to content

Commit df51fe3

Browse files
committed
Revert "rt: Use obstacks in lieu of dynamically-sized frames"
This reverts commit cc5fcfc.
1 parent 49397b5 commit df51fe3

File tree

7 files changed

+40
-69
lines changed

7 files changed

+40
-69
lines changed

src/comp/middle/trans.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -466,20 +466,17 @@ fn alloca(cx: &@block_ctxt, t: TypeRef) -> ValueRef {
466466
}
467467

468468
fn array_alloca(cx: &@block_ctxt, t: TypeRef, n: ValueRef) -> ValueRef {
469-
let bcx = cx;
470469
let builder = new_builder(cx.fcx.lldynamicallocas);
471-
let lltaskptr = bcx_fcx(bcx).lltaskptr;
472-
473-
let dynastack_alloc = bcx_ccx(bcx).upcalls.dynastack_alloc;
474-
let llsz = builder.Mul(C_uint(llsize_of_real(bcx_ccx(bcx), t)), n);
475-
let llresult = builder.Call(dynastack_alloc, ~[lltaskptr, llsz]);
476-
ret builder.PointerCast(llresult, T_ptr(t));
477-
}
478-
479-
fn mk_obstack_token(ccx: &@crate_ctxt, lldynamicallocas: BasicBlockRef,
480-
lltaskptr: ValueRef) -> ValueRef {
481-
let builder = new_builder(lldynamicallocas);
482-
ret builder.Call(ccx.upcalls.dynastack_mark, ~[lltaskptr]);
470+
alt bcx_fcx(cx).llobstacktoken {
471+
none. {
472+
let dynastack_mark = bcx_ccx(cx).upcalls.dynastack_mark;
473+
let lltaskptr = bcx_fcx(cx).lltaskptr;
474+
bcx_fcx(cx).llobstacktoken =
475+
some(builder.Call(dynastack_mark, ~[lltaskptr]));
476+
}
477+
some(_) { /* no-op */ }
478+
}
479+
ret builder.ArrayAlloca(t, n);
483480
}
484481

485482

@@ -4410,8 +4407,6 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
44104407
lltargetfn = bcx.build.PointerCast(lltargetfn, T_ptr(T_ptr(lltargetty)));
44114408
lltargetfn = bcx.build.Load(lltargetfn);
44124409
llvm::LLVMSetTailCall(bcx.build.FastCall(lltargetfn, llargs), 1);
4413-
4414-
bcx = trans_fn_cleanups(bcx); // TODO: Might break tail call.
44154410
bcx.build.RetVoid();
44164411
finish_fn(fcx, lltop);
44174412
ret {val: llthunk, ty: llthunk_ty};
@@ -5616,8 +5611,14 @@ fn trans_block_cleanups(cx: &@block_ctxt, cleanup_cx: &@block_ctxt) ->
56165611
}
56175612

56185613
fn trans_fn_cleanups(bcx: &@block_ctxt) -> @block_ctxt {
5619-
bcx.build.Call(bcx_ccx(bcx).upcalls.dynastack_free,
5620-
~[bcx_fcx(bcx).lltaskptr, bcx_fcx(bcx).llobstacktoken]);
5614+
alt bcx_fcx(bcx).llobstacktoken {
5615+
some(lltoken_) {
5616+
let lltoken = lltoken_; // satisfy alias checker
5617+
bcx.build.Call(bcx_ccx(bcx).upcalls.dynastack_free,
5618+
~[bcx_fcx(bcx).lltaskptr, lltoken]);
5619+
}
5620+
none. { /* nothing to do */ }
5621+
}
56215622
ret bcx;
56225623
}
56235624

@@ -5806,7 +5807,6 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: &span, llfndecl: ValueRef,
58065807
let derived_tydescs =
58075808
map::mk_hashmap::<ty::t, derived_tydesc_info>(ty::hash_ty, ty::eq_ty);
58085809
let llbbs = mk_standard_basic_blocks(llfndecl);
5809-
let llobstacktoken = mk_obstack_token(cx.ccx, llbbs.da, lltaskptr);
58105810
ret @{llfn: llfndecl,
58115811
lltaskptr: lltaskptr,
58125812
llenv: llenv,
@@ -5816,7 +5816,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: &span, llfndecl: ValueRef,
58165816
mutable llderivedtydescs_first: llbbs.dt,
58175817
mutable llderivedtydescs: llbbs.dt,
58185818
mutable lldynamicallocas: llbbs.da,
5819-
mutable llobstacktoken: llobstacktoken,
5819+
mutable llobstacktoken: none::<ValueRef>,
58205820
mutable llself: none::<val_self_pair>,
58215821
mutable lliterbody: none::<ValueRef>,
58225822
mutable iterbodyty: none::<ty::t>,
@@ -6137,7 +6137,6 @@ fn trans_res_ctor(cx: @local_ctxt, sp: &span, dtor: &ast::_fn,
61376137
let flag = GEP_tup_like(bcx, tup_t, llretptr, ~[0, 0]);
61386138
bcx = flag.bcx;
61396139
bcx.build.Store(C_int(1), flag.val);
6140-
bcx = trans_fn_cleanups(bcx);
61416140
bcx.build.RetVoid();
61426141
finish_fn(fcx, lltop);
61436142
}
@@ -6434,7 +6433,6 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
64346433
};
64356434
bcx.build.FastCall(main_llfn, args);
64366435
}
6437-
bcx = trans_fn_cleanups(bcx);
64386436
bcx.build.RetVoid();
64396437

64406438
let lltop = bcx.llbb;
@@ -6756,7 +6754,6 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str],
67566754
for d: {val: ValueRef, ty: ty::t} in drop_args {
67576755
bcx = drop_ty(bcx, d.val, d.ty).bcx;
67586756
}
6759-
bcx = trans_fn_cleanups(bcx);
67606757
bcx.build.RetVoid();
67616758
finish_fn(fcx, lltop);
67626759
}

src/comp/middle/trans_common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ type fn_ctxt = {
215215
mutable lldynamicallocas: BasicBlockRef,
216216

217217
// The token used to clear the dynamic allocas at the end of this frame.
218-
mutable llobstacktoken: ValueRef,
218+
// Will be |none| if there are no dynamic allocas.
219+
mutable llobstacktoken: option::t<ValueRef>,
219220

220221
// The 'self' object currently in use in this function, if there
221222
// is one.

src/comp/middle/trans_objects.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
192192
let p = bcx.build.PointerCast(box.box, llbox_ty);
193193
bcx.build.Store(p, pair_box);
194194
}
195-
196-
bcx = trans_fn_cleanups(bcx);
197195
bcx.build.RetVoid();
198196

199197
// Insert the mandatory first few basic blocks before lltop.
@@ -712,7 +710,6 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
712710
// And, finally, call the outer method.
713711
bcx.build.FastCall(llouter_mthd, llouter_mthd_args);
714712

715-
bcx = trans_fn_cleanups(bcx);
716713
bcx.build.RetVoid();
717714
finish_fn(fcx, lltop);
718715

@@ -885,7 +882,6 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method,
885882
// And, finally, call the original (inner) method.
886883
bcx.build.FastCall(llorig_mthd, llorig_mthd_args);
887884

888-
bcx = trans_fn_cleanups(bcx);
889885
bcx.build.RetVoid();
890886
finish_fn(fcx, lltop);
891887

src/rt/rust_obstack.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
#undef max
1515
#endif
1616

17-
//#define DPRINT(fmt,...) fprintf(stderr, fmt, ##__VA_ARGS__)
18-
#define DPRINT(fmt,...)
19-
20-
//const size_t DEFAULT_CHUNK_SIZE = 4096;
21-
const size_t DEFAULT_CHUNK_SIZE = 300000;
22-
const size_t DEFAULT_ALIGNMENT = 16;
17+
const size_t DEFAULT_CHUNK_SIZE = 4096;
2318

2419
struct rust_obstack_chunk {
2520
rust_obstack_chunk *prev;
@@ -37,13 +32,8 @@ struct rust_obstack_chunk {
3732

3833
void *
3934
rust_obstack_chunk::alloc(size_t len) {
40-
alen = align_to(alen, DEFAULT_ALIGNMENT);
41-
42-
if (len > size - alen) {
43-
DPRINT("Not enough space, len=%lu!\n", len);
44-
assert(0);
35+
if (len > size - alen)
4536
return NULL; // Not enough space.
46-
}
4737
void *result = data + alen;
4838
alen += len;
4939
return result;
@@ -52,7 +42,7 @@ rust_obstack_chunk::alloc(size_t len) {
5242
bool
5343
rust_obstack_chunk::free(void *ptr) {
5444
uint8_t *p = (uint8_t *)ptr;
55-
if (p < data || p > data + size)
45+
if (p < data || p >= data + size)
5646
return false;
5747
assert(p <= data + alen);
5848
alen = (size_t)(p - data);
@@ -64,7 +54,6 @@ void *
6454
rust_obstack::alloc_new(size_t len) {
6555
size_t chunk_size = std::max(len, DEFAULT_CHUNK_SIZE);
6656
void *ptr = task->malloc(sizeof(chunk) + chunk_size, "obstack");
67-
DPRINT("making new chunk at %p, len %lu\n", ptr, chunk_size);
6857
chunk = new(ptr) rust_obstack_chunk(chunk, chunk_size);
6958
return chunk->alloc(len);
7059
}
@@ -81,12 +70,8 @@ void *
8170
rust_obstack::alloc(size_t len) {
8271
if (!chunk)
8372
return alloc_new(len);
84-
85-
DPRINT("alloc sz %u", (uint32_t)len);
86-
8773
void *ptr = chunk->alloc(len);
8874
ptr = ptr ? ptr : alloc_new(len);
89-
9075
return ptr;
9176
}
9277

@@ -95,11 +80,8 @@ rust_obstack::free(void *ptr) {
9580
if (!ptr)
9681
return;
9782

98-
DPRINT("free ptr %p\n", ptr);
99-
10083
assert(chunk);
10184
while (!chunk->free(ptr)) {
102-
DPRINT("deleting chunk at %p\n", chunk);
10385
rust_obstack_chunk *prev = chunk->prev;
10486
task->free(chunk);
10587
chunk = prev;

src/rt/rust_shape.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ const uint8_t CMP_LT = 1u;
6464
const uint8_t CMP_LE = 2u;
6565

6666

67+
// Utility functions
68+
69+
// Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power
70+
// of two.
71+
template<typename T>
72+
static inline T
73+
align_to(T size, size_t alignment) {
74+
assert(alignment);
75+
T x = (T)(((uintptr_t)size + alignment - 1) & ~(alignment - 1));
76+
return x;
77+
}
78+
6779
// Utility classes
6880

6981
struct size_align {
@@ -173,18 +185,11 @@ class ptr_pair {
173185
}
174186
};
175187

176-
} // end namespace shape
177-
178-
179-
inline shape::ptr_pair
180-
align_to(const shape::ptr_pair &pair, size_t n) {
181-
return shape::ptr_pair::make(align_to(pair.fst, n),
182-
align_to(pair.snd, n));
188+
inline ptr_pair
189+
align_to(const ptr_pair &pair, size_t n) {
190+
return ptr_pair::make(align_to(pair.fst, n), align_to(pair.snd, n));
183191
}
184192

185-
186-
namespace shape {
187-
188193
// NB: This function does not align.
189194
template<typename T>
190195
inline data_pair<T>

src/rt/rust_upcall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ upcall_dynastack_mark(rust_task *task) {
430430
/** Allocates space in the dynamic stack and returns it. */
431431
extern "C" CDECL void *
432432
upcall_dynastack_alloc(rust_task *task, size_t sz) {
433-
return sz ? task->dynastack.alloc(sz) : NULL;
433+
return task->dynastack.alloc(sz);
434434
}
435435

436436
/** Frees space in the dynamic stack. */

src/rt/rust_util.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,6 @@ next_power_of_two(size_t s)
125125
return tmp + 1;
126126
}
127127

128-
// Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power
129-
// of two.
130-
template<typename T>
131-
static inline T
132-
align_to(T size, size_t alignment) {
133-
assert(alignment);
134-
T x = (T)(((uintptr_t)size + alignment - 1) & ~(alignment - 1));
135-
return x;
136-
}
137-
138128
// Initialization helper for ISAAC RNG
139129

140130
template <typename sched_or_kernel>

0 commit comments

Comments
 (0)