Simplify the codegen in iter_vec_loop

No need to create a bunch of blocks and a stack allocated temporary just
to build a simple loop.
This commit is contained in:
Björn Steinbrink 2015-02-17 10:40:46 +01:00
parent f1bb6c2f46
commit 378abdbde7

View File

@ -426,49 +426,26 @@ pub fn iter_vec_loop<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
let _icx = push_ctxt("tvec::iter_vec_loop"); let _icx = push_ctxt("tvec::iter_vec_loop");
let fcx = bcx.fcx; let fcx = bcx.fcx;
let next_bcx = fcx.new_temp_block("expr_repeat: while next");
let loop_bcx = fcx.new_temp_block("expr_repeat"); let loop_bcx = fcx.new_temp_block("expr_repeat");
let cond_bcx = fcx.new_temp_block("expr_repeat: loop cond"); let next_bcx = fcx.new_temp_block("expr_repeat: next");
let body_bcx = fcx.new_temp_block("expr_repeat: body: set");
let inc_bcx = fcx.new_temp_block("expr_repeat: body: inc");
Br(bcx, loop_bcx.llbb, DebugLoc::None); Br(bcx, loop_bcx.llbb, DebugLoc::None);
let loop_counter = { let loop_counter = Phi(loop_bcx, bcx.ccx().int_type(), &[C_uint(bcx.ccx(), 0us)], &[bcx.llbb]);
// i = 0
let i = alloca(loop_bcx, bcx.ccx().int_type(), "__i");
Store(loop_bcx, C_uint(bcx.ccx(), 0us), i);
Br(loop_bcx, cond_bcx.llbb, DebugLoc::None); let bcx = loop_bcx;
i
let lleltptr = if vt.llunit_alloc_size == 0 {
data_ptr
} else {
InBoundsGEP(bcx, data_ptr, &[loop_counter])
}; };
let bcx = f(bcx, lleltptr, vt.unit_ty);
let plusone = Add(bcx, loop_counter, C_uint(bcx.ccx(), 1us), DebugLoc::None);
AddIncomingToPhi(loop_counter, plusone, bcx.llbb);
{ // i < count let cond_val = ICmp(bcx, llvm::IntULT, plusone, count, DebugLoc::None);
let lhs = Load(cond_bcx, loop_counter); CondBr(bcx, cond_val, loop_bcx.llbb, next_bcx.llbb, DebugLoc::None);
let rhs = count;
let cond_val = ICmp(cond_bcx, llvm::IntULT, lhs, rhs, DebugLoc::None);
CondBr(cond_bcx, cond_val, body_bcx.llbb, next_bcx.llbb, DebugLoc::None);
}
{ // loop body
let i = Load(body_bcx, loop_counter);
let lleltptr = if vt.llunit_alloc_size == 0 {
data_ptr
} else {
InBoundsGEP(body_bcx, data_ptr, &[i])
};
let body_bcx = f(body_bcx, lleltptr, vt.unit_ty);
Br(body_bcx, inc_bcx.llbb, DebugLoc::None);
}
{ // i += 1
let i = Load(inc_bcx, loop_counter);
let plusone = Add(inc_bcx, i, C_uint(bcx.ccx(), 1us), DebugLoc::None);
Store(inc_bcx, plusone, loop_counter);
Br(inc_bcx, cond_bcx.llbb, DebugLoc::None);
}
next_bcx next_bcx
} }