Refactor Orc JIT to enable lazy compilation (#974)
Refactor LLVM Orc JIT to actually enable the lazy compilation and speedup the launching process: https://llvm.org/docs/ORCv2.html#laziness Main modifications: - Create LLVM module for each wasm function, wrap it with thread safe module so that the modules can be compiled parallelly - Lookup function from aot module instance's func_ptrs but not directly call the function to decouple the module relationship - Compile the function when it is first called and hasn't been compiled - Create threads to pre-compile the WASM functions parallelly when loading - Set Lazy JIT as default, update document and build/test scripts
This commit is contained in:
@ -1419,6 +1419,17 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
|
||||
}
|
||||
argc = func_type->param_cell_num;
|
||||
|
||||
#if WASM_ENABLE_LAZY_JIT != 0
|
||||
if (!function->u.func.func_ptr) {
|
||||
AOTModule *aot_module = (AOTModule *)module_inst->aot_module.ptr;
|
||||
if (!(function->u.func.func_ptr =
|
||||
aot_lookup_orcjit_func(aot_module->comp_ctx->orc_lazyjit,
|
||||
module_inst, function->func_index))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set thread handle and stack boundary */
|
||||
wasm_exec_env_set_thread_info(exec_env);
|
||||
|
||||
@ -2300,6 +2311,15 @@ aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
|
||||
func_type_idx = func_type_indexes[func_idx];
|
||||
func_type = aot_module->func_types[func_type_idx];
|
||||
|
||||
#if WASM_ENABLE_LAZY_JIT != 0
|
||||
if (func_idx >= aot_module->import_func_count && !func_ptrs[func_idx]) {
|
||||
if (!(func_ptr = aot_lookup_orcjit_func(
|
||||
aot_module->comp_ctx->orc_lazyjit, module_inst, func_idx))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(func_ptr = func_ptrs[func_idx])) {
|
||||
bh_assert(func_idx < aot_module->import_func_count);
|
||||
import_func = aot_module->import_funcs + func_idx;
|
||||
|
||||
Reference in New Issue
Block a user