Implement call Fast JIT function from LLVM JIT jitted code (#1714)
Basically implement the Multi-tier JIT engine. And update document and wamr-test-suites script.
This commit is contained in:
@ -19,6 +19,9 @@
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
#include "../libraries/debug-engine/debug_engine.h"
|
||||
#endif
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
#include "../fast-jit/jit_compiler.h"
|
||||
#endif
|
||||
#if WASM_ENABLE_JIT != 0
|
||||
#include "../aot/aot_runtime.h"
|
||||
#endif
|
||||
@ -1414,30 +1417,10 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
|
||||
extra_info_offset = (uint32)total_size;
|
||||
total_size += sizeof(WASMModuleInstanceExtra);
|
||||
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
if (!is_sub_inst) {
|
||||
os_mutex_lock(&module->ref_count_lock);
|
||||
if (module->ref_count != 0) {
|
||||
LOG_WARNING(
|
||||
"warning: multiple instances referencing the same module may "
|
||||
"cause unexpected behaviour during debugging");
|
||||
}
|
||||
module->ref_count++;
|
||||
os_mutex_unlock(&module->ref_count_lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate the memory for module instance with memory instances,
|
||||
global data, table data appended at the end */
|
||||
if (!(module_inst =
|
||||
runtime_malloc(total_size, error_buf, error_buf_size))) {
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
if (!is_sub_inst) {
|
||||
os_mutex_lock(&module->ref_count_lock);
|
||||
module->ref_count--;
|
||||
os_mutex_unlock(&module->ref_count_lock);
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1827,6 +1810,33 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0 \
|
||||
|| (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
|
||||
&& WASM_ENABLE_LAZY_JIT != 0)
|
||||
if (!is_sub_inst) {
|
||||
/* Add module instance into module's instance list */
|
||||
os_mutex_lock(&module->instance_list_lock);
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
if (module->instance_list) {
|
||||
LOG_WARNING(
|
||||
"warning: multiple instances referencing to the same module "
|
||||
"may cause unexpected behaviour during debugging");
|
||||
}
|
||||
#endif
|
||||
#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
|
||||
&& WASM_ENABLE_LAZY_JIT != 0
|
||||
/* Copy llvm func ptrs again in case that they were updated
|
||||
after the module instance was created */
|
||||
bh_memcpy_s(module_inst->func_ptrs + module->import_function_count,
|
||||
sizeof(void *) * module->function_count, module->func_ptrs,
|
||||
sizeof(void *) * module->function_count);
|
||||
#endif
|
||||
module_inst->e->next = module->instance_list;
|
||||
module->instance_list = module_inst;
|
||||
os_mutex_unlock(&module->instance_list_lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (module->start_function != (uint32)-1) {
|
||||
/* TODO: fix start function can be import function issue */
|
||||
if (module->start_function >= module->import_function_count)
|
||||
@ -1864,8 +1874,8 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
|
||||
wasm_runtime_dump_module_inst_mem_consumption(
|
||||
(WASMModuleInstanceCommon *)module_inst);
|
||||
#endif
|
||||
(void)global_data_end;
|
||||
|
||||
(void)global_data_end;
|
||||
return module_inst;
|
||||
|
||||
fail:
|
||||
@ -1935,11 +1945,28 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0
|
||||
#if WASM_ENABLE_DEBUG_INTERP != 0 \
|
||||
|| (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
|
||||
&& WASM_ENABLE_LAZY_JIT != 0)
|
||||
if (!is_sub_inst) {
|
||||
os_mutex_lock(&module_inst->module->ref_count_lock);
|
||||
module_inst->module->ref_count--;
|
||||
os_mutex_unlock(&module_inst->module->ref_count_lock);
|
||||
WASMModule *module = module_inst->module;
|
||||
WASMModuleInstance *instance_prev = NULL, *instance;
|
||||
os_mutex_lock(&module->instance_list_lock);
|
||||
|
||||
instance = module->instance_list;
|
||||
while (instance) {
|
||||
if (instance == module_inst) {
|
||||
if (!instance_prev)
|
||||
module->instance_list = instance->e->next;
|
||||
else
|
||||
instance_prev->e->next = instance->e->next;
|
||||
break;
|
||||
}
|
||||
instance_prev = instance;
|
||||
instance = instance->e->next;
|
||||
}
|
||||
|
||||
os_mutex_unlock(&module->instance_list_lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2803,7 +2830,7 @@ fast_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
|
||||
return call_indirect(exec_env, tbl_idx, elem_idx, argc, argv, true,
|
||||
type_idx);
|
||||
}
|
||||
#endif
|
||||
#endif /* end of WASM_ENABLE_FAST_JIT != 0 */
|
||||
|
||||
#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user