diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index ae866b6209..303675bc97 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -185,7 +185,7 @@ jobs: $CLASSIC_INTERP_BUILD_OPTIONS, $FAST_INTERP_BUILD_OPTIONS, $LLVM_EAGER_JIT_BUILD_OPTIONS, - #$LLVM_LAZY_JIT_BUILD_OPTIONS, + $LLVM_LAZY_JIT_BUILD_OPTIONS, ] make_options_feature: [ # Features diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index 28a3fc95d9..750190fe98 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -2898,14 +2898,22 @@ aot_load_from_comp_data(AOTCompData *comp_data, AOTCompContext *comp_ctx, } /* fill in func_ptrs[] */ + LOG_VERBOSE("to fill in func_ptrs ..."); +#if WASM_ENABLE_LAZY_JIT == 0 bh_print_time("Begin to do eager compilation..."); +#endif for (i = 0; i < module->func_count; i++) { LLVMErrorRef error; LLVMOrcJITTargetAddress func_addr; char func_name[32] = { 0 }; snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, i); +#if WASM_ENABLE_LAZY_JIT != 0 + error = + LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, &func_addr, func_name); +#else error = LLVMOrcLLJITLookup(comp_ctx->orc_jit, &func_addr, func_name); +#endif if (error != LLVMErrorSuccess) { char *err_msg = LLVMGetErrorMessage(error); set_error_buf_v(error_buf, error_buf_size, @@ -2944,8 +2952,13 @@ aot_load_from_comp_data(AOTCompData *comp_data, AOTCompContext *comp_ctx, snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, comp_data->start_func_index - module->import_func_count); +#if WASM_ENABLE_LAZY_JIT != 0 + if ((error = LLVMOrcLLLazyJITLookup(comp_ctx->orc_jit, + &func_addr, func_name))) { +#else if ((error = LLVMOrcLLJITLookup(comp_ctx->orc_jit, &func_addr, func_name))) { +#endif char *err_msg = LLVMGetErrorMessage(error); set_error_buf_v(error_buf, error_buf_size, "failed to compile orc jit function: %s", diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index e054f66198..0ed64f73d6 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -2674,28 +2674,38 @@ aot_compile_wasm(AOTCompContext *comp_ctx) return false; } + /* Run IR optimization before feeding in ORCJIT and AOT codegen */ if (comp_ctx->optimize) { - if (!comp_ctx->is_jit_mode) { - /* Run passes for AOT indirect mode */ - if (comp_ctx->is_indirect_mode) { - bh_print_time("Begin to run optimization passes " - "for indirect mode"); - if (!apply_passes_for_indirect_mode(comp_ctx)) { - return false; - } + /* Run specific passes for AOT indirect mode */ + if (!comp_ctx->is_jit_mode && comp_ctx->is_indirect_mode) { + bh_print_time("Begin to run optimization passes " + "for indirect mode"); + if (!apply_passes_for_indirect_mode(comp_ctx)) { + return false; } - - /* Run passes for both indirect mode and normal mode */ - bh_print_time("Begin to run llvm optimization passes"); - aot_apply_llvm_new_pass_manager(comp_ctx, comp_ctx->module); } + + /* Run passes for all JIT/AOT mode */ + bh_print_time("Begin to run llvm optimization passes"); + aot_apply_llvm_new_pass_manager(comp_ctx, comp_ctx->module); + bh_print_time("Finish llvm optimization passes"); } +#ifdef DUMP_MODULE + LLVMDumpModule(comp_ctx->module); + os_printf("\n"); +#endif + if (comp_ctx->is_jit_mode) { LLVMErrorRef err; LLVMOrcJITDylibRef orc_main_dylib; LLVMOrcThreadSafeModuleRef orc_thread_safe_module; + +#if WASM_ENABLE_LAZY_JIT != 0 + orc_main_dylib = LLVMOrcLLLazyJITGetMainJITDylib(comp_ctx->orc_jit); +#else orc_main_dylib = LLVMOrcLLJITGetMainJITDylib(comp_ctx->orc_jit); +#endif if (!orc_main_dylib) { aot_set_last_error( "failed to get orc orc_jit main dynmaic library"); @@ -2709,8 +2719,13 @@ aot_compile_wasm(AOTCompContext *comp_ctx) return false; } +#if WASM_ENABLE_LAZY_JIT != 0 + if ((err = LLVMOrcLLLazyJITAddLLVMIRModule( + comp_ctx->orc_jit, orc_main_dylib, orc_thread_safe_module))) { +#else if ((err = LLVMOrcLLJITAddLLVMIRModule( comp_ctx->orc_jit, orc_main_dylib, orc_thread_safe_module))) { +#endif /* If adding the ThreadSafeModule fails then we need to clean it up by ourselves, otherwise the orc orc_jit will manage the memory. */ @@ -2720,10 +2735,6 @@ aot_compile_wasm(AOTCompContext *comp_ctx) } } -#if 0 - LLVMDumpModule(comp_ctx->module); - os_printf("\n"); -#endif return true; } diff --git a/core/iwasm/compilation/aot_emit_function.c b/core/iwasm/compilation/aot_emit_function.c index 66d189fb87..f620adbf6f 100644 --- a/core/iwasm/compilation/aot_emit_function.c +++ b/core/iwasm/compilation/aot_emit_function.c @@ -267,130 +267,6 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, return true; } -/*TODO: maybe no need to do that*/ -static bool -lookup_orcjit_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, - LLVMValueRef func_idx, LLVMValueRef *p_func) -{ - LLVMBasicBlockRef block_curr, block_resolve_func, block_func_resolved; - LLVMValueRef param_values[3], func, value, func_ptr, cmp, phi; - LLVMTypeRef param_types[3], ret_type, func_type, func_ptr_type; - - block_curr = LLVMGetInsertBlock(comp_ctx->builder); - - if (!(block_resolve_func = LLVMAppendBasicBlockInContext( - comp_ctx->context, func_ctx->func, "resolve_func"))) { - aot_set_last_error("llvm add basic block failed."); - return false; - } - if (!(block_func_resolved = LLVMAppendBasicBlockInContext( - comp_ctx->context, func_ctx->func, "func_resolved"))) { - aot_set_last_error("llvm add basic block failed."); - return false; - } - LLVMMoveBasicBlockAfter(block_resolve_func, block_curr); - LLVMMoveBasicBlockAfter(block_func_resolved, block_resolve_func); - - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_func_resolved); - if (!(phi = LLVMBuildPhi(comp_ctx->builder, INT8_PTR_TYPE, "phi"))) { - aot_set_last_error("llvm build phi failed."); - return false; - } - - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr); - - /* Load function pointer */ - if (!(func_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE, - func_ctx->func_ptrs, &func_idx, 1, - "func_ptr_tmp"))) { - aot_set_last_error("llvm build inbounds gep failed."); - return false; - } - - if (!(func = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, func_ptr, - "func_ptr"))) { - aot_set_last_error("llvm build load failed."); - return false; - } - - /* If func ptr is NULL, call aot_lookup_orcjit_func to resolve it */ - if (!(cmp = LLVMBuildIsNull(comp_ctx->builder, func, "cmp"))) { - aot_set_last_error("llvm build is null failed"); - return false; - } - - /* Create condition br */ - if (!LLVMBuildCondBr(comp_ctx->builder, cmp, block_resolve_func, - block_func_resolved)) { - aot_set_last_error("llvm build cond br failed."); - return false; - } - LLVMAddIncoming(phi, &func, &block_curr, 1); - - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_resolve_func); - - param_types[0] = INT8_PTR_TYPE; - param_types[1] = comp_ctx->aot_inst_type; - param_types[2] = I32_TYPE; - ret_type = INT8_PTR_TYPE; - - if (!(func_type = LLVMFunctionType(ret_type, param_types, 3, false)) - || !(func_ptr_type = LLVMPointerType(func_type, 0))) { - aot_set_last_error("llvm add function type failed."); - return false; - } - - if (!(value = I64_CONST((uint64)(uintptr_t)aot_lookup_orcjit_func)) - || !(func = LLVMConstIntToPtr(value, func_ptr_type))) { - aot_set_last_error("create LLVM value failed."); - return false; - } - - param_values[0] = I64_CONST((uintptr_t)comp_ctx->orc_jit); - if (!param_values[0]) { - aot_set_last_error("llvm build const failed."); - return false; - } - if (!(param_values[0] = - LLVMConstIntToPtr(param_values[0], INT8_PTR_TYPE))) { - aot_set_last_error("llvm build bit cast failed."); - return false; - } - - param_values[1] = func_ctx->aot_inst; - - param_values[2] = func_idx; - if (!param_values[2]) { - aot_set_last_error("llvm build const failed."); - return false; - } - - /* Call the function */ - if (!(func = LLVMBuildCall2(comp_ctx->builder, func_type, func, - param_values, 3, "call_orcjit_lookup"))) { - aot_set_last_error("LLVM build call failed."); - return false; - } - - /* Check whether exception was thrown when looking up func */ - if (!check_exception_thrown(comp_ctx, func_ctx)) { - return false; - } - - block_curr = LLVMGetInsertBlock(comp_ctx->builder); - LLVMAddIncoming(phi, &func, &block_curr, 1); - - if (!LLVMBuildBr(comp_ctx->builder, block_func_resolved)) { - aot_set_last_error("llvm build br failed."); - return false; - } - - LLVMPositionBuilderAtEnd(comp_ctx->builder, block_func_resolved); - - *p_func = phi; - return true; -} - #if (WASM_ENABLE_DUMP_CALL_STACK != 0) || (WASM_ENABLE_PERF_PROFILING != 0) static bool call_aot_alloc_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, @@ -909,35 +785,6 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, else { func = func_ctxes[func_idx - import_func_count]->func; } - // else { - // LLVMTypeRef func_ptr_type; - // LLVMValueRef func_idx_const = I32_CONST(func_idx); - - // if (!func_idx_const) { - // aot_set_last_error("llvm build const failed."); - // goto fail; - // } - - // /* For LAZY JIT, each function belongs to its own module, - // we call aot_lookup_orcjit_func to get the func pointer */ - // if (!lookup_orcjit_func(comp_ctx, func_ctx, func_idx_const, - // &func)) { - // goto fail; - // } - - // if (!(func_ptr_type = LLVMPointerType( - // func_ctxes[func_idx - - // import_func_count]->func_type, 0))) { - // aot_set_last_error("construct func ptr type failed."); - // goto fail; - // } - - // if (!(func = LLVMBuildBitCast(comp_ctx->builder, func, - // func_ptr_type, "aot_func"))) { - // aot_set_last_error("llvm bit cast failed."); - // goto fail; - // } - // } } aot_func = func_ctxes[func_idx - import_func_count]->aot_func; @@ -1580,11 +1427,6 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, goto fail; } - // /* For LAZY JIT, each function belongs to its own module, - // we call aot_lookup_orcjit_func to get the func pointer */ - // if (!lookup_orcjit_func(comp_ctx, func_ctx, func_idx, &func_ptr)) - // goto fail; - if (!(llvm_func_type = LLVMFunctionType(ret_type, param_types, total_param_count, false)) || !(llvm_func_ptr_type = LLVMPointerType(llvm_func_type, 0))) { diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index beb3d8c961..ebfaa63869 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1239,16 +1239,14 @@ aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err) LLVMDisposeErrorMessage(err_msg); } +#ifndef NDEBUG static LLVMErrorRef run_pass(void *ctx, LLVMModuleRef module) { size_t len = 0; - LOG_VERBOSE("--- Do IR optimization @ T#%ld---", + LOG_VERBOSE("--- In IRTransformLayer @ T#%ld---", LLVMGetModuleIdentifier(module, &len), pthread_self()); - bh_print_time("Begin to run func optimization passes"); - aot_apply_llvm_new_pass_manager((AOTCompContext *)ctx, module); - bh_print_time("Finish func optimization passes"); - + bh_print_time("Begin to generate machine code"); (void)ctx; (void)module; return LLVMErrorSuccess; @@ -1265,49 +1263,39 @@ do_ir_transform(void *ctx, LLVMOrcThreadSafeModuleRef *module, static LLVMErrorRef do_obj_transform(void *Ctx, LLVMMemoryBufferRef *ObjInOut) { - bh_print_time("Begin to run object optimization passes"); - LOG_VERBOSE("--- Do Object optimization @ T#%ld ---", pthread_self()); - bh_print_time("Finish object optimization passes"); + bh_print_time("Finish generating machine code"); + LOG_VERBOSE("--- In ObjectTransformLayer @ T#%ld ---", pthread_self()); (void)Ctx; (void)ObjInOut; return LLVMErrorSuccess; } +#endif static bool -orc_jit_create(AOTCompContext *comp_ctx, uint32 func_count) +create_target_machine_detect_host(AOTCompContext *comp_ctx) { - uint32 i; + char *triple = NULL; + LLVMTargetRef target = NULL; char *err_msg = NULL; char *cpu = NULL; char *features = NULL; - char *llvm_triple = NULL; - char func_name[32] = { 0 }; - LLVMErrorRef err; - LLVMTargetRef llvm_targetref = NULL; - LLVMTargetMachineRef target_machine_for_orcjit = NULL; - LLVMOrcLLJITRef orc_jit = NULL; - LLVMOrcJITTargetMachineBuilderRef target_machine_builder = NULL; - LLVMOrcLLJITBuilderRef jit_builder = NULL; - LLVMOrcMaterializationUnitRef orc_material_unit = NULL; - LLVMOrcExecutionSessionRef orc_execution_session = NULL; - LLVMOrcLazyCallThroughManagerRef orc_call_through_mgr = NULL; - LLVMOrcIndirectStubsManagerRef orc_indirect_stub_mgr = NULL; - LLVMOrcCSymbolAliasMapPair *orc_symbol_map_pairs = NULL; - - llvm_triple = LLVMGetDefaultTargetTriple(); - if (llvm_triple == NULL) { + LLVMTargetMachineRef target_machine = NULL; + bool ret = false; + + triple = LLVMGetDefaultTargetTriple(); + if (triple == NULL) { aot_set_last_error("failed to get default target triple."); goto fail; } - if (LLVMGetTargetFromTriple(llvm_triple, &llvm_targetref, &err_msg) != 0) { + if (LLVMGetTargetFromTriple(triple, &target, &err_msg) != 0) { aot_set_last_error_v("failed to get llvm target from triple %s.", err_msg); LLVMDisposeMessage(err_msg); goto fail; } - if (!LLVMTargetHasJIT(llvm_targetref)) { + if (!LLVMTargetHasJIT(target)) { aot_set_last_error("unspported JIT on this platform."); goto fail; } @@ -1327,155 +1315,128 @@ orc_jit_create(AOTCompContext *comp_ctx, uint32 func_count) LOG_VERBOSE("LLVM ORCJIT detected CPU \"%s\", with features \"%s\"\n", cpu, features); - comp_ctx->target_machine = LLVMCreateTargetMachine( - llvm_targetref, llvm_triple, cpu, features, LLVMCodeGenLevelDefault, + /* create TargetMachine */ + target_machine = LLVMCreateTargetMachine( + target, triple, cpu, features, LLVMCodeGenLevelDefault, LLVMRelocDefault, LLVMCodeModelJITDefault); - if (!comp_ctx->target_machine) { + if (!target_machine) { aot_set_last_error("failed to create target machine."); goto fail; } + comp_ctx->target_machine = target_machine; - target_machine_for_orcjit = LLVMCreateTargetMachine( - llvm_targetref, llvm_triple, cpu, features, LLVMCodeGenLevelDefault, - LLVMRelocDefault, LLVMCodeModelJITDefault); - if (!target_machine_for_orcjit) { - aot_set_last_error("failed to create target machine."); - goto fail; - } + /* Save target arch */ + get_target_arch_from_triple(triple, comp_ctx->target_arch, + sizeof(comp_ctx->target_arch)); + ret = true; - target_machine_builder = - LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine( - target_machine_for_orcjit); - if (!target_machine_builder) { - aot_set_last_error("failed to create target machine builder."); +fail: + if (triple) + LLVMDisposeMessage(triple); + if (features) + LLVMDisposeMessage(features); + if (cpu) + LLVMDisposeMessage(cpu); + + return ret; +} + +static bool +orc_jit_create(AOTCompContext *comp_ctx) +{ + LLVMErrorRef err; +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITRef orc_jit = NULL; + LLVMOrcLLLazyJITBuilderRef builder = NULL; +#else + LLVMOrcLLJITRef orc_jit = NULL; + LLVMOrcLLJITBuilderRef builder = NULL; +#endif + LLVMOrcJITTargetMachineBuilderRef jtmb = NULL; + bool ret = false; + +#if WASM_ENABLE_LAZY_JIT != 0 + builder = LLVMOrcCreateLLLazyJITBuilder(); +#else + builder = LLVMOrcCreateLLJITBuilder(); +#endif + if (builder == NULL) { + aot_set_last_error("failed to create jit builder."); goto fail; } - /* The target_machine_for_orcjit has been disposed before - LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine() returns */ - target_machine_for_orcjit = NULL; - jit_builder = LLVMOrcCreateLLJITBuilder(); - if (!jit_builder) { - aot_set_last_error("failed to create orc_jit builder."); + err = LLVMOrcJITTargetMachineBuilderDetectHost(&jtmb); + if (err != LLVMErrorSuccess) { + aot_handle_llvm_errmsg( + "quited to create LLVMOrcJITTargetMachineBuilderRef", err); goto fail; } - LLVMOrcLLJITBuilderSetNumCompileThreads(jit_builder, + + /* ownership transfer + * LLVMOrcJITTargetMachineBuilderRef -> LLVMOrcLLJITBuilderRef + */ +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITBuilderSetNumCompileThreads( + builder, WASM_ORC_JIT_COMPILE_THREAD_NUM); + LLVMOrcLLLazyJITBuilderSetJITTargetMachineBuilder(builder, jtmb); + err = LLVMOrcCreateLLLazyJIT(&orc_jit, builder); +#else + LLVMOrcLLJITBuilderSetNumCompileThreads(builder, WASM_ORC_JIT_COMPILE_THREAD_NUM); - LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(jit_builder, - target_machine_builder); - /* Should not dispose of the JITTargetMachineBuilder after calling - LLVMOrcLLJITBuilderSetJITTargetMachineBuilder() */ - target_machine_builder = NULL; - - err = LLVMOrcCreateLLJIT(&orc_jit, jit_builder); - if (err) { - aot_handle_llvm_errmsg("failed to create llvm orcjit instance", err); + LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(builder, jtmb); + err = LLVMOrcCreateLLJIT(&orc_jit, builder); +#endif + if (err != LLVMErrorSuccess) { + aot_handle_llvm_errmsg("quited to create llvm lazy orcjit instance", + err); goto fail; } - /* The jit_builder is managed by orc_jit after calling - LLVMOrcCreateLLJIT(), here we should not dispose it again */ - jit_builder = NULL; + /* ownership transfer + * LLVMOrcLLJITBuilderRef -> LLVMOrcLLJITRef + */ + builder = NULL; +#ifndef NDEBUG + /* Setup TransferLayer */ LLVMOrcIRTransformLayerSetTransform( - LLVMOrcLLJITGetIRTransformLayer(orc_jit), *do_ir_transform, comp_ctx); - LLVMOrcObjectTransformLayerSetTransform( - LLVMOrcLLJITGetObjTransformLayer(orc_jit), *do_obj_transform, comp_ctx); - - if (func_count > 0) { - orc_execution_session = LLVMOrcLLJITGetExecutionSession(orc_jit); - if (!orc_execution_session) { - aot_set_last_error("failed to get orc execution session"); - goto fail; - } - - err = LLVMOrcCreateLocalLazyCallThroughManager( - llvm_triple, orc_execution_session, 0, &orc_call_through_mgr); - if (err) { - aot_handle_llvm_errmsg("failed to create orc call through manager", - err); - goto fail; - } - - orc_indirect_stub_mgr = - LLVMOrcCreateLocalIndirectStubsManager(llvm_triple); - if (!orc_indirect_stub_mgr) { - aot_set_last_error("failed to create orc indirect stub manager"); - goto fail; - } - - if (!(orc_symbol_map_pairs = wasm_runtime_malloc( - sizeof(LLVMOrcCSymbolAliasMapPair) * func_count))) { - aot_set_last_error("failed to allocate memory"); - goto fail; - } - memset(orc_symbol_map_pairs, 0, - sizeof(LLVMOrcCSymbolAliasMapPair) * func_count); - - for (i = 0; i < func_count; i++) { - snprintf(func_name, sizeof(func_name), "orcjit_%s%d", - AOT_FUNC_PREFIX, i); - orc_symbol_map_pairs[i].Name = - LLVMOrcExecutionSessionIntern(orc_execution_session, func_name); - snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, i); - orc_symbol_map_pairs[i].Entry.Name = - LLVMOrcExecutionSessionIntern(orc_execution_session, func_name); - orc_symbol_map_pairs[i].Entry.Flags.GenericFlags = - LLVMJITSymbolGenericFlagsExported - | LLVMJITSymbolGenericFlagsCallable; - orc_symbol_map_pairs[i].Entry.Flags.TargetFlags = - LLVMJITSymbolGenericFlagsExported - | LLVMJITSymbolGenericFlagsCallable; - - if (!orc_symbol_map_pairs[i].Name - || !orc_symbol_map_pairs[i].Entry.Name) { - aot_set_last_error("failed to allocate memory"); - goto fail; - } - } +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITGetIRTransformLayer(orc_jit), +#else + LLVMOrcLLJITGetIRTransformLayer(orc_jit), +#endif + *do_ir_transform, comp_ctx); - orc_material_unit = - LLVMOrcLazyReexports(orc_call_through_mgr, orc_indirect_stub_mgr, - LLVMOrcLLJITGetMainJITDylib(orc_jit), - orc_symbol_map_pairs, func_count); - if (!orc_material_unit) { - aot_set_last_error("failed to orc re-exports"); - goto fail; - } - } + LLVMOrcObjectTransformLayerSetTransform( +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITGetObjTransformLayer(orc_jit), +#else + LLVMOrcLLJITGetObjTransformLayer(orc_jit), +#endif + *do_obj_transform, comp_ctx); +#endif + /* ownership transfer + * local -> AOTCompContext + */ comp_ctx->orc_jit = orc_jit; - comp_ctx->orc_material_unit = orc_material_unit; - comp_ctx->orc_symbol_map_pairs = orc_symbol_map_pairs; - comp_ctx->orc_call_through_mgr = orc_call_through_mgr; - comp_ctx->orc_indirect_stub_mgr = orc_indirect_stub_mgr; - - LLVMDisposeMessage(llvm_triple); - LLVMDisposeMessage(cpu); - LLVMDisposeMessage(features); - return true; + orc_jit = NULL; + ret = true; fail: - if (orc_symbol_map_pairs) - wasm_runtime_free(orc_symbol_map_pairs); - if (orc_call_through_mgr) - LLVMOrcDisposeLazyCallThroughManager(orc_call_through_mgr); - if (orc_indirect_stub_mgr) - LLVMOrcDisposeIndirectStubsManager(orc_indirect_stub_mgr); + if (builder) +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcDisposeLLLazyJITBuilder(builder); +#else + LLVMOrcDisposeLLJITBuilder(builder); +#endif + if (orc_jit) +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcDisposeLLLazyJIT(orc_jit); +#else LLVMOrcDisposeLLJIT(orc_jit); - if (target_machine_builder) - LLVMOrcDisposeJITTargetMachineBuilder(target_machine_builder); - if (jit_builder) - LLVMOrcDisposeLLJITBuilder(jit_builder); - if (target_machine_for_orcjit) - LLVMDisposeTargetMachine(target_machine_for_orcjit); - if (features) - LLVMDisposeMessage(features); - if (cpu) - LLVMDisposeMessage(cpu); - if (llvm_triple) - LLVMDisposeMessage(llvm_triple); - return false; +#endif + return ret; } AOTCompContext * @@ -1603,30 +1564,21 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) comp_ctx->custom_sections_count = option->custom_sections_count; if (option->is_jit_mode) { - char *triple_jit = NULL; - comp_ctx->is_jit_mode = true; + /* Create TargetMachine */ + if (!create_target_machine_detect_host(comp_ctx)) + goto fail; + /* Create LLJIT Instance */ - if (!orc_jit_create(comp_ctx, comp_data->func_count)) { + if (!orc_jit_create(comp_ctx)) goto fail; - } #ifndef OS_ENABLE_HW_BOUND_CHECK comp_ctx->enable_bound_check = true; #else comp_ctx->enable_bound_check = false; #endif - - if (!(triple_jit = - (char *)LLVMOrcLLJITGetTripleString(comp_ctx->orc_jit))) { - aot_set_last_error("can not get triple from the target machine"); - goto fail; - } - - /* Save target arch */ - get_target_arch_from_triple(triple_jit, comp_ctx->target_arch, - sizeof(comp_ctx->target_arch)); } else { /* Create LLVM target machine */ @@ -2103,33 +2055,26 @@ aot_destroy_comp_context(AOTCompContext *comp_ctx) if (!comp_ctx) return; - if (comp_ctx->orc_symbol_map_pairs) - wasm_runtime_free(comp_ctx->orc_symbol_map_pairs); - - if (comp_ctx->orc_call_through_mgr) - LLVMOrcDisposeLazyCallThroughManager(comp_ctx->orc_call_through_mgr); - - if (comp_ctx->orc_indirect_stub_mgr) - LLVMOrcDisposeIndirectStubsManager(comp_ctx->orc_indirect_stub_mgr); - - if (comp_ctx->orc_material_unit) - LLVMOrcDisposeMaterializationUnit(comp_ctx->orc_material_unit); - if (comp_ctx->target_machine) LLVMDisposeTargetMachine(comp_ctx->target_machine); if (comp_ctx->builder) LLVMDisposeBuilder(comp_ctx->builder); - if (comp_ctx->orc_jit) - LLVMOrcDisposeLLJIT(comp_ctx->orc_jit); - if (comp_ctx->orc_thread_safe_context) LLVMOrcDisposeThreadSafeContext(comp_ctx->orc_thread_safe_context); /* Note: don't dispose comp_ctx->context and comp_ctx->module as they are disposed when disposing the thread safe context */ + /* Has to be the last one */ + if (comp_ctx->orc_jit) +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcDisposeLLLazyJIT(comp_ctx->orc_jit); +#else + LLVMOrcDisposeLLJIT(comp_ctx->orc_jit); +#endif + LLVMShutdown(); if (comp_ctx->func_ctxes) diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index 71351edf35..00aaae26c0 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -30,6 +30,8 @@ #include "llvm-c/DebugInfo.h" #endif +#include "orc_extra/aot_orc_extra.h" + #ifdef __cplusplus extern "C" { #endif @@ -48,6 +50,16 @@ extern "C" { #define OPQ_PTR_TYPE INT8_PTR_TYPE #endif +#ifndef NDEBUG +#undef DEBUG_PASS +#undef DUMP_MODULE +// #define DEBUG_PASS +// #define DUMP_MODULE +#else +#undef DEBUG_PASS +#undef DUMP_MODULE +#endif + /** * Value in the WASM operation stack, each stack element * is an LLVM value @@ -280,14 +292,14 @@ typedef struct AOTCompContext { /* Hardware intrinsic compability flags */ uint64 flags[8]; - /* LLVM execution engine required by JIT */ + /* required by JIT */ +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITRef orc_jit; +#else LLVMOrcLLJITRef orc_jit; - LLVMOrcMaterializationUnitRef orc_material_unit; - LLVMOrcLazyCallThroughManagerRef orc_call_through_mgr; - LLVMOrcIndirectStubsManagerRef orc_indirect_stub_mgr; - LLVMOrcCSymbolAliasMapPairs orc_symbol_map_pairs; +#endif LLVMOrcThreadSafeContextRef orc_thread_safe_context; - /* Each aot function has its own module */ + LLVMModuleRef module; bool is_jit_mode; @@ -492,19 +504,17 @@ aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass); void aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module); -LLVMOrcJITTargetMachineBuilderRef -LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(LLVMTargetMachineRef TM); - -void -LLVMOrcLLJITBuilderSetNumCompileThreads(LLVMOrcLLJITBuilderRef orcjit_builder, - unsigned num_compile_threads); - void aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err); void * -aot_lookup_orcjit_func(LLVMOrcLLJITRef orc_jit, void *module_inst, - uint32 func_idx); +aot_lookup_orcjit_func( +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITRef orc_jit, +#else + LLVMOrcLLJITRef orc_jit, +#endif + void *module_inst, uint32 func_idx); #ifdef __cplusplus } /* end of extern "C" */ diff --git a/core/iwasm/compilation/aot_llvm_extra.cpp b/core/iwasm/compilation/aot_llvm_extra.cpp index f02636a759..893dede471 100644 --- a/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/core/iwasm/compilation/aot_llvm_extra.cpp @@ -4,6 +4,7 @@ */ #include "llvm/Passes/StandardInstrumentations.h" +#include "llvm/Support/Error.h" #include #include #include @@ -51,7 +52,7 @@ using namespace llvm; using namespace llvm::orc; -extern "C" { +LLVM_C_EXTERN_C_BEGIN bool aot_check_simd_compatibility(const char *arch_c_str, const char *cpu_c_str); @@ -62,18 +63,12 @@ aot_add_expand_memory_op_pass(LLVMPassManagerRef pass); void aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass); -void -aot_func_disable_tce(LLVMValueRef func); - void aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module); -} -static TargetMachine * -unwrap(LLVMTargetMachineRef P) -{ - return reinterpret_cast(P); -} +LLVM_C_EXTERN_C_END + +ExitOnError ExitOnErr; class ExpandMemoryOpPass : public llvm::ModulePass { @@ -175,13 +170,15 @@ ExpandMemoryOpPass::runOnModule(Module &M) void aot_add_expand_memory_op_pass(LLVMPassManagerRef pass) { - unwrap(pass)->add(new ExpandMemoryOpPass()); + reinterpret_cast(pass)->add( + new ExpandMemoryOpPass()); } void aot_add_simple_loop_unswitch_pass(LLVMPassManagerRef pass) { - unwrap(pass)->add(createSimpleLoopUnswitchLegacyPass()); + reinterpret_cast(pass)->add( + createSimpleLoopUnswitchLegacyPass()); } bool @@ -225,18 +222,14 @@ aot_check_simd_compatibility(const char *arch_c_str, const char *cpu_c_str) #endif /* WASM_ENABLE_SIMD */ } -DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLJITBuilder, LLVMOrcLLJITBuilderRef) - -void -LLVMOrcLLJITBuilderSetNumCompileThreads(LLVMOrcLLJITBuilderRef orcjit_builder, - unsigned num_compile_threads) -{ - unwrap(orcjit_builder)->setNumCompileThreads(num_compile_threads); -} - void * -aot_lookup_orcjit_func(LLVMOrcLLJITRef orc_jit, void *module_inst, - uint32 func_idx) +aot_lookup_orcjit_func( +#if WASM_ENABLE_LAZY_JIT != 0 + LLVMOrcLLLazyJITRef orc_jit, +#else + LLVMOrcLLJITRef orc_jit, +#endif + void *module_inst, uint32 func_idx) { char func_name[32], buf[128], *err_msg = NULL; LLVMErrorRef error; @@ -256,7 +249,11 @@ aot_lookup_orcjit_func(LLVMOrcLLJITRef orc_jit, void *module_inst, snprintf(func_name, sizeof(func_name), "%s%d", AOT_FUNC_PREFIX, func_idx - aot_module->import_func_count); +#if WASM_ENABLE_LAZY_JIT != 0 + if ((error = LLVMOrcLLLazyJITLookup(orc_jit, &func_addr, func_name))) { +#else if ((error = LLVMOrcLLJITLookup(orc_jit, &func_addr, func_name))) { +#endif err_msg = LLVMGetErrorMessage(error); snprintf(buf, sizeof(buf), "failed to lookup orcjit function: %s", err_msg); @@ -268,34 +265,11 @@ aot_lookup_orcjit_func(LLVMOrcLLJITRef orc_jit, void *module_inst, return (void *)func_addr; } -void -aot_func_disable_tce(LLVMValueRef func) -{ - Function *F = unwrap(func); - auto Attrs = F->getAttributes(); - -#if LLVM_VERSION_MAJOR <= 13 - Attrs = Attrs.addAttribute(F->getContext(), AttributeList::FunctionIndex, - "disable-tail-calls", "true"); -#else - Attrs = - Attrs.addAttributeAtIndex(F->getContext(), AttributeList::FunctionIndex, - "disable-tail-calls", "true"); -#endif - F->setAttributes(Attrs); -} - -#ifndef NDEBUG -// #define DEBUG_PASS -#undef DEBUG_PASS -#else -#undef DEBUG_PASS -#endif - void aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) { - TargetMachine *TM = unwrap(comp_ctx->target_machine); + TargetMachine *TM = + reinterpret_cast(comp_ctx->target_machine); PipelineTuningOptions PTO; PTO.LoopVectorization = true; PTO.SLPVectorization = true; @@ -404,7 +378,7 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) // const char *Passes = "default"; const char *Passes = "mem2reg,instcombine,simplifycfg,jump-threading,indvars"; - auto Err = PB.parsePassPipeline(MPM, Passes); + ExitOnErr(PB.parsePassPipeline(MPM, Passes)); } else { FunctionPassManager FPM; diff --git a/core/iwasm/compilation/iwasm_compl.cmake b/core/iwasm/compilation/iwasm_compl.cmake index 4ec4603049..6fb372c41a 100644 --- a/core/iwasm/compilation/iwasm_compl.cmake +++ b/core/iwasm/compilation/iwasm_compl.cmake @@ -11,7 +11,8 @@ else() ${IWASM_COMPL_DIR}/simd/*.c ${IWASM_COMPL_DIR}/simd/*.cpp ${IWASM_COMPL_DIR}/*.c - ${IWASM_COMPL_DIR}/*.cpp) + ${IWASM_COMPL_DIR}/*.cpp + ${IWASM_COMPL_DIR}/orc_extra/*.cpp) endif() set (IWASM_COMPL_SOURCE ${source_all}) diff --git a/core/iwasm/compilation/orc_extra/aot_orc_extra.cpp b/core/iwasm/compilation/orc_extra/aot_orc_extra.cpp new file mode 100644 index 0000000000..4e091f56ff --- /dev/null +++ b/core/iwasm/compilation/orc_extra/aot_orc_extra.cpp @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#include "llvm-c/LLJIT.h" +#include "llvm-c/Orc.h" +#include "llvm-c/OrcEE.h" +#include "llvm-c/TargetMachine.h" + +#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" +#include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "llvm/ExecutionEngine/Orc/ObjectTransformLayer.h" +#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" +#include "llvm/Support/CBindingWrapping.h" + +#include "aot_orc_extra.h" + +using namespace llvm; +using namespace llvm::orc; + +namespace llvm { +namespace orc { + +class InProgressLookupState; + +class OrcV2CAPIHelper +{ + public: + using PoolEntry = SymbolStringPtr::PoolEntry; + using PoolEntryPtr = SymbolStringPtr::PoolEntryPtr; + + // Move from SymbolStringPtr to PoolEntryPtr (no change in ref count). + static PoolEntryPtr moveFromSymbolStringPtr(SymbolStringPtr S) + { + PoolEntryPtr Result = nullptr; + std::swap(Result, S.S); + return Result; + } + + // Move from a PoolEntryPtr to a SymbolStringPtr (no change in ref count). + static SymbolStringPtr moveToSymbolStringPtr(PoolEntryPtr P) + { + SymbolStringPtr S; + S.S = P; + return S; + } + + // Copy a pool entry to a SymbolStringPtr (increments ref count). + static SymbolStringPtr copyToSymbolStringPtr(PoolEntryPtr P) + { + return SymbolStringPtr(P); + } + + static PoolEntryPtr getRawPoolEntryPtr(const SymbolStringPtr &S) + { + return S.S; + } + + static void retainPoolEntry(PoolEntryPtr P) + { + SymbolStringPtr S(P); + S.S = nullptr; + } + + static void releasePoolEntry(PoolEntryPtr P) + { + SymbolStringPtr S; + S.S = P; + } + + static InProgressLookupState *extractLookupState(LookupState &LS) + { + return LS.IPLS.release(); + } + + static void resetLookupState(LookupState &LS, InProgressLookupState *IPLS) + { + return LS.reset(IPLS); + } +}; + +} // namespace orc +} // namespace llvm + +// ORC.h +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionSession, LLVMOrcExecutionSessionRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRTransformLayer, LLVMOrcIRTransformLayerRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITDylib, LLVMOrcJITDylibRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(JITTargetMachineBuilder, + LLVMOrcJITTargetMachineBuilderRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ObjectTransformLayer, + LLVMOrcObjectTransformLayerRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OrcV2CAPIHelper::PoolEntry, + LLVMOrcSymbolStringPoolEntryRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SymbolStringPool, LLVMOrcSymbolStringPoolRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ThreadSafeModule, LLVMOrcThreadSafeModuleRef) + +// LLJIT.h +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLJITBuilder, LLVMOrcLLJITBuilderRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLLazyJITBuilder, LLVMOrcLLLazyJITBuilderRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLLazyJIT, LLVMOrcLLLazyJITRef) + +void +LLVMOrcLLJITBuilderSetNumCompileThreads(LLVMOrcLLJITBuilderRef Builder, + unsigned NumCompileThreads) +{ + unwrap(Builder)->setNumCompileThreads(NumCompileThreads); +} + +LLVMOrcLLLazyJITBuilderRef +LLVMOrcCreateLLLazyJITBuilder(void) +{ + return wrap(new LLLazyJITBuilder()); +} + +void +LLVMOrcDisposeLLLazyJITBuilder(LLVMOrcLLLazyJITBuilderRef Builder) +{ + delete unwrap(Builder); +} + +void +LLVMOrcLLLazyJITBuilderSetNumCompileThreads(LLVMOrcLLLazyJITBuilderRef Builder, + unsigned NumCompileThreads) +{ + unwrap(Builder)->setNumCompileThreads(NumCompileThreads); +} + +void +LLVMOrcLLLazyJITBuilderSetJITTargetMachineBuilder( + LLVMOrcLLLazyJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMP) +{ + unwrap(Builder)->setJITTargetMachineBuilder(*unwrap(JTMP)); +} + +LLVMErrorRef +LLVMOrcCreateLLLazyJIT(LLVMOrcLLLazyJITRef *Result, + LLVMOrcLLLazyJITBuilderRef Builder) +{ + assert(Result && "Result can not be null"); + + if (!Builder) + Builder = LLVMOrcCreateLLLazyJITBuilder(); + + auto J = unwrap(Builder)->create(); + LLVMOrcDisposeLLLazyJITBuilder(Builder); + + if (!J) { + Result = nullptr; + return wrap(J.takeError()); + } + + *Result = wrap(J->release()); + return LLVMErrorSuccess; +} + +LLVMErrorRef +LLVMOrcDisposeLLLazyJIT(LLVMOrcLLLazyJITRef J) +{ + delete unwrap(J); + return LLVMErrorSuccess; +} + +LLVMErrorRef +LLVMOrcLLLazyJITAddLLVMIRModule(LLVMOrcLLLazyJITRef J, LLVMOrcJITDylibRef JD, + LLVMOrcThreadSafeModuleRef TSM) +{ + std::unique_ptr TmpTSM(unwrap(TSM)); + return wrap(unwrap(J)->addLazyIRModule(*unwrap(JD), std::move(*TmpTSM))); +} + +LLVMErrorRef +LLVMOrcLLLazyJITLookup(LLVMOrcLLLazyJITRef J, LLVMOrcExecutorAddress *Result, + const char *Name) +{ + assert(Result && "Result can not be null"); + + auto Sym = unwrap(J)->lookup(Name); + if (!Sym) { + *Result = 0; + return wrap(Sym.takeError()); + } + + *Result = Sym->getAddress(); + return LLVMErrorSuccess; +} + +LLVMOrcSymbolStringPoolEntryRef +LLVMOrcLLLazyJITMangleAndIntern(LLVMOrcLLLazyJITRef J, + const char *UnmangledName) +{ + return wrap(OrcV2CAPIHelper::moveFromSymbolStringPtr( + unwrap(J)->mangleAndIntern(UnmangledName))); +} + +LLVMOrcJITDylibRef +LLVMOrcLLLazyJITGetMainJITDylib(LLVMOrcLLLazyJITRef J) +{ + return wrap(&unwrap(J)->getMainJITDylib()); +} + +const char * +LLVMOrcLLLazyJITGetTripleString(LLVMOrcLLLazyJITRef J) +{ + return unwrap(J)->getTargetTriple().str().c_str(); +} + +LLVMOrcExecutionSessionRef +LLVMOrcLLLazyJITGetExecutionSession(LLVMOrcLLLazyJITRef J) +{ + return wrap(&unwrap(J)->getExecutionSession()); +} + +LLVMOrcIRTransformLayerRef +LLVMOrcLLLazyJITGetIRTransformLayer(LLVMOrcLLLazyJITRef J) +{ + return wrap(&unwrap(J)->getIRTransformLayer()); +} + +LLVMOrcObjectTransformLayerRef +LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J) +{ + return wrap(&unwrap(J)->getObjTransformLayer()); +} \ No newline at end of file diff --git a/core/iwasm/compilation/orc_extra/aot_orc_extra.h b/core/iwasm/compilation/orc_extra/aot_orc_extra.h new file mode 100644 index 0000000000..e152b87784 --- /dev/null +++ b/core/iwasm/compilation/orc_extra/aot_orc_extra.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + */ + +#ifndef _AOT_ORC_LAZINESS_H_ +#define _AOT_ORC_LAZINESS_H_ + +#include "llvm-c/Error.h" +#include "llvm-c/ExternC.h" +#include "llvm-c/LLJIT.h" +#include "llvm-c/Orc.h" +#include "llvm-c/Types.h" + +LLVM_C_EXTERN_C_BEGIN + +typedef struct LLVMOrcOpaqueLLLazyJITBuilder *LLVMOrcLLLazyJITBuilderRef; +typedef struct LLVMOrcOpaqueLLLazyJIT *LLVMOrcLLLazyJITRef; + +// Extra bindings for LLJIT +void +LLVMOrcLLJITBuilderSetNumCompileThreads(LLVMOrcLLJITBuilderRef Builder, + unsigned NumCompileThreads); + +// Extra bindings for LLLazyJIT +LLVMOrcLLLazyJITBuilderRef +LLVMOrcCreateLLLazyJITBuilder(void); + +void +LLVMOrcDisposeLLLazyJITBuilder(LLVMOrcLLLazyJITBuilderRef Builder); + +void +LLVMOrcLLLazyJITBuilderSetJITTargetMachineBuilder( + LLVMOrcLLLazyJITBuilderRef Builder, LLVMOrcJITTargetMachineBuilderRef JTMP); + +void +LLVMOrcLLLazyJITBuilderSetNumCompileThreads(LLVMOrcLLLazyJITBuilderRef Builder, + unsigned NumCompileThreads); + +LLVMErrorRef +LLVMOrcCreateLLLazyJIT(LLVMOrcLLLazyJITRef *Result, + LLVMOrcLLLazyJITBuilderRef Builder); + +LLVMErrorRef +LLVMOrcDisposeLLLazyJIT(LLVMOrcLLLazyJITRef J); + +LLVMErrorRef +LLVMOrcLLLazyJITAddLLVMIRModule(LLVMOrcLLLazyJITRef J, LLVMOrcJITDylibRef JD, + LLVMOrcThreadSafeModuleRef TSM); + +LLVMErrorRef +LLVMOrcLLLazyJITLookup(LLVMOrcLLLazyJITRef J, LLVMOrcExecutorAddress *Result, + const char *Name); + +LLVMOrcSymbolStringPoolEntryRef +LLVMOrcLLLazyJITMangleAndIntern(LLVMOrcLLLazyJITRef J, + const char *UnmangledName); + +LLVMOrcJITDylibRef +LLVMOrcLLLazyJITGetMainJITDylib(LLVMOrcLLLazyJITRef J); + +const char * +LLVMOrcLLLazyJITGetTripleString(LLVMOrcLLLazyJITRef J); + +LLVMOrcExecutionSessionRef +LLVMOrcLLLazyJITGetExecutionSession(LLVMOrcLLLazyJITRef J); + +LLVMOrcIRTransformLayerRef +LLVMOrcLLLazyJITGetIRTransformLayer(LLVMOrcLLLazyJITRef J); + +LLVMOrcObjectTransformLayerRef +LLVMOrcLLLazyJITGetObjTransformLayer(LLVMOrcLLLazyJITRef J); + +LLVM_C_EXTERN_C_END +#endif diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 3434e2021a..b6dbfaf40c 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -173,10 +173,18 @@ readonly FAST_INTERP_COMPILE_FLAGS="\ # jit: report linking error if set COLLECT_CODE_COVERAGE, # now we don't collect code coverage of jit type -readonly JIT_COMPILE_FLAGS="\ +readonly ORC_EAGER_JIT_COMPILE_FLAGS="\ -DWAMR_BUILD_TARGET=${TARGET} \ -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \ -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \ + -DWAMR_BUILD_LAZY_JIT=0 \ + -DWAMR_BUILD_SPEC_TEST=1" + +readonly ORC_LAZY_JIT_COMPILE_FLAGS="\ + -DWAMR_BUILD_TARGET=${TARGET} \ + -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \ + -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \ + -DWAMR_BUILD_LAZY_JIT=1 \ -DWAMR_BUILD_SPEC_TEST=1" readonly AOT_COMPILE_FLAGS="\ @@ -196,7 +204,8 @@ readonly FAST_JIT_COMPILE_FLAGS="\ readonly COMPILE_FLAGS=( "${CLASSIC_INTERP_COMPILE_FLAGS}" "${FAST_INTERP_COMPILE_FLAGS}" - "${JIT_COMPILE_FLAGS}" + "${ORC_EAGER_JIT_COMPILE_FLAGS}" + "${ORC_LAZY_JIT_COMPILE_FLAGS}" "${AOT_COMPILE_FLAGS}" "${FAST_JIT_COMPILE_FLAGS}" ) @@ -595,9 +604,16 @@ function trigger() continue fi - echo "work in jit mode" - # jit - BUILD_FLAGS="$JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS" + echo "work in orc jit eager compilation mode" + BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS" + build_iwasm_with_cfg $BUILD_FLAGS + build_wamrc + for suite in "${TEST_CASE_ARR[@]}"; do + $suite"_test" jit + done + + echo "work in orc jit lazy compilation mode" + BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS" build_iwasm_with_cfg $BUILD_FLAGS build_wamrc for suite in "${TEST_CASE_ARR[@]}"; do