Expand description
Codegen for prelude borrow array operations.
A borrow_array<n, T> is lowered to a fat pointer {ptr, mask_ptr, usize} that is
allocated to at least n * sizeof(T) bytes. The second pointer is a bit-packed mask
storing which array elements have been borrowed (1=borrowed, 0=available). It should
be allocated to at least ceil(n / sizeof(usize)) * sizeof(usize) bytes. The extra
usize is an offset pointing to the first element, i.e. the first element is at address
ptr + offset * sizeof(T).
The rationale behind the additional offset is the pop_left operation which bumps
the offset instead of mutating the pointer. This way, we can still free the original
pointer when the array is discarded after a pop.
We provide utility functions barray_fat_pointer_ty, build_barray_fat_pointer, and
decompose_barray_fat_pointer to work with borrow-array fat pointers.
The DefaultBorrowArrayCodegen extension allocates all arrays on the heap using the
standard libc malloc and free functions. This behaviour can be customised
by providing a different implementation for BorrowArrayCodegen::emit_allocate_array
and BorrowArrayCodegen::emit_free_array.
Structs§
- BArray
FatPtr Components - Borrow
Array Codegen Extension - Default
Borrow Array Codegen - A trivial implementation of
BorrowArrayCodegenwhich passes all methods through to their default implementations.
Traits§
- Borrow
Array Codegen - A helper trait for customising the lowering of
borrow_array, including its types,hugr_core::ops::constant::CustomConsts, and ops.
Functions§
- barray_
fat_ pointer_ ty - Returns the LLVM representation of a borrow array value as a fat pointer.
- build_
all_ borrowed_ check - Emits a check that all array elements have been borrowed.
- build_
barray_ alloc - Helper function to allocate a fat borrow array pointer.
- build_
barray_ fat_ pointer - Constructs a borrow array fat pointer value.
- build_
bounds_ check - Emits a check that a specified (unsigned) index is less than the size of the array
- build_
is_ borrowed_ bit - Emits a check that returns whether a specific array element is borrowed (true) or not (false).
- build_
none_ borrowed_ check - Emits a check that no array elements have been borrowed.
- decompose_
barray_ fat_ pointer - Returns the underlying pointer, mask and offset stored in a fat borrow array pointer.
- emit_
barray_ discard - Emits an
BArrayDiscardop. - emit_
barray_ op - Emits an
BArrayOp. - emit_
barray_ unsafe_ op - Emits an
BArrayUnsafeOp. - emit_
barray_ value - Emits an
borrow_array::BArrayValue. - emit_
clone_ op - Emits an
BArrayCloneop. - emit_
from_ array_ op - Emits an
BArrayFromArrayop. - emit_
repeat_ op - Emits an
BArrayRepeatop. - emit_
scan_ op - Emits an
BArrayScanop. - emit_
to_ array_ op - Emits an
BArrayToArrayop.