diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 667a1977..4a0cba09 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -242,11 +242,11 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module, LLVMTypeRef func_type, LLVMValueRef wrapped_func) { LLVMValueRef precheck_func; - LLVMBasicBlockRef begin; - LLVMBasicBlockRef check_top_block; - LLVMBasicBlockRef update_top_block; - LLVMBasicBlockRef stack_bound_check_block; - LLVMBasicBlockRef call_wrapped_func_block; + LLVMBasicBlockRef begin = NULL; + LLVMBasicBlockRef check_top_block = NULL; + LLVMBasicBlockRef update_top_block = NULL; + LLVMBasicBlockRef stack_bound_check_block = NULL; + LLVMBasicBlockRef call_wrapped_func_block = NULL; LLVMValueRef *params = NULL; precheck_func = @@ -385,6 +385,8 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module, goto fail; } + bh_assert(update_top_block); + /* * update native_stack_top_min if * new_sp = sp - size < native_stack_top_min @@ -412,7 +414,7 @@ aot_add_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module, */ LLVMPositionBuilderAtEnd(b, update_top_block); LLVMValueRef new_sp_ptr = - LLVMBuildIntToPtr(b, new_sp, OPQ_PTR_TYPE, "new_sp_ptr"); + LLVMBuildIntToPtr(b, new_sp, INT8_PTR_TYPE, "new_sp_ptr"); if (!new_sp_ptr) { goto fail; } @@ -1376,25 +1378,33 @@ static bool aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx) { const char *stack_sizes_name = "stack_sizes"; - LLVMTypeRef stack_sizes_type = - LLVMArrayType(I32_TYPE, comp_data->func_count); + LLVMValueRef stack_sizes, *values, array, alias; + LLVMTypeRef stack_sizes_type; +#if LLVM_VERSION_MAJOR <= 13 + LLVMTypeRef alias_type; +#endif + uint64 size; + uint32 i; + + stack_sizes_type = LLVMArrayType(I32_TYPE, comp_data->func_count); if (!stack_sizes_type) { aot_set_last_error("failed to create stack_sizes type."); return false; } - LLVMValueRef stack_sizes = + + stack_sizes = LLVMAddGlobal(comp_ctx->module, stack_sizes_type, stack_sizes_name); if (!stack_sizes) { aot_set_last_error("failed to create stack_sizes global."); return false; } - LLVMValueRef *values; - uint64 size = sizeof(LLVMValueRef) * comp_data->func_count; + + size = sizeof(LLVMValueRef) * comp_data->func_count; if (size >= UINT32_MAX || !(values = wasm_runtime_malloc((uint32)size))) { aot_set_last_error("allocate memory failed."); return false; } - uint32 i; + for (i = 0; i < comp_data->func_count; i++) { /* * This value is a placeholder, which will be replaced @@ -1405,23 +1415,35 @@ aot_create_stack_sizes(const AOTCompData *comp_data, AOTCompContext *comp_ctx) */ values[i] = I32_NEG_ONE; } - LLVMValueRef array = - LLVMConstArray(I32_TYPE, values, comp_data->func_count); + + array = LLVMConstArray(I32_TYPE, values, comp_data->func_count); wasm_runtime_free(values); if (!array) { aot_set_last_error("failed to create stack_sizes initializer."); return false; } LLVMSetInitializer(stack_sizes, array); + /* * create an alias so that aot_resolve_stack_sizes can find it. */ - LLVMValueRef alias = LLVMAddAlias2(comp_ctx->module, stack_sizes_type, 0, - stack_sizes, aot_stack_sizes_name); +#if LLVM_VERSION_MAJOR > 13 + alias = LLVMAddAlias2(comp_ctx->module, stack_sizes_type, 0, stack_sizes, + aot_stack_sizes_name); +#else + alias_type = LLVMPointerType(stack_sizes_type, 0); + if (!alias_type) { + aot_set_last_error("failed to create alias type."); + return false; + } + alias = LLVMAddAlias(comp_ctx->module, alias_type, stack_sizes, + aot_stack_sizes_name); +#endif if (!alias) { aot_set_last_error("failed to create stack_sizes alias."); return false; } + /* * make the original symbol internal. we mainly use this version to * avoid creating extra relocations in the precheck functions. diff --git a/core/iwasm/compilation/aot_llvm_extra.cpp b/core/iwasm/compilation/aot_llvm_extra.cpp index a8843cce..10903940 100644 --- a/core/iwasm/compilation/aot_llvm_extra.cpp +++ b/core/iwasm/compilation/aot_llvm_extra.cpp @@ -235,7 +235,11 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module) PTO.SLPVectorization = true; PTO.LoopUnrolling = true; - Optional PGO = None; +#if LLVM_VERSION_MAJOR >= 16 + Optional PGO = std::nullopt; +#else + Optional PGO = llvm::None; +#endif if (comp_ctx->enable_llvm_pgo) { /* Disable static counter allocation for value profiler, it will be allocated by runtime */ diff --git a/core/iwasm/compilation/aot_llvm_extra2.cpp b/core/iwasm/compilation/aot_llvm_extra2.cpp index 94eee858..42e53ddf 100644 --- a/core/iwasm/compilation/aot_llvm_extra2.cpp +++ b/core/iwasm/compilation/aot_llvm_extra2.cpp @@ -23,7 +23,11 @@ convert(LLVMRelocMode reloc_mode) { switch (reloc_mode) { case LLVMRelocDefault: +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif case LLVMRelocStatic: return llvm::Reloc::Static; case LLVMRelocPIC: @@ -38,7 +42,11 @@ convert(LLVMRelocMode reloc_mode) return llvm::Reloc::ROPI_RWPI; } bh_assert(0); +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif } static llvm::CodeGenOpt::Level @@ -64,10 +72,18 @@ convert(LLVMCodeModel code_model, bool *jit) *jit = false; switch (code_model) { case LLVMCodeModelDefault: +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif case LLVMCodeModelJITDefault: *jit = true; +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif case LLVMCodeModelTiny: return llvm::CodeModel::Tiny; case LLVMCodeModelSmall: @@ -80,7 +96,11 @@ convert(LLVMCodeModel code_model, bool *jit) return llvm::CodeModel::Large; } bh_assert(0); +#if LLVM_VERSION_MAJOR >= 16 + return std::nullopt; +#else return llvm::None; +#endif } LLVMTargetMachineRef diff --git a/core/iwasm/compilation/aot_orc_extra2.cpp b/core/iwasm/compilation/aot_orc_extra2.cpp index 3b028f15..515f7209 100644 --- a/core/iwasm/compilation/aot_orc_extra2.cpp +++ b/core/iwasm/compilation/aot_orc_extra2.cpp @@ -112,10 +112,16 @@ MyCompiler::operator()(llvm::Module &M) PM.run(M); } +#if LLVM_VERSION_MAJOR > 13 auto ObjBuffer = std::make_unique( std::move(ObjBufferSV), M.getModuleIdentifier() + "-jitted-objectbuffer", /*RequiresNullTerminator=*/false); +#else + auto ObjBuffer = std::make_unique( + std::move(ObjBufferSV), + M.getModuleIdentifier() + "-jitted-objectbuffer"); +#endif return std::move(ObjBuffer); }