Refine opcode br_table for classic interpreter (#1112)

Refine opcode br_table for classic interpreter as there may be a lot of
leb128 decoding when the br count is big:
1. Use the bytecode itself to store the decoded leb br depths if each
    decoded depth can be stored with one byte
2. Create br_table cache to store the decode leb br depths if the decoded
    depth cannot be stored with one byte
After the optimization, the class interpreter can access the br depths array
with index, no need to decode the leb128 again.

And fix function record_fast_op() return value unchecked issue in source
debugging feature.
This commit is contained in:
Wenyong Huang
2022-04-23 19:15:55 +08:00
committed by GitHub
parent 5f8d1428d5
commit adaaf348ed
7 changed files with 292 additions and 17 deletions

View File

@ -276,8 +276,13 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
aot_set_last_error("allocate memory failed.");
goto fail;
}
#if WASM_ENABLE_FAST_INTERP != 0
for (i = 0; i <= br_count; i++)
read_leb_uint32(frame_ip, frame_ip_end, br_depths[i]);
#else
for (i = 0; i <= br_count; i++)
br_depths[i] = *frame_ip++;
#endif
if (!aot_compile_op_br_table(comp_ctx, func_ctx, br_depths,
br_count, &frame_ip)) {
@ -288,6 +293,35 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
wasm_runtime_free(br_depths);
break;
#if WASM_ENABLE_FAST_INTERP == 0
case EXT_OP_BR_TABLE_CACHE:
{
BrTableCache *node = bh_list_first_elem(
comp_ctx->comp_data->wasm_module->br_table_cache_list);
BrTableCache *node_next;
uint8 *p_opcode = frame_ip - 1;
read_leb_uint32(frame_ip, frame_ip_end, br_count);
while (node) {
node_next = bh_list_elem_next(node);
if (node->br_table_op_addr == p_opcode) {
br_depths = node->br_depths;
if (!aot_compile_op_br_table(comp_ctx, func_ctx,
br_depths, br_count,
&frame_ip)) {
return false;
}
break;
}
node = node_next;
}
bh_assert(node);
break;
}
#endif
case WASM_OP_RETURN:
if (!aot_compile_op_return(comp_ctx, func_ctx, &frame_ip))
return false;