mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Entire inner loop happens in phi2 node, rather than phi2 node happening inside loop
This commit is contained in:
parent
0e15f75f3b
commit
e47c847118
1 changed files with 51 additions and 54 deletions
|
@ -1698,17 +1698,19 @@ fn list_join<'a, 'ctx, 'env>(
|
|||
// Inner Loop
|
||||
{
|
||||
let inner_list_len = load_list_len(builder, inner_list_wrapper);
|
||||
let inner_list_ptr =
|
||||
load_list_ptr(builder, inner_list_wrapper, elem_ptr_type);
|
||||
|
||||
// inner_list_len > 0
|
||||
let inner_list_comparison = builder.build_int_compare(
|
||||
IntPredicate::UGT,
|
||||
inner_list_len,
|
||||
ctx.i64_type().const_int(0, false),
|
||||
"greaterthanzero",
|
||||
);
|
||||
let inner_list_comparison = list_is_not_empty(builder, ctx, inner_list_len);
|
||||
|
||||
let build_empty = || {
|
||||
BasicValueEnum::PointerValue(
|
||||
builder
|
||||
.build_load(dest_elem_ptr_alloca, "load_dest_elem_ptr")
|
||||
.into_pointer_value(),
|
||||
)
|
||||
};
|
||||
|
||||
let build_non_empty = || {
|
||||
let inner_index_name = "#inner_index";
|
||||
let inner_index_alloca =
|
||||
builder.build_alloca(ctx.i64_type(), inner_index_name);
|
||||
|
@ -1732,17 +1734,10 @@ fn list_join<'a, 'ctx, 'env>(
|
|||
|
||||
builder.build_store(inner_index_alloca, next_inner_index);
|
||||
|
||||
let build_empty = || {
|
||||
BasicValueEnum::PointerValue(
|
||||
builder
|
||||
.build_load(dest_elem_ptr_alloca, "load_dest_elem_ptr")
|
||||
// .into_int_value()
|
||||
.into_pointer_value(),
|
||||
)
|
||||
};
|
||||
|
||||
let build_non_empty = || {
|
||||
let src_elem_ptr = unsafe {
|
||||
let inner_list_ptr =
|
||||
load_list_ptr(builder, inner_list_wrapper, elem_ptr_type);
|
||||
|
||||
builder.build_in_bounds_gep(
|
||||
inner_list_ptr,
|
||||
&[curr_inner_index],
|
||||
|
@ -1759,28 +1754,15 @@ fn list_join<'a, 'ctx, 'env>(
|
|||
|
||||
builder.build_store(curr_dest_elem_ptr, src_elem);
|
||||
|
||||
BasicValueEnum::PointerValue(unsafe {
|
||||
let inc_dest_elem_ptr = BasicValueEnum::PointerValue(unsafe {
|
||||
builder.build_in_bounds_gep(
|
||||
curr_dest_elem_ptr,
|
||||
&[env.ptr_int().const_int(1 as u64, false)],
|
||||
"increment_dest_elem",
|
||||
)
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
let next_dest_elem_ptr = build_basic_phi2(
|
||||
env,
|
||||
parent,
|
||||
inner_list_comparison,
|
||||
build_non_empty,
|
||||
build_empty,
|
||||
BasicTypeEnum::PointerType(get_ptr_type(
|
||||
&elem_type,
|
||||
AddressSpace::Generic,
|
||||
)),
|
||||
);
|
||||
|
||||
builder.build_store(dest_elem_ptr_alloca, next_dest_elem_ptr);
|
||||
builder.build_store(dest_elem_ptr_alloca, inc_dest_elem_ptr);
|
||||
|
||||
let inner_loop_end_cond = builder.build_int_compare(
|
||||
IntPredicate::ULT,
|
||||
|
@ -1798,6 +1780,21 @@ fn list_join<'a, 'ctx, 'env>(
|
|||
after_inner_loop_bb,
|
||||
);
|
||||
builder.position_at_end(after_inner_loop_bb);
|
||||
|
||||
inc_dest_elem_ptr
|
||||
};
|
||||
|
||||
build_basic_phi2(
|
||||
env,
|
||||
parent,
|
||||
inner_list_comparison,
|
||||
build_non_empty,
|
||||
build_empty,
|
||||
BasicTypeEnum::PointerType(get_ptr_type(
|
||||
&elem_type,
|
||||
AddressSpace::Generic,
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
// #index < outer_list_len
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue