Skip to content

Commit

Permalink
cr suggestions: remove unneeded code and add llvm_jit_array_init_with…
Browse files Browse the repository at this point in the history
…_data
  • Loading branch information
TianlongLiang committed Oct 8, 2023
1 parent 18ba384 commit ee92031
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 47 deletions.
4 changes: 2 additions & 2 deletions core/iwasm/aot/aot_runtime.c
Expand Up @@ -3710,8 +3710,8 @@ aot_array_init_with_data(AOTModuleInstance *module_inst, uint32 seg_index,
uint64 total_size = (int64)elem_size * array_len;

aot_module = (AOTModule *)module_inst->module;
seg_len = aot_module->array_init_data_list[seg_index]->byte_count;
data = aot_module->array_init_data_list[seg_index]->bytes;
seg_len = aot_module->mem_init_data_list[seg_index]->byte_count;
data = aot_module->mem_init_data_list[seg_index]->bytes;

if (data_seg_offset >= seg_len || total_size > seg_len - data_seg_offset) {
aot_set_exception(module_inst, "out of bounds memory access");
Expand Down
4 changes: 0 additions & 4 deletions core/iwasm/aot/aot_runtime.h
Expand Up @@ -262,10 +262,6 @@ typedef struct AOTModule {
HashMap *ref_type_set;
struct WASMRttType **rtt_types;
korp_mutex rtt_type_lock;

/* array init data info */
uint32 array_init_data_count;
AOTArrayInitData **array_init_data_list;
#endif

#if WASM_ENABLE_DEBUG_AOT != 0
Expand Down
14 changes: 0 additions & 14 deletions core/iwasm/compilation/aot.h
Expand Up @@ -116,20 +116,6 @@ typedef struct AOTMemInitData {
uint8 bytes[1];
} AOTMemInitData;

/* TODO: reuse mem init data or this new data structure? */

/**
* A segment of array init data
*/
typedef struct AOTArrayInitData {
/* Start address of init data */
AOTInitExpr offset;
/* Byte count */
uint32 byte_count;
/* Byte array */
uint8 bytes[1];
} AOTArrayInitData;

/**
* Import table
*/
Expand Down
31 changes: 4 additions & 27 deletions core/iwasm/compilation/aot_emit_gc.c
Expand Up @@ -334,19 +334,6 @@ aot_struct_obj_set_field(AOTCompContext *comp_ctx, LLVMValueRef struct_obj,
goto fail;
}

/* Ensure correct alignment for some platforms when field_size == 8 */
#if !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) \
&& !defined(BUILD_TARGET_X86_32)
if (field_size == 8) {
if (!(field_data_ptr =
LLVMBuildBitCast(comp_ctx->builder, field_data_ptr,
INT32_PTR_TYPE, "field_value_ptr_align"))) {
aot_set_last_error("llvm build bitcast failed.");
goto fail;
}
}
#endif

/* Cast to the field data type ptr */
if (!(field_data_ptr = LLVMBuildBitCast(comp_ctx->builder, field_data_ptr,
LLVMPointerType(field_data_type, 0),
Expand Down Expand Up @@ -401,19 +388,6 @@ aot_struct_obj_get_field(AOTCompContext *comp_ctx, LLVMValueRef struct_obj,
break;
}

/* Ensure correct alignment for some platforms when field_size == 8 */
#if !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) \
&& !defined(BUILD_TARGET_X86_32)
if (field_size == 8) {
if (!(field_data_ptr =
LLVMBuildBitCast(comp_ctx->builder, field_data_ptr,
INT32_PTR_TYPE, "field_value_ptr_align"))) {
aot_set_last_error("llvm build bitcast failed.");
goto fail;
}
}
#endif

if (!(field_data_ptr = LLVMBuildBitCast(comp_ctx->builder, field_data_ptr,
LLVMPointerType(field_data_type, 0),
"field_value_ptr"))) {
Expand Down Expand Up @@ -862,7 +836,10 @@ aot_call_aot_array_init_with_data(
param_types[5] = I32_TYPE;
ret_type = INT8_TYPE;

GET_AOT_FUNCTION(aot_array_init_with_data, 6);
if (comp_ctx->is_jit_mode)
GET_AOT_FUNCTION(llvm_array_init_with_data, 6);
else
GET_AOT_FUNCTION(aot_array_init_with_data, 6);

/* Call function aot_array_init_with_data() */
param_values[0] = func_ctx->aot_inst;
Expand Down
25 changes: 25 additions & 0 deletions core/iwasm/interpreter/wasm_runtime.c
Expand Up @@ -3706,6 +3706,31 @@ llvm_jit_rtt_type_new(WASMModuleInstance *module_inst, uint32 type_index)
rtt_type_count, rtt_type_lock);
}

bool
llvm_array_init_with_data(WASMModuleInstance *module_inst, uint32 seg_index,
uint32 data_seg_offset, WASMArrayObjectRef array_obj,
uint32 elem_size, uint32 array_len)
{
WASMModule *wasm_module = module_inst->module;
WASMDataSeg *data_seg;
uint8 *array_elem_base;
uint64 total_size;

data_seg = wasm_module->data_segments[seg_index];
total_size = (int64)elem_size * array_len;

if (data_seg_offset >= data_seg->data_length
|| total_size > data_seg->data_length - data_seg_offset) {
wasm_set_exception(module_inst, "out of bounds memory access");
return false;
}

array_elem_base = (uint8 *)wasm_array_obj_first_elem_addr(array_obj);
bh_memcpy_s(array_elem_base, (uint32)total_size,
data_seg->data + data_seg_offset, (uint32)total_size);

return true;
}
#endif /* end of WASM_ENABLE_GC != 0 */

#endif /* end of WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 */
Expand Down
5 changes: 5 additions & 0 deletions core/iwasm/interpreter/wasm_runtime.h
Expand Up @@ -718,6 +718,11 @@ llvm_jit_obj_is_instance_of(WASMModuleInstance *module_inst,

WASMRttTypeRef
llvm_jit_rtt_type_new(WASMModuleInstance *module_inst, uint32 type_index);

bool
llvm_array_init_with_data(WASMModuleInstance *module_inst, uint32 seg_index,
uint32 data_seg_offset, WASMArrayObjectRef array_obj,
uint32 elem_size, uint32 array_len);
#endif
#endif /* end of WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 */

Expand Down

0 comments on commit ee92031

Please sign in to comment.