Skip to content

Commit 869b2d7

Browse files
committed
Send string concatenation to specialized upcall, shave 17s off librustc compile time.
1 parent bbfa08d commit 869b2d7

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

src/rt/rust_upcall.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,34 @@ upcall_vec_grow(rust_vec** vp, size_t new_sz) {
309309
UPCALL_SWITCH_STACK(&args, upcall_s_vec_grow);
310310
}
311311

312+
struct s_str_concat_args {
313+
rust_vec* lhs;
314+
rust_vec* rhs;
315+
rust_vec* retval;
316+
};
317+
318+
extern "C" CDECL void
319+
upcall_s_str_concat(s_str_concat_args *args) {
320+
rust_vec *lhs = args->lhs;
321+
rust_vec *rhs = args->rhs;
322+
rust_task *task = rust_task_thread::get_task();
323+
size_t fill = lhs->fill + rhs->fill - 1;
324+
rust_vec* v = (rust_vec*)task->kernel->malloc(fill + sizeof(rust_vec),
325+
"str_concat");
326+
v->fill = v->alloc = fill;
327+
memmove(&v->data[0], &lhs->data[0], lhs->fill - 1);
328+
memmove(&v->data[lhs->fill - 1], &rhs->data[0], rhs->fill);
329+
args->retval = v;
330+
}
331+
332+
extern "C" CDECL rust_vec*
333+
upcall_str_concat(rust_vec* lhs, rust_vec* rhs) {
334+
s_str_concat_args args = {lhs, rhs, 0};
335+
UPCALL_SWITCH_STACK(&args, upcall_s_str_concat);
336+
return args.retval;
337+
}
338+
339+
312340
extern "C" _Unwind_Reason_Code
313341
__gxx_personality_v0(int version,
314342
_Unwind_Action actions,

src/rt/rustrt.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ upcall_shared_malloc
6767
upcall_shared_free
6868
upcall_shared_realloc
6969
upcall_vec_grow
70+
upcall_str_concat
7071
upcall_call_shim_on_c_stack
7172
upcall_call_shim_on_rust_stack
7273
upcall_new_stack

src/rustc/back/upcall.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type upcalls =
1818
mark: ValueRef,
1919
vec_grow: ValueRef,
2020
vec_push: ValueRef,
21+
str_concat: ValueRef,
2122
cmp_type: ValueRef,
2223
log_type: ValueRef,
2324
alloc_c_stack: ValueRef,
@@ -69,6 +70,9 @@ fn declare_upcalls(targ_cfg: @session::config,
6970
dvi("vec_push",
7071
[T_ptr(T_ptr(opaque_vec_t)), T_ptr(tydesc_type),
7172
T_ptr(T_i8())]),
73+
str_concat:
74+
d("str_concat", [T_ptr(opaque_vec_t), T_ptr(opaque_vec_t)],
75+
T_ptr(opaque_vec_t)),
7276
cmp_type:
7377
dv("cmp_type",
7478
[T_ptr(T_i1()), T_ptr(tydesc_type),

src/rustc/middle/trans/tvec.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,16 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
194194
fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
195195
rhs: ValueRef, dest: dest) -> block {
196196
let ccx = bcx.ccx();
197-
let strings = alt ty::get(vec_ty).struct {
198-
ty::ty_str { true }
199-
_ { false }
200-
};
197+
198+
if ty::get(vec_ty).struct == ty::ty_str {
199+
let n = Call(bcx, ccx.upcalls.str_concat, [lhs, rhs]);
200+
ret base::store_in_dest(bcx, n, dest);
201+
}
202+
201203
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
202204
let llunitty = type_of::type_of(ccx, unit_ty);
203205

204206
let lhs_fill = get_fill(bcx, lhs);
205-
if strings { lhs_fill = Sub(bcx, lhs_fill, C_int(ccx, 1)); }
206207
let rhs_fill = get_fill(bcx, rhs);
207208
let new_fill = Add(bcx, lhs_fill, rhs_fill);
208209
let {bcx: bcx, val: new_vec_ptr} = alloc_raw(bcx, new_fill, new_fill);

0 commit comments

Comments
 (0)