Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bdc4795
Make copy of existing array lowering
mark-koch Sep 15, 2025
5bc67e3
Rename everything
mark-koch Sep 15, 2025
fe5d575
Implement bitmask lowering
mark-koch Sep 22, 2025
b23b593
Handle 0 sized arrays
mark-koch Sep 29, 2025
b3d5b8e
Clippy
mark-koch Sep 29, 2025
877771c
Stop using lazy_static
mark-koch Sep 29, 2025
924a6d3
Fix docs
mark-koch Sep 29, 2025
2d19e2f
Refactor and rename outline_into_function
mark-koch Sep 29, 2025
cb58a3a
Rename ERR_NOT_FREE to ERR_NOT_BORROWED
mark-koch Sep 29, 2025
56eee57
Add codegen for conversion ops
mark-koch Sep 30, 2025
439f09c
refactor: allow non-void get_or_make_function (#2609)
ss2165 Oct 6, 2025
437762e
comments
acl-cqc Oct 6, 2025
1775208
Avoid a match using .as_ref().map::<&dyn BasicValue,_>
acl-cqc Oct 6, 2025
207b254
rename toplevel funcs to be consistent
acl-cqc Oct 6, 2025
f729f34
Inline variable 'memset_intrinsic'; outline i8t with comment
acl-cqc Oct 6, 2025
e3ee86d
inspect_mask_idx closure adds terminator
acl-cqc Oct 6, 2025
975771e
inspect_mask_blocks takes expected value and error message rather tha…
acl-cqc Oct 6, 2025
a33d99c
rename inspect_mask_blocks, doc
acl-cqc Oct 7, 2025
aaac55c
update snapshots due to renaming of blocks
acl-cqc Oct 7, 2025
a616a8e
also pass MaskInfo into build_mask_padding
acl-cqc Oct 7, 2025
cab33fa
check_all_mask_blocks_eq -> check_all_mask_eq with build_mask_padding…
acl-cqc Oct 7, 2025
72e7c54
switch triple to struct BArrayFatPtrComponents
acl-cqc Oct 7, 2025
4cc2bca
A load more discard_all_borrowed_panic tests...all passing
acl-cqc Oct 7, 2025
9b6299c
Test returning just one index to an array of all-borrowed...still all…
acl-cqc Oct 7, 2025
073d039
more tests, finally demonstrating the problem(s?)
acl-cqc Oct 7, 2025
202dc48
fix shifting in one direction only, with llvm test
acl-cqc Oct 7, 2025
d5d5999
fix: reorder loads/stores in build_mask_padding
acl-cqc Oct 7, 2025
4a64ae4
Fix accessing/padding beyond end of mask
acl-cqc Oct 7, 2025
6c45cbf
trivial refactor: pass last_idx into build_mask_padding, avoids recom…
acl-cqc Oct 7, 2025
e619155
refactor: split build_mask_padding into two calls
acl-cqc Oct 7, 2025
bf4b6d6
refactor: build_mask_padding1d tests value before direction, some com…
acl-cqc Oct 7, 2025
b056e4d
build_barray_alloc: do not return mask_ptr
acl-cqc Oct 7, 2025
b80bc0e
build_barray_fat_pointer takes BArrayFatPointerComponents
acl-cqc Oct 7, 2025
5ca60ce
build_(idx_(free,not_borrowed)_check,mask_flip) -> check_mask_eq(enum…
acl-cqc Oct 7, 2025
dc99387
Avoid xor in mask-check methods by flipping bbs; update more snapshots
acl-cqc Oct 8, 2025
c2cdf79
common up array allocation w/bit-cast
acl-cqc Oct 8, 2025
6cf427b
check_mask_idx -> check_mask_elem, does not check the index is correct
acl-cqc Oct 8, 2025
e5a364a
refactor: Make check_mask_elem into MaskCheck.emit
acl-cqc Oct 8, 2025
b7e50ab
refactor: rename CheckPresent -> CheckNotBorrowed
acl-cqc Oct 8, 2025
5aaba8f
doc MaskCheck
acl-cqc Oct 8, 2025
14dced7
Merge remote-tracking branch 'origin/main' into feat/barray-llvm
acl-cqc Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugr-core/src/std_extensions/collections/borrow_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ pub trait BArrayOpBuilder: GenericArrayOpBuilder {
elem_ty: Type,
input: Wire,
) -> Result<(), BuildError> {
self.add_generic_array_discard_empty::<Array>(elem_ty, input)
self.add_generic_array_discard_empty::<BorrowArray>(elem_ty, input)
}

/// Adds a borrow array borrow operation to the dataflow graph.
Expand Down
70 changes: 67 additions & 3 deletions hugr-llvm/src/emit/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use inkwell::{
basic_block::BasicBlock,
builder::Builder,
context::Context,
module::Module,
module::{Linkage, Module},
types::{BasicType, BasicTypeEnum, FunctionType},
values::{BasicValueEnum, FunctionValue, GlobalValue, IntValue},
values::{BasicValue, BasicValueEnum, FunctionValue, GlobalValue, IntValue},
};
use itertools::zip_eq;
use itertools::{Itertools, zip_eq};

use crate::types::{HugrFuncType, HugrSumType, HugrType, TypingSession};
use crate::{custom::CodegenExtsMap, types::LLVMSumType, utils::fat::FatNode};
Expand Down Expand Up @@ -357,6 +357,70 @@ pub fn build_ok_or_else<'c, H: HugrView<Node = Node>>(
let either = builder.build_select(is_ok, right, left, "")?;
Ok(either)
}
/// Helper to outline LLVM IR into a function call instead of inlining it every time.
///
/// The first time this helper is called with a given function name, a function is built
/// using the provided closure. Future invocations with the same name will just emit calls
/// to this function.
///
/// The return type is specified by `ret_type`, and if `Some` then the closure must return
/// a value of that type, which will be returned from the function. Otherwise, the function
/// will return void.
pub fn get_or_make_function<'c, H: HugrView<Node = Node>, const N: usize>(
ctx: &mut EmitFuncContext<'c, '_, H>,
func_name: &str,
args: [BasicValueEnum<'c>; N],
ret_type: Option<BasicTypeEnum<'c>>,
go: impl FnOnce(
&mut EmitFuncContext<'c, '_, H>,
[BasicValueEnum<'c>; N],
) -> Result<Option<BasicValueEnum<'c>>>,
) -> Result<Option<BasicValueEnum<'c>>> {
let func = match ctx.get_current_module().get_function(func_name) {
Some(func) => func,
None => {
let arg_tys = args.iter().map(|v| v.get_type().into()).collect_vec();
let sig = match ret_type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bizarre here that BasicTypeEnum and VoidType define fn_type as two completely unrelated methods! But yeah I don't see a better way :(

Some(ret_ty) => ret_ty.fn_type(&arg_tys, false),
None => ctx.iw_context().void_type().fn_type(&arg_tys, false),
};
let func =
ctx.get_current_module()
.add_function(func_name, sig, Some(Linkage::Internal));
let bb = ctx.iw_context().append_basic_block(func, "");
let args = (0..N)
.map(|i| func.get_nth_param(i as u32).unwrap())
.collect_array()
.unwrap();

let curr_bb = ctx.builder().get_insert_block().unwrap();
let curr_func = ctx.func;

ctx.builder().position_at_end(bb);
ctx.func = func;
let ret_val = go(ctx, args)?;
if ctx
.builder()
.get_insert_block()
.unwrap()
.get_terminator()
.is_none()
{
ctx.builder()
.build_return(ret_val.as_ref().map::<&dyn BasicValue, _>(|v| v))?;
}

ctx.builder().position_at_end(curr_bb);
ctx.func = curr_func;
func
}
};
let call_site =
ctx.builder()
.build_call(func, &args.iter().map(|&a| a.into()).collect_vec(), "")?;
let result = call_site.try_as_basic_value().left();
Ok(result)
}

#[cfg(test)]
mod tests {
Expand Down
1 change: 1 addition & 0 deletions hugr-llvm/src/extension/collections.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Emission logic for collections.

pub mod array;
pub mod borrow_array;
pub mod list;
pub mod stack_array;
pub mod static_array;
Loading
Loading