[artiq] WIP

This commit is contained in:
David Mak 2024-08-15 13:44:31 +08:00
parent c00f6939e9
commit 5d11c78fa4
1 changed files with 13 additions and 33 deletions

View File

@ -600,8 +600,9 @@ fn format_rpc_ret<'ctx>(
let dims_buf_sz = let dims_buf_sz =
ctx.builder.build_int_mul(ndarray.load_ndims(ctx), llvm_usize_sizeof, "").unwrap(); ctx.builder.build_int_mul(ndarray.load_ndims(ctx), llvm_usize_sizeof, "").unwrap();
let buffer_size = // let buffer_size =
ctx.builder.build_int_add(dims_buf_sz, llvm_pdata_sizeof, "").unwrap(); // ctx.builder.build_int_add(dims_buf_sz, llvm_pdata_sizeof, "").unwrap();
let buffer_size = llvm_usize.const_int(12, false);
let buffer = let buffer =
ctx.builder.build_array_alloca(llvm_pi8, buffer_size, "rpc.buffer").unwrap(); ctx.builder.build_array_alloca(llvm_pi8, buffer_size, "rpc.buffer").unwrap();
@ -610,13 +611,7 @@ fn format_rpc_ret<'ctx>(
.build_bitcast(buffer, llvm_pi8, "") .build_bitcast(buffer, llvm_pi8, "")
.map(BasicValueEnum::into_pointer_value) .map(BasicValueEnum::into_pointer_value)
.unwrap(); .unwrap();
let buffer = ArraySliceValue::from_ptr_val( let buffer = ArraySliceValue::from_ptr_val(buffer, buffer_size, Some("rpc.buffer.ptr"));
buffer,
ctx.builder
.build_left_shift(buffer_size, llvm_usize.const_int(2, false), "")
.unwrap(),
Some("rpc.buffer.ptr"),
);
let i_addr = ctx.builder.build_alloca(llvm_usize, "i.addr").unwrap(); let i_addr = ctx.builder.build_alloca(llvm_usize, "i.addr").unwrap();
ctx.builder.build_store(i_addr, llvm_usize.const_zero()).unwrap(); ctx.builder.build_store(i_addr, llvm_usize.const_zero()).unwrap();
@ -647,36 +642,22 @@ fn format_rpc_ret<'ctx>(
.unwrap()) .unwrap())
}, },
|generator, ctx| { |generator, ctx| {
// let data_addr = ctx let phi = phi.as_basic_value().into_pointer_value();
// .builder let pbuffer_data_begin = unsafe {
// .build_load( ctx.builder.build_in_bounds_gep(phi, &[llvm_usize.const_int(8, false)], "")
// ctx.builder }
// .build_bitcast(data_addr, llvm_ppi8, "") .unwrap();
// .map(BasicValueEnum::into_pointer_value)
// .unwrap(),
// "",
// )
// .map(BasicValueEnum::into_pointer_value)
// .unwrap();
//
// call_memcpy_generic(
// ctx,
// ndarray.ptr_to_data(ctx),
// data_addr,
// llvm_pdata_sizeof,
// llvm_i1.const_zero(),
// );
call_memcpy_generic( call_memcpy_generic(
ctx, ctx,
ndarray.ptr_to_data(ctx), ndarray.ptr_to_data(ctx),
buffer.base_ptr(ctx, generator), pbuffer_data_begin,
llvm_pdata_sizeof, llvm_pdata_sizeof,
llvm_i1.const_zero(), llvm_i1.const_zero(),
); );
let pbuffer_dims_begin = unsafe { let pbuffer_dims_begin =
buffer.ptr_offset_unchecked(ctx, generator, &llvm_pdata_sizeof, None) unsafe { ctx.builder.build_in_bounds_gep(phi, &[llvm_pdata_sizeof], "") }
}; .unwrap();
call_memcpy_generic( call_memcpy_generic(
ctx, ctx,
ndarray.dim_sizes().base_ptr(ctx, generator), ndarray.dim_sizes().base_ptr(ctx, generator),
@ -760,7 +741,6 @@ fn format_rpc_ret<'ctx>(
ctx.builder.build_unconditional_branch(head_bb).unwrap(); ctx.builder.build_unconditional_branch(head_bb).unwrap();
ctx.builder.position_at_end(tail_bb); ctx.builder.position_at_end(tail_bb);
ctx.builder.build_load(slot, "rpc.result").unwrap() ctx.builder.build_load(slot, "rpc.result").unwrap()
} }
}; };