forked from M-Labs/nac3
core: fix new irrt ndarray issues
This commit is contained in:
parent
d92cccb85e
commit
0cc7e41c6f
|
@ -204,7 +204,7 @@ fn call_nac3_ndarray_set_strides_by_shape<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
FunctionBuilder::begin(
|
FunctionBuilder::begin(
|
||||||
ctx,
|
ctx,
|
||||||
&get_sized_dependent_function_name(sizet, "__nac3_ndarray_util_assert_shape_no_negative"),
|
&get_sized_dependent_function_name(sizet, "__nac3_ndarray_set_strides_by_shape"),
|
||||||
)
|
)
|
||||||
.arg("ndarray", &PointerModel(StructModel(NpArray { sizet })), ndarray_ptr)
|
.arg("ndarray", &PointerModel(StructModel(NpArray { sizet })), ndarray_ptr)
|
||||||
.returning_void();
|
.returning_void();
|
||||||
|
@ -217,10 +217,7 @@ fn call_nac3_ndarray_nbytes<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
) -> Int<'ctx> {
|
) -> Int<'ctx> {
|
||||||
let sizet = IntModel(generator.get_size_type(ctx.ctx));
|
let sizet = IntModel(generator.get_size_type(ctx.ctx));
|
||||||
|
|
||||||
FunctionBuilder::begin(
|
FunctionBuilder::begin(ctx, &get_sized_dependent_function_name(sizet, "__nac3_ndarray_nbytes"))
|
||||||
ctx,
|
|
||||||
&get_sized_dependent_function_name(sizet, "__nac3_ndarray_util_assert_shape_no_negative"),
|
|
||||||
)
|
|
||||||
.arg("ndarray", &PointerModel(StructModel(NpArray { sizet })), ndarray_ptr)
|
.arg("ndarray", &PointerModel(StructModel(NpArray { sizet })), ndarray_ptr)
|
||||||
.returning("nbytes", &sizet)
|
.returning("nbytes", &sizet)
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,4 +77,16 @@ impl<'ctx> OpaquePointer<'ctx> {
|
||||||
pub fn store(&self, ctx: &CodeGenContext<'ctx, '_>, value: BasicValueEnum<'ctx>) {
|
pub fn store(&self, ctx: &CodeGenContext<'ctx, '_>, value: BasicValueEnum<'ctx>) {
|
||||||
ctx.builder.build_store(self.0, value).unwrap();
|
ctx.builder.build_store(self.0, value).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_ptr(ctx: &CodeGenContext<'ctx, '_>, ptr: PointerValue<'ctx>) -> Self {
|
||||||
|
let ptr = ctx
|
||||||
|
.builder
|
||||||
|
.build_pointer_cast(
|
||||||
|
ptr,
|
||||||
|
ctx.ctx.i8_type().ptr_type(AddressSpace::default()),
|
||||||
|
"opaque.from_ptr",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
OpaquePointer(ptr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,16 @@ where
|
||||||
let ndarray_ptr = call_ndarray_empty_impl(generator, ctx, elem_ty, shape, shape_ty, name)?;
|
let ndarray_ptr = call_ndarray_empty_impl(generator, ctx, elem_ty, shape, shape_ty, name)?;
|
||||||
|
|
||||||
// NOTE: fill_value's type is not checked!! so be careful with logics
|
// NOTE: fill_value's type is not checked!! so be careful with logics
|
||||||
let fill_value_ptr =
|
|
||||||
OpaquePointer(ctx.builder.build_alloca(fill_value.get_type(), "fill_value_ptr").unwrap());
|
// Allocate fill_value on the stack and give the corresponding stack pointer
|
||||||
fill_value_ptr.store(ctx, fill_value);
|
// to call_nac3_ndarray_fill_generic
|
||||||
|
let fill_value_ptr = ctx.builder.build_alloca(fill_value.get_type(), "fill_value_ptr").unwrap();
|
||||||
|
ctx.builder.build_store(fill_value_ptr, fill_value).unwrap();
|
||||||
|
|
||||||
|
// Opaque-ize fill_value_ptr (turning it into `i8*`) before passing
|
||||||
|
// to call_nac3_ndarray_fill_generic
|
||||||
|
let fill_value_ptr = OpaquePointer::from_ptr(ctx, fill_value_ptr);
|
||||||
|
|
||||||
call_nac3_ndarray_fill_generic(generator, ctx, &ndarray_ptr, &fill_value_ptr);
|
call_nac3_ndarray_fill_generic(generator, ctx, &ndarray_ptr, &fill_value_ptr);
|
||||||
|
|
||||||
Ok(ndarray_ptr)
|
Ok(ndarray_ptr)
|
||||||
|
|
Loading…
Reference in New Issue