Skip to content

Commit cab33fa

Browse files
committed
check_all_mask_blocks_eq -> check_all_mask_eq with build_mask_padding inside
1 parent a616a8e commit cab33fa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

hugr-llvm/src/extension/collections/borrow_array.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -579,17 +579,24 @@ struct MaskInfo<'a> {
579579

580580
/// Emits instructions to check all blocks of the borrowed mask are equal to `expected_val`
581581
/// or else panic with the specified error.
582-
fn check_all_mask_blocks_eq<'c, H: HugrView<Node = Node>>(
582+
fn check_all_mask_eq<'c, H: HugrView<Node = Node>>(
583583
ccg: &impl BorrowArrayCodegen,
584584
ctx: &mut EmitFuncContext<'c, '_, H>,
585585
mask_info: &MaskInfo<'c>,
586-
expected_val: IntValue<'c>,
586+
expected: bool,
587587
err: &ConstError,
588588
) -> Result<()> {
589+
build_mask_padding(ctx, mask_info, expected)?;
590+
589591
let builder = ctx.builder();
590592
let end_idx = builder.build_int_add(mask_info.offset, mask_info.size, "")?;
591593

592594
let usize_t = usize_ty(&ctx.typing_session());
595+
let expected_val = if expected {
596+
usize_t.const_all_ones()
597+
} else {
598+
usize_t.const_zero()
599+
};
593600
let block_size = usize_t.const_int(usize_t.get_bit_width() as u64, false);
594601
let start_block = builder.build_int_unsigned_div(mask_info.offset, block_size, "")?;
595602
let end_block = builder.build_int_unsigned_div(end_idx, block_size, "")?;
@@ -811,8 +818,7 @@ pub fn build_none_borrowed_check<'c, H: HugrView<Node = Node>>(
811818
offset,
812819
size,
813820
};
814-
build_mask_padding(ctx, &info, false)?;
815-
check_all_mask_blocks_eq(ccg, ctx, &info, usize_t.const_zero(), &ERR_SOME_BORROWED)?;
821+
check_all_mask_eq(ccg, ctx, &info, false, &ERR_SOME_BORROWED)?;
816822
Ok(None)
817823
},
818824
)?;
@@ -849,9 +855,7 @@ pub fn build_all_borrowed_check<'c, H: HugrView<Node = Node>>(
849855
offset,
850856
size,
851857
};
852-
build_mask_padding(ctx, &info, true)?;
853-
let ones = usize_t.const_all_ones();
854-
check_all_mask_blocks_eq(ccg, ctx, &info, ones, &ERR_NOT_ALL_BORROWED)?;
858+
check_all_mask_eq(ccg, ctx, &info, true, &ERR_NOT_ALL_BORROWED)?;
855859
Ok(None)
856860
},
857861
)?;

0 commit comments

Comments
 (0)