mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
use phi node in elem_loop
This commit is contained in:
parent
44e8fbc203
commit
29e7853b85
1 changed files with 8 additions and 6 deletions
|
@ -965,6 +965,8 @@ where
|
||||||
let ctx = env.context;
|
let ctx = env.context;
|
||||||
let builder = env.builder;
|
let builder = env.builder;
|
||||||
|
|
||||||
|
let entry = env.builder.get_insert_block().unwrap();
|
||||||
|
|
||||||
// constant 1i64
|
// constant 1i64
|
||||||
let one = env.ptr_int().const_int(1, false);
|
let one = env.ptr_int().const_int(1, false);
|
||||||
|
|
||||||
|
@ -976,15 +978,15 @@ where
|
||||||
builder.build_unconditional_branch(loop_bb);
|
builder.build_unconditional_branch(loop_bb);
|
||||||
builder.position_at_end(loop_bb);
|
builder.position_at_end(loop_bb);
|
||||||
|
|
||||||
let curr_index = builder
|
let current_index_phi = env.builder.build_phi(env.ptr_int(), "current_index");
|
||||||
.build_load(index_alloca, index_name)
|
let current_index = current_index_phi.as_basic_value().into_int_value();
|
||||||
.into_int_value();
|
|
||||||
let next_index = builder.build_int_add(curr_index, one, "nextindex");
|
|
||||||
|
|
||||||
builder.build_store(index_alloca, next_index);
|
let next_index = builder.build_int_add(current_index, one, "next_index");
|
||||||
|
|
||||||
|
current_index_phi.add_incoming(&[(&next_index, loop_bb), (&env.ptr_int().const_zero(), entry)]);
|
||||||
|
|
||||||
// The body of the loop
|
// The body of the loop
|
||||||
loop_fn(curr_index);
|
loop_fn(current_index);
|
||||||
|
|
||||||
// #index < end
|
// #index < end
|
||||||
let loop_end_cond = bounds_check_comparison(builder, next_index, end);
|
let loop_end_cond = bounds_check_comparison(builder, next_index, end);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue