[artiq] symbol_resolver: Use TargetData to get size of dtype

dtype.size_of() may not return a constant value.
This commit is contained in:
David Mak 2025-01-06 16:39:24 +08:00
parent 4e21def1a0
commit 3c5e247195

View File

@ -1213,8 +1213,16 @@ impl InnerResolver {
data_global.set_initializer(&data);
// Get the constant itemsize.
let itemsize = dtype.size_of().unwrap();
let itemsize = itemsize.get_zero_extended_constant().unwrap();
//
// NOTE: dtype.size_of() may return a non-constant, where `TargetData::get_store_size`
// will always return a constant size.
let itemsize = ctx
.registry
.llvm_options
.create_target_machine()
.map(|tm| tm.get_target_data().get_store_size(&dtype))
.unwrap();
assert_ne!(itemsize, 0);
// Create the strides needed for ndarray.strides
let strides = make_contiguous_strides(itemsize, ndims, &shape_u64s);