From d6113bc2d28feffe83556d8839b489663f932266 Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 15 Aug 2024 13:44:31 +0800 Subject: [PATCH] [artiq] WIP --- nac3artiq/src/codegen.rs | 46 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/nac3artiq/src/codegen.rs b/nac3artiq/src/codegen.rs index c86766e9..77de4214 100644 --- a/nac3artiq/src/codegen.rs +++ b/nac3artiq/src/codegen.rs @@ -600,8 +600,9 @@ fn format_rpc_ret<'ctx>( let dims_buf_sz = ctx.builder.build_int_mul(ndarray.load_ndims(ctx), llvm_usize_sizeof, "").unwrap(); - let buffer_size = - ctx.builder.build_int_add(dims_buf_sz, llvm_pdata_sizeof, "").unwrap(); + // let buffer_size = + // ctx.builder.build_int_add(dims_buf_sz, llvm_pdata_sizeof, "").unwrap(); + let buffer_size = llvm_usize.const_int(32, false); let buffer = 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, "") .map(BasicValueEnum::into_pointer_value) .unwrap(); - let buffer = ArraySliceValue::from_ptr_val( - buffer, - ctx.builder - .build_left_shift(buffer_size, llvm_usize.const_int(2, false), "") - .unwrap(), - Some("rpc.buffer.ptr"), - ); + let buffer = ArraySliceValue::from_ptr_val(buffer, buffer_size, Some("rpc.buffer.ptr")); let i_addr = ctx.builder.build_alloca(llvm_usize, "i.addr").unwrap(); ctx.builder.build_store(i_addr, llvm_usize.const_zero()).unwrap(); @@ -647,36 +642,22 @@ fn format_rpc_ret<'ctx>( .unwrap()) }, |generator, ctx| { - // let data_addr = ctx - // .builder - // .build_load( - // ctx.builder - // .build_bitcast(data_addr, llvm_ppi8, "") - // .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(), - // ); + let phi = phi.as_basic_value().into_pointer_value(); + let pbuffer_data_begin = unsafe { + ctx.builder.build_in_bounds_gep(phi, &[llvm_usize.const_int(8, false)], "") + } + .unwrap(); call_memcpy_generic( ctx, ndarray.ptr_to_data(ctx), - buffer.base_ptr(ctx, generator), + pbuffer_data_begin, llvm_pdata_sizeof, llvm_i1.const_zero(), ); - let pbuffer_dims_begin = unsafe { - buffer.ptr_offset_unchecked(ctx, generator, &llvm_pdata_sizeof, None) - }; + let pbuffer_dims_begin = + unsafe { ctx.builder.build_in_bounds_gep(phi, &[llvm_pdata_sizeof], "") } + .unwrap(); call_memcpy_generic( ctx, 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.position_at_end(tail_bb); - ctx.builder.build_load(slot, "rpc.result").unwrap() } };