Skip to content

Commit 7b245d4

Browse files
committed
librustc: Stop generating first-class aggregates in visit glue, since they kick us off fast isel. Closes #4352. rs=minor-perf-improvement
1 parent 9abcacc commit 7b245d4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ fn C_cstr(cx: @crate_ctxt, s: ~str) -> ValueRef {
10941094
return g;
10951095
}
10961096
1097+
// NB: Do not use `do_spill_noroot` to make this into a constant string, or
1098+
// you will be kicked off fast isel. See issue #4352 for an example of this.
10971099
fn C_estr_slice(cx: @crate_ctxt, s: ~str) -> ValueRef {
10981100
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s), T_ptr(T_i8()));
10991101
C_struct(~[cs, C_uint(cx, str::len(s) + 1u /* +1 for null */)])

src/librustc/middle/trans/reflect.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ impl reflector {
4646
}
4747

4848
fn c_slice(s: ~str) -> ValueRef {
49-
let ss = C_estr_slice(self.bcx.ccx(), s);
50-
do_spill_noroot(self.bcx, ss)
49+
// We're careful to not use first class aggregates here because that
50+
// will kick us off fast isel. (Issue #4352.)
51+
let bcx = self.bcx;
52+
let str_vstore = ty::vstore_slice(ty::re_static);
53+
let str_ty = ty::mk_estr(bcx.tcx(), str_vstore);
54+
let scratch = scratch_datum(bcx, str_ty, false);
55+
let c_str = PointerCast(bcx, C_cstr(bcx.ccx(), s), T_ptr(T_i8()));
56+
Store(bcx, c_str, GEPi(bcx, scratch.val, [ 0, 0 ]));
57+
let len = C_uint(bcx.ccx(), s.len() + 1);
58+
Store(bcx, len, GEPi(bcx, scratch.val, [ 0, 1 ]));
59+
scratch.val
5160
}
5261

5362
fn c_size_and_align(t: ty::t) -> ~[ValueRef] {

0 commit comments

Comments
 (0)