Pull element init into a reusable closure
This commit is contained in:
parent
7ad45f1d2f
commit
65ea9f3eb4
1 changed files with 21 additions and 14 deletions
|
@ -93,8 +93,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match cg_elem.val {
|
let try_init_all_same = |bx: &mut Bx, v| {
|
||||||
OperandValue::Immediate(v) => {
|
|
||||||
let start = dest.val.llval;
|
let start = dest.val.llval;
|
||||||
let size = bx.const_usize(dest.layout.size.bytes());
|
let size = bx.const_usize(dest.layout.size.bytes());
|
||||||
|
|
||||||
|
@ -102,13 +101,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
if bx.cx().const_to_opt_u128(v, false) == Some(0) {
|
if bx.cx().const_to_opt_u128(v, false) == Some(0) {
|
||||||
let fill = bx.cx().const_u8(0);
|
let fill = bx.cx().const_u8(0);
|
||||||
bx.memset(start, fill, size, dest.val.align, MemFlags::empty());
|
bx.memset(start, fill, size, dest.val.align, MemFlags::empty());
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use llvm.memset.p0i8.* to initialize byte arrays
|
// Use llvm.memset.p0i8.* to initialize byte arrays
|
||||||
let v = bx.from_immediate(v);
|
let v = bx.from_immediate(v);
|
||||||
if bx.cx().val_ty(v) == bx.cx().type_i8() {
|
if bx.cx().val_ty(v) == bx.cx().type_i8() {
|
||||||
bx.memset(start, v, size, dest.val.align, MemFlags::empty());
|
bx.memset(start, v, size, dest.val.align, MemFlags::empty());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
match cg_elem.val {
|
||||||
|
OperandValue::Immediate(v) => {
|
||||||
|
if try_init_all_same(bx, v) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue