Skip to content

Commit 00c5652

Browse files
committed
---
yaml --- r: 30107 b: refs/heads/incoming c: ff9151f h: refs/heads/master i: 30105: 28463db 30103: 2c26edf v: v3
1 parent c46f4a8 commit 00c5652

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: db71ff3eb61bbce3123f62b274100dadf5ca99a6
9+
refs/heads/incoming: ff9151fa55e4e81c0cbaa7181eb672b2df6b53f6
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/rustc/middle/trans/base.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ fn alloca_maybe_zeroed(cx: block, t: TypeRef, zero: bool) -> ValueRef {
278278
if cx.unreachable { return llvm::LLVMGetUndef(t); }
279279
let initcx = raw_block(cx.fcx, false, cx.fcx.llstaticallocas);
280280
let p = Alloca(initcx, t);
281-
if zero { Store(initcx, C_null(t), p); }
281+
if zero { memzero(initcx, p, t); }
282282
return p;
283283
}
284284

@@ -287,10 +287,38 @@ fn zero_mem(cx: block, llptr: ValueRef, t: ty::t) -> block {
287287
let bcx = cx;
288288
let ccx = cx.ccx();
289289
let llty = type_of(ccx, t);
290-
Store(bcx, C_null(llty), llptr);
290+
memzero(bcx, llptr, llty);
291291
return bcx;
292292
}
293293

294+
// Always use this function instead of storing a zero constant to the memory
295+
// in question. If you store a zero constant, LLVM will drown in vreg
296+
// allocation for large data structures, and the generated code will be
297+
// awful. (A telltale sign of this is large quantities of
298+
// `mov [byte ptr foo],0` in the generated code.)
299+
fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
300+
let _icx = cx.insn_ctxt("memzero");
301+
let ccx = cx.ccx();
302+
303+
let intrinsic_key;
304+
match ccx.sess.targ_cfg.arch {
305+
session::arch_x86 | session::arch_arm => {
306+
intrinsic_key = ~"llvm.memset.p0i8.i32";
307+
}
308+
session::arch_x86_64 => {
309+
intrinsic_key = ~"llvm.memset.p0i8.i64";
310+
}
311+
}
312+
313+
let llintrinsicfn = ccx.intrinsics.get(intrinsic_key);
314+
let llptr = PointerCast(cx, llptr, T_ptr(T_i8()));
315+
let llzeroval = C_u8(0);
316+
let size = IntCast(cx, llsize_of(ccx, llty), ccx.int_type);
317+
let align = C_i32(1i32);
318+
let volatile = C_bool(false);
319+
Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]);
320+
}
321+
294322
fn arrayalloca(cx: block, t: TypeRef, v: ValueRef) -> ValueRef {
295323
let _icx = cx.insn_ctxt("arrayalloca");
296324
if cx.unreachable { return llvm::LLVMGetUndef(t); }

0 commit comments

Comments
 (0)