Skip to content

Commit a3f0b31

Browse files
committed
---
yaml --- r: 4790 b: refs/heads/master c: f17edf9 h: refs/heads/master v: v3
1 parent b1ae9b5 commit a3f0b31

File tree

7 files changed

+58
-25
lines changed

7 files changed

+58
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0b7af403843d54c3200f8f9accbd2b279d6a7a0c
2+
refs/heads/master: f17edf9829e88090445a7f8b3e74979ca08ecfa0

trunk/src/comp/middle/trans.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,28 @@ 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;
469470
let builder = new_builder(cx.fcx.lldynamicallocas);
471+
let lltaskptr = bcx_fcx(bcx).lltaskptr;
470472
alt bcx_fcx(cx).llobstacktoken {
471473
none. {
472-
let dynastack_mark = bcx_ccx(cx).upcalls.dynastack_mark;
473-
let lltaskptr = bcx_fcx(cx).lltaskptr;
474474
bcx_fcx(cx).llobstacktoken =
475-
some(builder.Call(dynastack_mark, ~[lltaskptr]));
475+
some(mk_obstack_token(bcx_ccx(cx), cx.fcx.lldynamicallocas,
476+
lltaskptr));
476477
}
477478
some(_) { /* no-op */ }
478479
}
479-
ret builder.ArrayAlloca(t, n);
480+
481+
let dynastack_alloc = bcx_ccx(bcx).upcalls.dynastack_alloc;
482+
let llsz = builder.Mul(C_uint(llsize_of_real(bcx_ccx(bcx), t)), n);
483+
let llresult = builder.Call(dynastack_alloc, ~[lltaskptr, llsz]);
484+
ret builder.PointerCast(llresult, T_ptr(t));
485+
}
486+
487+
fn mk_obstack_token(ccx: &@crate_ctxt, lldynamicallocas: BasicBlockRef,
488+
lltaskptr: ValueRef) -> ValueRef {
489+
let builder = new_builder(lldynamicallocas);
490+
ret builder.Call(ccx.upcalls.dynastack_mark, ~[lltaskptr]);
480491
}
481492

482493

trunk/src/comp/middle/trans_common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ type fn_ctxt = {
217217
mutable llreturn: BasicBlockRef,
218218

219219
// The token used to clear the dynamic allocas at the end of this frame.
220-
// Will be |none| if there are no dynamic allocas.
221220
mutable llobstacktoken: option::t<ValueRef>,
222221

223222
// The 'self' object currently in use in this function, if there

trunk/src/rt/rust_obstack.cpp

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

17-
const size_t DEFAULT_CHUNK_SIZE = 4096;
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;
1823

1924
struct rust_obstack_chunk {
2025
rust_obstack_chunk *prev;
@@ -32,8 +37,13 @@ struct rust_obstack_chunk {
3237

3338
void *
3439
rust_obstack_chunk::alloc(size_t len) {
35-
if (len > size - alen)
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);
3645
return NULL; // Not enough space.
46+
}
3747
void *result = data + alen;
3848
alen += len;
3949
return result;
@@ -42,7 +52,7 @@ rust_obstack_chunk::alloc(size_t len) {
4252
bool
4353
rust_obstack_chunk::free(void *ptr) {
4454
uint8_t *p = (uint8_t *)ptr;
45-
if (p < data || p >= data + size)
55+
if (p < data || p > data + size)
4656
return false;
4757
assert(p <= data + alen);
4858
alen = (size_t)(p - data);
@@ -54,6 +64,7 @@ void *
5464
rust_obstack::alloc_new(size_t len) {
5565
size_t chunk_size = std::max(len, DEFAULT_CHUNK_SIZE);
5666
void *ptr = task->malloc(sizeof(chunk) + chunk_size, "obstack");
67+
DPRINT("making new chunk at %p, len %lu\n", ptr, chunk_size);
5768
chunk = new(ptr) rust_obstack_chunk(chunk, chunk_size);
5869
return chunk->alloc(len);
5970
}
@@ -70,8 +81,12 @@ void *
7081
rust_obstack::alloc(size_t len) {
7182
if (!chunk)
7283
return alloc_new(len);
84+
85+
DPRINT("alloc sz %u", (uint32_t)len);
86+
7387
void *ptr = chunk->alloc(len);
7488
ptr = ptr ? ptr : alloc_new(len);
89+
7590
return ptr;
7691
}
7792

@@ -80,8 +95,11 @@ rust_obstack::free(void *ptr) {
8095
if (!ptr)
8196
return;
8297

98+
DPRINT("free ptr %p\n", ptr);
99+
83100
assert(chunk);
84101
while (!chunk->free(ptr)) {
102+
DPRINT("deleting chunk at %p\n", chunk);
85103
rust_obstack_chunk *prev = chunk->prev;
86104
task->free(chunk);
87105
chunk = prev;

trunk/src/rt/rust_shape.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,6 @@ 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-
7967
// Utility classes
8068

8169
struct size_align {
@@ -185,11 +173,18 @@ class ptr_pair {
185173
}
186174
};
187175

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));
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));
191183
}
192184

185+
186+
namespace shape {
187+
193188
// NB: This function does not align.
194189
template<typename T>
195190
inline data_pair<T>

trunk/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 task->dynastack.alloc(sz);
433+
return sz ? task->dynastack.alloc(sz) : NULL;
434434
}
435435

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

trunk/src/rt/rust_util.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ 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+
128138
// Initialization helper for ISAAC RNG
129139

130140
template <typename sched_or_kernel>

0 commit comments

Comments
 (0)