Refine aot call_indirect opcode translation (#492)

Re-implement aot call_indirect opcode translation: when calling non-import function, translate it by LLVM call IR to call the function in AOTed code, so as to avoid calling runtime aot_call_indirect API which is much slower. For import function, keep calling aot_call_indirect API due to the possible pointer/string argument conversion.

And add prompt info while app heap is corrupted, change emit_leb to emit_uint32 inter fast-interp to refine footprint.

Signed-off-by: Wenyong Huang <wenyong.huang@intel.com>
This commit is contained in:
Wenyong Huang
2021-01-05 04:05:30 -06:00
committed by GitHub
parent f2a63d8623
commit 788cbf2a19
15 changed files with 529 additions and 191 deletions

View File

@ -791,6 +791,12 @@ load_function_import(const WASMModule *parent_module, WASMModule *sub_module,
return false;
}
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0)
declare_type_index = wasm_get_smallest_type_idx(
parent_module->types, parent_module->type_count,
declare_type_index);
#endif
declare_func_type = parent_module->types[declare_type_index];
if (wasm_runtime_is_host_module(sub_module_name)) {
@ -1724,6 +1730,11 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
return false;
}
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0)
type_index = wasm_get_smallest_type_idx(
module->types, module->type_count, type_index);
#endif
read_leb_uint32(p_code, buf_code_end, code_size);
if (code_size == 0
|| p_code + code_size > buf_code_end) {
@ -4312,10 +4323,6 @@ fail:
LOG_OP("%d\t", value); \
} while (0)
#define emit_leb() do { \
wasm_loader_emit_leb(loader_ctx, p_org, p); \
} while (0)
static bool
wasm_loader_ctx_reinit(WASMLoaderContext *ctx)
{
@ -4402,21 +4409,6 @@ wasm_loader_emit_backspace(WASMLoaderContext *ctx, uint32 size)
ctx->code_compiled_size -= size;
}
static void
wasm_loader_emit_leb(WASMLoaderContext *ctx, uint8* start, uint8* end)
{
if (ctx->p_code_compiled) {
bh_memcpy_s(ctx->p_code_compiled,
ctx->p_code_compiled_end - ctx->p_code_compiled,
start, end - start);
ctx->p_code_compiled += (end - start);
}
else {
ctx->code_compiled_size += (end - start);
}
}
static bool
preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
uint32 local_index, uint32 local_type, bool *preserved,
@ -6497,8 +6489,7 @@ handle_op_block_and_loop:
}
}
else { /* local index larger than 255, reserve leb */
p_org ++;
emit_leb();
emit_uint32(loader_ctx, local_idx);
POP_OFFSET_TYPE(local_type);
}
#else
@ -6554,11 +6545,10 @@ handle_op_block_and_loop:
}
}
else { /* local index larger than 255, reserve leb */
p_org ++;
emit_leb();
emit_uint32(loader_ctx, local_idx);
}
emit_operand(loader_ctx, *(loader_ctx->frame_offset -
wasm_value_type_cell_num(local_type)));
wasm_value_type_cell_num(local_type)));
#else
#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0)
if (local_offset < 0x80) {