Support table64 extension in classic-interp and AOT running modes (#3811)

Add table64 extension(in Memory64 proposal) support in classic-interp
and AOT running modes, currently still use uint32 to represent table's
initial and maximum size to keep AOT ABI unchanged.
This commit is contained in:
TianlongLiang
2024-10-11 21:14:56 +08:00
committed by GitHub
parent 2b5e2d9c2c
commit 36d438051e
16 changed files with 922 additions and 175 deletions

View File

@ -2089,6 +2089,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef ext_ret_offset, ext_ret_ptr, ext_ret, res;
LLVMValueRef *param_values = NULL, *value_rets = NULL;
LLVMValueRef *result_phis = NULL, value_ret, import_func_count;
#if WASM_ENABLE_MEMORY64 != 0
LLVMValueRef u32_max, u32_cmp_result;
#endif
LLVMTypeRef *param_types = NULL, ret_type;
LLVMTypeRef llvm_func_type, llvm_func_ptr_type;
LLVMTypeRef ext_ret_ptr_type;
@ -2153,7 +2156,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
func_param_count = func_type->param_count;
func_result_count = func_type->result_count;
POP_I32(elem_idx);
POP_TBL_ELEM_IDX(elem_idx);
/* get the cur size of the table instance */
if (!(offset = I32_CONST(get_tbl_inst_offset(comp_ctx, func_ctx, tbl_idx)
@ -2182,6 +2185,27 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail;
}
#if WASM_ENABLE_MEMORY64 != 0
/* Check if elem index >= UINT32_MAX */
if (IS_TABLE64(tbl_idx)) {
if (!(u32_max = I64_CONST(UINT32_MAX))) {
aot_set_last_error("llvm build const failed");
goto fail;
}
if (!(u32_cmp_result =
LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, elem_idx,
u32_max, "cmp_elem_idx_u32_max"))) {
aot_set_last_error("llvm build icmp failed.");
goto fail;
}
if (!(elem_idx = LLVMBuildTrunc(comp_ctx->builder, elem_idx, I32_TYPE,
"elem_idx_i32"))) {
aot_set_last_error("llvm build trunc failed.");
goto fail;
}
}
#endif
/* Check if (uint32)elem index >= table size */
if (!(cmp_elem_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, elem_idx,
table_size_const, "cmp_elem_idx"))) {
@ -2189,7 +2213,19 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
goto fail;
}
/* Throw exception if elem index >= table size */
#if WASM_ENABLE_MEMORY64 != 0
if (IS_TABLE64(tbl_idx)) {
if (!(cmp_elem_idx =
LLVMBuildOr(comp_ctx->builder, cmp_elem_idx, u32_cmp_result,
"larger_than_u32_max_or_cur_size"))) {
aot_set_last_error("llvm build or failed.");
goto fail;
}
}
#endif
/* Throw exception if elem index >= table size or elem index >= UINT32_MAX
*/
if (!(check_elem_idx_succ = LLVMAppendBasicBlockInContext(
comp_ctx->context, func_ctx->func, "check_elem_idx_succ"))) {
aot_set_last_error("llvm add basic block failed.");