From 5e9abda11ce0772afabbbc7f01f3c55a695ead8e Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Sun, 10 Nov 2024 12:34:12 +0000 Subject: [PATCH] Refactor table element retrieval to use temporary variable for improved clarity and consistency; restore aot_compile_get_tbl_inst function --- core/iwasm/common/wasm_runtime_common.c | 10 +++-- core/iwasm/compilation/aot_emit_table.c | 52 ++++++++++++------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index 538d54f28b..1346ee3b09 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -468,11 +468,12 @@ WASMTableInstance_to_wasm_table_inst_t(const WASMModule *module, out->cur_size = table_rt->cur_size; /* table_index < 0, it means it is created by host */ + uintptr_t tmp = (uintptr_t)table_rt->elems; if (table_index > 0 && table_index < (int64)module->import_table_count) { - out->elems = *(void **)(uintptr_t)table_rt->elems; + out->elems = *(void **)tmp; } else { - out->elems = (void *)table_rt->elems; + out->elems = (void *)tmp; } bh_assert(out->elems); @@ -490,11 +491,12 @@ AOTTableInstance_to_wasm_table_inst_t(const AOTModule *module, out->cur_size = table_rt->cur_size; /* table_index < 0, it means it is created by host */ + uintptr_t tmp = (uintptr_t)table_rt->elems; if (table_index > 0 && table_index < (int64)module->import_table_count) { - out->elems = *(void **)(uintptr_t)table_rt->elems; + out->elems = *(void **)tmp; } else { - out->elems = (void *)table_rt->elems; + out->elems = (void *)tmp; } bh_assert(out->elems); diff --git a/core/iwasm/compilation/aot_emit_table.c b/core/iwasm/compilation/aot_emit_table.c index 16f4df64e7..97ed73cf16 100644 --- a/core/iwasm/compilation/aot_emit_table.c +++ b/core/iwasm/compilation/aot_emit_table.c @@ -135,32 +135,6 @@ get_module_inst_extra_offset(AOTCompContext *comp_ctx) return offset_32; } -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 - -LLVMValueRef -aot_compile_get_tbl_inst(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - uint32 tbl_idx) -{ - LLVMValueRef offset, tbl_inst; - - if (!(offset = - I64_CONST(get_tbl_inst_offset(comp_ctx, func_ctx, tbl_idx)))) { - HANDLE_FAILURE("LLVMConstInt"); - goto fail; - } - - if (!(tbl_inst = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, - func_ctx->aot_inst, &offset, 1, - "tbl_inst"))) { - HANDLE_FAILURE("LLVMBuildInBoundsGEP"); - goto fail; - } - - return tbl_inst; -fail: - return NULL; -} - LLVMValueRef aot_compile_get_table_elem_base(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 table_index) @@ -221,6 +195,32 @@ aot_compile_get_table_elem_base(AOTCompContext *comp_ctx, return NULL; } +#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 + +LLVMValueRef +aot_compile_get_tbl_inst(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, + uint32 tbl_idx) +{ + LLVMValueRef offset, tbl_inst; + + if (!(offset = + I64_CONST(get_tbl_inst_offset(comp_ctx, func_ctx, tbl_idx)))) { + HANDLE_FAILURE("LLVMConstInt"); + goto fail; + } + + if (!(tbl_inst = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, + func_ctx->aot_inst, &offset, 1, + "tbl_inst"))) { + HANDLE_FAILURE("LLVMBuildInBoundsGEP"); + goto fail; + } + + return tbl_inst; +fail: + return NULL; +} + bool aot_compile_op_elem_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 tbl_seg_idx)