Add more fast jit fixed virtual regs (#1409)

Add fast jit fixed virtual register import_func_ptrs_reg and func_type_indexes_reg
for the preparation of further optimizations.
This commit is contained in:
Wenyong Huang 2022-08-24 14:05:51 +08:00 committed by GitHub
parent f5283399ec
commit 08eeeb748c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 99 additions and 0 deletions

View File

@ -70,6 +70,21 @@ get_module_reg(JitFrame *frame)
return frame->module_reg;
}
JitReg
get_import_func_ptrs_reg(JitFrame *frame)
{
JitCompContext *cc = frame->cc;
JitReg module_inst_reg = get_module_inst_reg(frame);
if (!frame->import_func_ptrs_reg) {
frame->import_func_ptrs_reg = cc->import_func_ptrs_reg;
GEN_INSN(
LDPTR, frame->import_func_ptrs_reg, module_inst_reg,
NEW_CONST(I32, offsetof(WASMModuleInstance, import_func_ptrs)));
}
return frame->import_func_ptrs_reg;
}
JitReg
get_fast_jit_func_ptrs_reg(JitFrame *frame)
{
@ -85,6 +100,21 @@ get_fast_jit_func_ptrs_reg(JitFrame *frame)
return frame->fast_jit_func_ptrs_reg;
}
JitReg
get_func_type_indexes_reg(JitFrame *frame)
{
JitCompContext *cc = frame->cc;
JitReg module_inst_reg = get_module_inst_reg(frame);
if (!frame->func_type_indexes_reg) {
frame->func_type_indexes_reg = cc->func_type_indexes_reg;
GEN_INSN(
LDPTR, frame->func_type_indexes_reg, module_inst_reg,
NEW_CONST(I32, offsetof(WASMModuleInstance, func_type_indexes)));
}
return frame->func_type_indexes_reg;
}
JitReg
get_global_data_reg(JitFrame *frame)
{
@ -376,7 +406,9 @@ clear_fixed_virtual_regs(JitFrame *frame)
frame->module_inst_reg = 0;
frame->module_reg = 0;
frame->import_func_ptrs_reg = 0;
frame->fast_jit_func_ptrs_reg = 0;
frame->func_type_indexes_reg = 0;
frame->global_data_reg = 0;
frame->aux_stack_bound_reg = 0;
frame->aux_stack_bottom_reg = 0;
@ -572,7 +604,9 @@ create_fixed_virtual_regs(JitCompContext *cc)
cc->module_inst_reg = jit_cc_new_reg_ptr(cc);
cc->module_reg = jit_cc_new_reg_ptr(cc);
cc->import_func_ptrs_reg = jit_cc_new_reg_ptr(cc);
cc->fast_jit_func_ptrs_reg = jit_cc_new_reg_ptr(cc);
cc->func_type_indexes_reg = jit_cc_new_reg_ptr(cc);
cc->global_data_reg = jit_cc_new_reg_ptr(cc);
cc->aux_stack_bound_reg = jit_cc_new_reg_I32(cc);
cc->aux_stack_bottom_reg = jit_cc_new_reg_I32(cc);

View File

@ -187,9 +187,15 @@ get_module_inst_reg(JitFrame *frame);
JitReg
get_module_reg(JitFrame *frame);
JitReg
get_import_func_ptrs_reg(JitFrame *frame);
JitReg
get_fast_jit_func_ptrs_reg(JitFrame *frame);
JitReg
get_func_type_indexes_reg(JitFrame *frame);
JitReg
get_global_data_reg(JitFrame *frame);

View File

@ -909,8 +909,12 @@ typedef struct JitFrame {
JitReg module_inst_reg;
/* WASM module */
JitReg module_reg;
/* module_inst->import_func_ptrs */
JitReg import_func_ptrs_reg;
/* module_inst->fast_jit_func_ptrs */
JitReg fast_jit_func_ptrs_reg;
/* module_inst->func_type_indexes */
JitReg func_type_indexes_reg;
/* Base address of global data */
JitReg global_data_reg;
/* Boundary of auxiliary stack */
@ -1027,8 +1031,12 @@ typedef struct JitCompContext {
JitReg module_inst_reg;
/* WASM module */
JitReg module_reg;
/* module_inst->import_func_ptrs */
JitReg import_func_ptrs_reg;
/* module_inst->fast_jit_func_ptrs */
JitReg fast_jit_func_ptrs_reg;
/* module_inst->func_type_indexes */
JitReg func_type_indexes_reg;
/* Base address of global data */
JitReg global_data_reg;
/* Boundary of auxiliary stack */

View File

@ -1262,6 +1262,47 @@ check_linked_symbol(WASMModuleInstance *module_inst, char *error_buf,
return true;
}
#if WASM_ENABLE_FAST_JIT != 0
static uint32
get_smallest_type_idx(WASMModule *module, WASMType *func_type)
{
uint32 i;
for (i = 0; i < module->type_count; i++) {
if (func_type == module->types[i])
return i;
}
bh_assert(0);
return -1;
}
static bool
init_func_type_indexes(WASMModuleInstance *module_inst, char *error_buf,
uint32 error_buf_size)
{
uint32 i;
uint64 total_size = (uint64)sizeof(uint32) * module_inst->function_count;
/* Allocate memory */
if (!(module_inst->func_type_indexes =
runtime_malloc(total_size, error_buf, error_buf_size))) {
return false;
}
for (i = 0; i < module_inst->function_count; i++) {
WASMFunctionInstance *func_inst = module_inst->functions + i;
WASMType *func_type = func_inst->is_import_func
? func_inst->u.func_import->func_type
: func_inst->u.func->func_type;
module_inst->func_type_indexes[i] =
get_smallest_type_idx(module_inst->module, func_type);
}
return true;
}
#endif
/**
* Instantiate module
*/
@ -1384,6 +1425,10 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
&& !(module_inst->export_globals = export_globals_instantiate(
module, module_inst, module_inst->export_glob_count,
error_buf, error_buf_size)))
#endif
#if WASM_ENABLE_FAST_JIT != 0
|| (module_inst->function_count > 0
&& !init_func_type_indexes(module_inst, error_buf, error_buf_size))
#endif
) {
goto fail;
@ -1712,6 +1757,11 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
if (!module_inst)
return;
#if WASM_ENABLE_FAST_JIT != 0
if (module_inst->func_type_indexes)
wasm_runtime_free(module_inst->func_type_indexes);
#endif
#if WASM_ENABLE_MULTI_MODULE != 0
sub_module_deinstantiate(module_inst);
#endif

View File

@ -191,6 +191,7 @@ struct WASMModuleInstance {
#if WASM_ENABLE_FAST_JIT != 0
/* point to JITed functions */
void **fast_jit_func_ptrs;
uint32 *func_type_indexes;
#endif
WASMMemoryInstance **memories;