mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-09 05:06:17 +00:00
Enable aot compiler with llvm-14/15 (#1252)
Enable aot compiler and jit based on llvm-14.0 and llvm-15.0git, replace LLVMBuildLoad/LLVMBuildInBoundsGEP/LLVMBuildCall with LLVMBuildLoad2/LLVMBuildInBoundsGEP2/LLVMBuildCall2, and pass them with related types, so as to meet the requirements of opaque pointers. And fix several compilation errors for llvm-14.0/15.0git. Most spec cases and standalone cases are tested.
This commit is contained in:
parent
2746d29751
commit
5e238322c2
|
@ -2641,7 +2641,12 @@ apply_func_passes(AOTCompContext *comp_ctx)
|
||||||
LLVMAddLoopVectorizePass(pass_mgr);
|
LLVMAddLoopVectorizePass(pass_mgr);
|
||||||
LLVMAddSLPVectorizePass(pass_mgr);
|
LLVMAddSLPVectorizePass(pass_mgr);
|
||||||
LLVMAddLoopRotatePass(pass_mgr);
|
LLVMAddLoopRotatePass(pass_mgr);
|
||||||
|
#if LLVM_VERSION_MAJOR < 15
|
||||||
LLVMAddLoopUnswitchPass(pass_mgr);
|
LLVMAddLoopUnswitchPass(pass_mgr);
|
||||||
|
/* Binding disabled in LLVM 15, don't add the pass util we can either
|
||||||
|
add a binding to SimpleLoopUnswitchPass, or add it to
|
||||||
|
aot_llvm_extra.cpp */
|
||||||
|
#endif
|
||||||
LLVMAddInstructionCombiningPass(pass_mgr);
|
LLVMAddInstructionCombiningPass(pass_mgr);
|
||||||
LLVMAddCFGSimplificationPass(pass_mgr);
|
LLVMAddCFGSimplificationPass(pass_mgr);
|
||||||
if (!comp_ctx->enable_thread_mgr) {
|
if (!comp_ctx->enable_thread_mgr) {
|
||||||
|
@ -2694,8 +2699,10 @@ apply_lto_passes(AOTCompContext *comp_ctx)
|
||||||
LLVMPassManagerBuilderSetOptLevel(pass_mgr_builder, comp_ctx->opt_level);
|
LLVMPassManagerBuilderSetOptLevel(pass_mgr_builder, comp_ctx->opt_level);
|
||||||
LLVMPassManagerBuilderPopulateModulePassManager(pass_mgr_builder,
|
LLVMPassManagerBuilderPopulateModulePassManager(pass_mgr_builder,
|
||||||
common_pass_mgr);
|
common_pass_mgr);
|
||||||
|
#if LLVM_VERSION_MAJOR < 15
|
||||||
LLVMPassManagerBuilderPopulateLTOPassManager(pass_mgr_builder,
|
LLVMPassManagerBuilderPopulateLTOPassManager(pass_mgr_builder,
|
||||||
common_pass_mgr, true, true);
|
common_pass_mgr, true, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if WASM_ENABLE_LAZY_JIT == 0
|
#if WASM_ENABLE_LAZY_JIT == 0
|
||||||
LLVMRunPassManager(common_pass_mgr, comp_ctx->module);
|
LLVMRunPassManager(common_pass_mgr, comp_ctx->module);
|
||||||
|
|
|
@ -72,7 +72,8 @@ aot_compile_op_f32_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
aot_set_last_error("llvm build bitcast failed.");
|
aot_set_last_error("llvm build bitcast failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(value = LLVMBuildLoad(comp_ctx->builder, alloca, ""))) {
|
if (!(value =
|
||||||
|
LLVMBuildLoad2(comp_ctx->builder, F32_TYPE, alloca, ""))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +128,8 @@ aot_compile_op_f64_const(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
aot_set_last_error("llvm build bitcast failed.");
|
aot_set_last_error("llvm build bitcast failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(value = LLVMBuildLoad(comp_ctx->builder, alloca, ""))) {
|
if (!(value =
|
||||||
|
LLVMBuildLoad2(comp_ctx->builder, F64_TYPE, alloca, ""))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -677,9 +677,9 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
/* Offset of suspend_flags */
|
/* Offset of suspend_flags */
|
||||||
offset = I32_FIVE;
|
offset = I32_FIVE;
|
||||||
|
|
||||||
if (!(terminate_addr =
|
if (!(terminate_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->exec_env,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env, &offset, 1,
|
||||||
&offset, 1, "terminate_addr"))) {
|
"terminate_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -690,8 +690,9 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(terminate_flags = LLVMBuildLoad(comp_ctx->builder, terminate_addr,
|
if (!(terminate_flags =
|
||||||
"terminate_flags"))) {
|
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, terminate_addr,
|
||||||
|
"terminate_flags"))) {
|
||||||
aot_set_last_error("llvm build bit cast failed");
|
aot_set_last_error("llvm build bit cast failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,8 @@ aot_emit_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
/* Call the aot_set_exception_with_id() function */
|
/* Call the aot_set_exception_with_id() function */
|
||||||
param_values[0] = func_ctx->aot_inst;
|
param_values[0] = func_ctx->aot_inst;
|
||||||
param_values[1] = func_ctx->exception_id_phi;
|
param_values[1] = func_ctx->exception_id_phi;
|
||||||
if (!LLVMBuildCall(comp_ctx->builder, func, param_values, 2, "")) {
|
if (!LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 2,
|
||||||
|
"")) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,8 @@ check_exception_thrown(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
|
|
||||||
/* Load the first byte of aot_module_inst->cur_exception, and check
|
/* Load the first byte of aot_module_inst->cur_exception, and check
|
||||||
whether it is '\0'. If yes, no exception was thrown. */
|
whether it is '\0'. If yes, no exception was thrown. */
|
||||||
if (!(value = LLVMBuildLoad(comp_ctx->builder, func_ctx->cur_exception,
|
if (!(value = LLVMBuildLoad2(comp_ctx->builder, INT8_TYPE,
|
||||||
"exce_value"))
|
func_ctx->cur_exception, "exce_value"))
|
||||||
|| !(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ, value, I8_ZERO,
|
|| !(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ, value, I8_ZERO,
|
||||||
"cmp"))) {
|
"cmp"))) {
|
||||||
aot_set_last_error("llvm build icmp failed.");
|
aot_set_last_error("llvm build icmp failed.");
|
||||||
|
@ -207,8 +207,9 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s%d", "elem", i);
|
snprintf(buf, sizeof(buf), "%s%d", "elem", i);
|
||||||
if (!(elem_ptr = LLVMBuildInBoundsGEP(
|
if (!(elem_ptr =
|
||||||
comp_ctx->builder, func_ctx->argv_buf, &elem_idx, 1, buf))
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE,
|
||||||
|
func_ctx->argv_buf, &elem_idx, 1, buf))
|
||||||
|| !(elem_ptr = LLVMBuildBitCast(comp_ctx->builder, elem_ptr,
|
|| !(elem_ptr = LLVMBuildBitCast(comp_ctx->builder, elem_ptr,
|
||||||
elem_ptr_type, buf))) {
|
elem_ptr_type, buf))) {
|
||||||
aot_set_last_error("llvm build bit cast failed.");
|
aot_set_last_error("llvm build bit cast failed.");
|
||||||
|
@ -236,8 +237,8 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call aot_invoke_native() function */
|
/* call aot_invoke_native() function */
|
||||||
if (!(res = LLVMBuildCall(comp_ctx->builder, func, func_param_values, 4,
|
if (!(res = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"res"))) {
|
func_param_values, 4, "res"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -255,8 +256,8 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
aot_set_last_error("llvm build bit cast failed.");
|
aot_set_last_error("llvm build bit cast failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(*p_value_ret =
|
if (!(*p_value_ret = LLVMBuildLoad2(comp_ctx->builder, ret_type,
|
||||||
LLVMBuildLoad(comp_ctx->builder, value_ret, "value_ret"))) {
|
value_ret, "value_ret"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -299,14 +300,15 @@ lookup_orcjit_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
|
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
|
||||||
|
|
||||||
/* Load function pointer */
|
/* Load function pointer */
|
||||||
if (!(func_ptr =
|
if (!(func_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->func_ptrs,
|
func_ctx->func_ptrs, &func_idx, 1,
|
||||||
&func_idx, 1, "func_ptr_tmp"))) {
|
"func_ptr_tmp"))) {
|
||||||
aot_set_last_error("llvm build inbounds gep failed.");
|
aot_set_last_error("llvm build inbounds gep failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func = LLVMBuildLoad(comp_ctx->builder, func_ptr, "func_ptr"))) {
|
if (!(func = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, func_ptr,
|
||||||
|
"func_ptr"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -364,8 +366,8 @@ lookup_orcjit_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call the function */
|
/* Call the function */
|
||||||
if (!(func = LLVMBuildCall(comp_ctx->builder, func, param_values, 3,
|
if (!(func = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call_orcjit_lookup"))) {
|
param_values, 3, "call_orcjit_lookup"))) {
|
||||||
aot_set_last_error("LLVM build call failed.");
|
aot_set_last_error("LLVM build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -410,8 +412,9 @@ call_aot_alloc_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
param_values[0] = func_ctx->exec_env;
|
param_values[0] = func_ctx->exec_env;
|
||||||
param_values[1] = func_idx;
|
param_values[1] = func_idx;
|
||||||
|
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 2,
|
if (!(ret_value =
|
||||||
"call_aot_alloc_frame"))) {
|
LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values,
|
||||||
|
2, "call_aot_alloc_frame"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -462,8 +465,8 @@ call_aot_free_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
|
|
||||||
param_values[0] = func_ctx->exec_env;
|
param_values[0] = func_ctx->exec_env;
|
||||||
|
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 1,
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call_aot_free_frame"))) {
|
param_values, 1, "call_aot_free_frame"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -488,8 +491,8 @@ check_stack_boundary(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(stack_bound = LLVMBuildInBoundsGEP(
|
if (!(stack_bound = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->native_stack_bound,
|
comp_ctx->builder, INT8_TYPE, func_ctx->native_stack_bound,
|
||||||
&callee_local_size, 1, "stack_bound"))) {
|
&callee_local_size, 1, "stack_bound"))) {
|
||||||
aot_set_last_error("llvm build inbound gep failed.");
|
aot_set_last_error("llvm build inbound gep failed.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -603,8 +606,8 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call aot_check_app_addr_and_convert() function */
|
/* call aot_check_app_addr_and_convert() function */
|
||||||
if (!(res = LLVMBuildCall(comp_ctx->builder, func, func_param_values, 5,
|
if (!(res = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"res"))) {
|
func_param_values, 5, "res"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -614,8 +617,9 @@ check_app_addr_and_convert(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(*p_native_addr_converted = LLVMBuildLoad(
|
if (!(*p_native_addr_converted =
|
||||||
comp_ctx->builder, native_addr_ptr, "native_addr"))) {
|
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, native_addr_ptr,
|
||||||
|
"native_addr"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -734,9 +738,9 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "ext_ret%d_ptr", i);
|
snprintf(buf, sizeof(buf), "ext_ret%d_ptr", i);
|
||||||
if (!(ext_ret_ptr = LLVMBuildInBoundsGEP(comp_ctx->builder,
|
if (!(ext_ret_ptr = LLVMBuildInBoundsGEP2(
|
||||||
func_ctx->argv_buf,
|
comp_ctx->builder, I32_TYPE, func_ctx->argv_buf,
|
||||||
&ext_ret_idx, 1, buf))) {
|
&ext_ret_idx, 1, buf))) {
|
||||||
aot_set_last_error("llvm build GEP failed.");
|
aot_set_last_error("llvm build GEP failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -841,15 +845,15 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load function pointer */
|
/* Load function pointer */
|
||||||
if (!(func_ptr = LLVMBuildInBoundsGEP(
|
if (!(func_ptr = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->func_ptrs, &import_func_idx,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->func_ptrs,
|
||||||
1, "native_func_ptr_tmp"))) {
|
&import_func_idx, 1, "native_func_ptr_tmp"))) {
|
||||||
aot_set_last_error("llvm build inbounds gep failed.");
|
aot_set_last_error("llvm build inbounds gep failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_ptr = LLVMBuildLoad(comp_ctx->builder, func_ptr,
|
if (!(func_ptr = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
"native_func_ptr"))) {
|
func_ptr, "native_func_ptr"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -861,8 +865,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call the function */
|
/* Call the function */
|
||||||
if (!(value_ret = LLVMBuildCall(
|
if (!(value_ret = LLVMBuildCall2(
|
||||||
comp_ctx->builder, func, param_values,
|
comp_ctx->builder, native_func_type, func, param_values,
|
||||||
(uint32)param_count + 1 + ext_ret_count,
|
(uint32)param_count + 1 + ext_ret_count,
|
||||||
(func_type->result_count > 0 ? "call" : "")))) {
|
(func_type->result_count > 0 ? "call" : "")))) {
|
||||||
aot_set_last_error("LLVM build call failed.");
|
aot_set_last_error("LLVM build call failed.");
|
||||||
|
@ -877,6 +881,9 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if LLVM_VERSION_MAJOR >= 14
|
||||||
|
LLVMTypeRef llvm_func_type;
|
||||||
|
#endif
|
||||||
bool recursive_call =
|
bool recursive_call =
|
||||||
(func_ctx == func_ctxes[func_idx - import_func_count]) ? true
|
(func_ctx == func_ctxes[func_idx - import_func_count]) ? true
|
||||||
: false;
|
: false;
|
||||||
|
@ -943,11 +950,15 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
&& !check_stack_boundary(comp_ctx, func_ctx, callee_cell_num))
|
&& !check_stack_boundary(comp_ctx, func_ctx, callee_cell_num))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 14
|
||||||
|
llvm_func_type = func_ctxes[func_idx - import_func_count]->func_type;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Call the function */
|
/* Call the function */
|
||||||
if (!(value_ret =
|
if (!(value_ret = LLVMBuildCall2(
|
||||||
LLVMBuildCall(comp_ctx->builder, func, param_values,
|
comp_ctx->builder, llvm_func_type, func, param_values,
|
||||||
(uint32)param_count + 1 + ext_ret_count,
|
(uint32)param_count + 1 + ext_ret_count,
|
||||||
(func_type->result_count > 0 ? "call" : "")))) {
|
(func_type->result_count > 0 ? "call" : "")))) {
|
||||||
aot_set_last_error("LLVM build call failed.");
|
aot_set_last_error("LLVM build call failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -972,9 +983,9 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
/* Load extra result from its address and push to stack */
|
/* Load extra result from its address and push to stack */
|
||||||
for (i = 0; i < ext_ret_count; i++) {
|
for (i = 0; i < ext_ret_count; i++) {
|
||||||
snprintf(buf, sizeof(buf), "func%d_ext_ret%d", func_idx, i);
|
snprintf(buf, sizeof(buf), "func%d_ext_ret%d", func_idx, i);
|
||||||
if (!(ext_ret =
|
if (!(ext_ret = LLVMBuildLoad2(
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
comp_ctx->builder, TO_LLVM_TYPE(ext_ret_types[i]),
|
||||||
param_values[1 + param_count + i], buf))) {
|
param_values[1 + param_count + i], buf))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1084,8 +1095,9 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s%d", "elem", i);
|
snprintf(buf, sizeof(buf), "%s%d", "elem", i);
|
||||||
if (!(elem_ptr = LLVMBuildInBoundsGEP(
|
if (!(elem_ptr =
|
||||||
comp_ctx->builder, func_ctx->argv_buf, &elem_idx, 1, buf))
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE,
|
||||||
|
func_ctx->argv_buf, &elem_idx, 1, buf))
|
||||||
|| !(elem_ptr = LLVMBuildBitCast(comp_ctx->builder, elem_ptr,
|
|| !(elem_ptr = LLVMBuildBitCast(comp_ctx->builder, elem_ptr,
|
||||||
elem_ptr_type, buf))) {
|
elem_ptr_type, buf))) {
|
||||||
aot_set_last_error("llvm build bit cast failed.");
|
aot_set_last_error("llvm build bit cast failed.");
|
||||||
|
@ -1114,8 +1126,8 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call aot_call_indirect() function */
|
/* call aot_call_indirect() function */
|
||||||
if (!(res = LLVMBuildCall(comp_ctx->builder, func, func_param_values, 5,
|
if (!(res = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"res"))) {
|
func_param_values, 5, "res"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1131,8 +1143,9 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "argv_ret%d", i);
|
snprintf(buf, sizeof(buf), "argv_ret%d", i);
|
||||||
if (!(ret_ptr = LLVMBuildInBoundsGEP(
|
if (!(ret_ptr =
|
||||||
comp_ctx->builder, func_ctx->argv_buf, &ret_idx, 1, buf))
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE,
|
||||||
|
func_ctx->argv_buf, &ret_idx, 1, buf))
|
||||||
|| !(ret_ptr = LLVMBuildBitCast(comp_ctx->builder, ret_ptr,
|
|| !(ret_ptr = LLVMBuildBitCast(comp_ctx->builder, ret_ptr,
|
||||||
ret_ptr_type, buf))) {
|
ret_ptr_type, buf))) {
|
||||||
aot_set_last_error("llvm build GEP or bit cast failed.");
|
aot_set_last_error("llvm build GEP or bit cast failed.");
|
||||||
|
@ -1140,7 +1153,8 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "ret%d", i);
|
snprintf(buf, sizeof(buf), "ret%d", i);
|
||||||
if (!(value_rets[i] = LLVMBuildLoad(comp_ctx->builder, ret_ptr, buf))) {
|
if (!(value_rets[i] =
|
||||||
|
LLVMBuildLoad2(comp_ctx->builder, ret_type, ret_ptr, buf))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1208,8 +1222,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(table_size_const = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst,
|
if (!(table_size_const = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "cur_size_i8p"))) {
|
func_ctx->aot_inst, &offset,
|
||||||
|
1, "cur_size_i8p"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildGEP");
|
HANDLE_FAILURE("LLVMBuildGEP");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1221,8 +1236,8 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(table_size_const =
|
if (!(table_size_const = LLVMBuildLoad2(comp_ctx->builder, I32_TYPE,
|
||||||
LLVMBuildLoad(comp_ctx->builder, table_size_const, "cur_size"))) {
|
table_size_const, "cur_size"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildLoad");
|
HANDLE_FAILURE("LLVMBuildLoad");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1255,8 +1270,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst,
|
if (!(table_elem = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "table_elem_i8p"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
|
"table_elem_i8p"))) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1268,14 +1284,15 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load function index */
|
/* Load function index */
|
||||||
if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, table_elem, &elem_idx, 1,
|
if (!(table_elem =
|
||||||
"table_elem"))) {
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE, table_elem,
|
||||||
|
&elem_idx, 1, "table_elem"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildNUWAdd");
|
HANDLE_FAILURE("LLVMBuildNUWAdd");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_idx =
|
if (!(func_idx = LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, table_elem,
|
||||||
LLVMBuildLoad(comp_ctx->builder, table_elem, "func_idx"))) {
|
"func_idx"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1302,15 +1319,15 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* Load function type index */
|
/* Load function type index */
|
||||||
if (!(ftype_idx_ptr = LLVMBuildInBoundsGEP(
|
if (!(ftype_idx_ptr = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->func_type_indexes, &func_idx, 1,
|
comp_ctx->builder, I32_TYPE, func_ctx->func_type_indexes,
|
||||||
"ftype_idx_ptr"))) {
|
&func_idx, 1, "ftype_idx_ptr"))) {
|
||||||
aot_set_last_error("llvm build inbounds gep failed.");
|
aot_set_last_error("llvm build inbounds gep failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ftype_idx =
|
if (!(ftype_idx = LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, ftype_idx_ptr,
|
||||||
LLVMBuildLoad(comp_ctx->builder, ftype_idx_ptr, "ftype_idx"))) {
|
"ftype_idx"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1399,9 +1416,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
CHECK_LLVM_CONST(ext_ret_offset);
|
CHECK_LLVM_CONST(ext_ret_offset);
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "ext_ret%d_ptr", i - 1);
|
snprintf(buf, sizeof(buf), "ext_ret%d_ptr", i - 1);
|
||||||
if (!(ext_ret_ptr =
|
if (!(ext_ret_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE,
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->argv_buf,
|
func_ctx->argv_buf,
|
||||||
&ext_ret_offset, 1, buf))) {
|
&ext_ret_offset, 1, buf))) {
|
||||||
aot_set_last_error("llvm build GEP failed.");
|
aot_set_last_error("llvm build GEP failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1553,14 +1570,15 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
#if WASM_ENABLE_LAZY_JIT == 0
|
#if WASM_ENABLE_LAZY_JIT == 0
|
||||||
/* Load function pointer */
|
/* Load function pointer */
|
||||||
if (!(func_ptr =
|
if (!(func_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->func_ptrs,
|
func_ctx->func_ptrs, &func_idx, 1,
|
||||||
&func_idx, 1, "func_ptr_tmp"))) {
|
"func_ptr_tmp"))) {
|
||||||
aot_set_last_error("llvm build inbounds gep failed.");
|
aot_set_last_error("llvm build inbounds gep failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_ptr = LLVMBuildLoad(comp_ctx->builder, func_ptr, "func_ptr"))) {
|
if (!(func_ptr = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, func_ptr,
|
||||||
|
"func_ptr"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1584,9 +1602,9 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(value_ret = LLVMBuildCall(comp_ctx->builder, func, param_values,
|
if (!(value_ret = LLVMBuildCall2(comp_ctx->builder, llvm_func_type, func,
|
||||||
total_param_count,
|
param_values, total_param_count,
|
||||||
func_result_count > 0 ? "ret" : ""))) {
|
func_result_count > 0 ? "ret" : ""))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1603,10 +1621,11 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
/* Load extra result from its address and push to stack */
|
/* Load extra result from its address and push to stack */
|
||||||
for (i = 1; i < func_result_count; i++) {
|
for (i = 1; i < func_result_count; i++) {
|
||||||
|
ret_type = TO_LLVM_TYPE(func_type->types[func_param_count + i]);
|
||||||
snprintf(buf, sizeof(buf), "ext_ret%d", i - 1);
|
snprintf(buf, sizeof(buf), "ext_ret%d", i - 1);
|
||||||
if (!(ext_ret =
|
if (!(ext_ret = LLVMBuildLoad2(comp_ctx->builder, ret_type,
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
param_values[func_param_count + i],
|
||||||
param_values[func_param_count + i], buf))) {
|
buf))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,10 @@ get_memory_check_bound(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
if (func_ctx->mem_space_unchanged)
|
if (func_ctx->mem_space_unchanged)
|
||||||
return mem_check_bound;
|
return mem_check_bound;
|
||||||
|
|
||||||
if (!(mem_check_bound = LLVMBuildLoad(comp_ctx->builder, mem_check_bound,
|
if (!(mem_check_bound = LLVMBuildLoad2(
|
||||||
"mem_check_bound"))) {
|
comp_ctx->builder,
|
||||||
|
(comp_ctx->pointer_size == sizeof(uint64)) ? I64_TYPE : I32_TYPE,
|
||||||
|
mem_check_bound, "mem_check_bound"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -106,9 +108,9 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
mem_base_addr = func_ctx->mem_info[0].mem_base_addr;
|
mem_base_addr = func_ctx->mem_info[0].mem_base_addr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!(mem_base_addr = LLVMBuildLoad(comp_ctx->builder,
|
if (!(mem_base_addr = LLVMBuildLoad2(
|
||||||
func_ctx->mem_info[0].mem_base_addr,
|
comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
"mem_base"))) {
|
func_ctx->mem_info[0].mem_base_addr, "mem_base"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -147,8 +149,9 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
/* inside memory space */
|
/* inside memory space */
|
||||||
offset1 = I32_CONST((uint32)mem_offset);
|
offset1 = I32_CONST((uint32)mem_offset);
|
||||||
CHECK_LLVM_CONST(offset1);
|
CHECK_LLVM_CONST(offset1);
|
||||||
if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr,
|
if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset1, 1, "maddr"))) {
|
mem_base_addr, &offset1, 1,
|
||||||
|
"maddr"))) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -229,8 +232,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* maddr = mem_base_addr + offset1 */
|
/* maddr = mem_base_addr + offset1 */
|
||||||
if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr,
|
if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset1, 1, "maddr"))) {
|
mem_base_addr, &offset1, 1, "maddr"))) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -248,9 +251,10 @@ fail:
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define BUILD_LOAD() \
|
#define BUILD_LOAD(data_type) \
|
||||||
do { \
|
do { \
|
||||||
if (!(value = LLVMBuildLoad(comp_ctx->builder, maddr, "data"))) { \
|
if (!(value = LLVMBuildLoad2(comp_ctx->builder, data_type, maddr, \
|
||||||
|
"data"))) { \
|
||||||
aot_set_last_error("llvm build load failed."); \
|
aot_set_last_error("llvm build load failed."); \
|
||||||
goto fail; \
|
goto fail; \
|
||||||
} \
|
} \
|
||||||
|
@ -333,12 +337,13 @@ fail:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BUILD_ATOMIC_LOAD(align) \
|
#define BUILD_ATOMIC_LOAD(align, data_type) \
|
||||||
do { \
|
do { \
|
||||||
if (!(check_memory_alignment(comp_ctx, func_ctx, maddr, align))) { \
|
if (!(check_memory_alignment(comp_ctx, func_ctx, maddr, align))) { \
|
||||||
goto fail; \
|
goto fail; \
|
||||||
} \
|
} \
|
||||||
if (!(value = LLVMBuildLoad(comp_ctx->builder, maddr, "data"))) { \
|
if (!(value = LLVMBuildLoad2(comp_ctx->builder, data_type, maddr, \
|
||||||
|
"data"))) { \
|
||||||
aot_set_last_error("llvm build load failed."); \
|
aot_set_last_error("llvm build load failed."); \
|
||||||
goto fail; \
|
goto fail; \
|
||||||
} \
|
} \
|
||||||
|
@ -369,6 +374,7 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
bool atomic)
|
bool atomic)
|
||||||
{
|
{
|
||||||
LLVMValueRef maddr, value = NULL;
|
LLVMValueRef maddr, value = NULL;
|
||||||
|
LLVMTypeRef data_type;
|
||||||
|
|
||||||
if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
|
if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
|
||||||
return false;
|
return false;
|
||||||
|
@ -378,26 +384,31 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
BUILD_PTR_CAST(INT32_PTR_TYPE);
|
BUILD_PTR_CAST(INT32_PTR_TYPE);
|
||||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||||
if (atomic)
|
if (atomic)
|
||||||
BUILD_ATOMIC_LOAD(align);
|
BUILD_ATOMIC_LOAD(align, I32_TYPE);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
BUILD_LOAD();
|
BUILD_LOAD(I32_TYPE);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
case 1:
|
case 1:
|
||||||
if (bytes == 2)
|
if (bytes == 2) {
|
||||||
BUILD_PTR_CAST(INT16_PTR_TYPE);
|
BUILD_PTR_CAST(INT16_PTR_TYPE);
|
||||||
else
|
data_type = INT16_TYPE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
BUILD_PTR_CAST(INT8_PTR_TYPE);
|
BUILD_PTR_CAST(INT8_PTR_TYPE);
|
||||||
|
data_type = INT8_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||||
if (atomic) {
|
if (atomic) {
|
||||||
BUILD_ATOMIC_LOAD(align);
|
BUILD_ATOMIC_LOAD(align, data_type);
|
||||||
BUILD_ZERO_EXT(I32_TYPE);
|
BUILD_ZERO_EXT(I32_TYPE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
BUILD_LOAD();
|
BUILD_LOAD(data_type);
|
||||||
if (sign)
|
if (sign)
|
||||||
BUILD_SIGN_EXT(I32_TYPE);
|
BUILD_SIGN_EXT(I32_TYPE);
|
||||||
else
|
else
|
||||||
|
@ -410,6 +421,7 @@ aot_compile_op_i32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
PUSH_I32(value);
|
PUSH_I32(value);
|
||||||
|
(void)data_type;
|
||||||
return true;
|
return true;
|
||||||
fail:
|
fail:
|
||||||
return false;
|
return false;
|
||||||
|
@ -421,6 +433,7 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
bool atomic)
|
bool atomic)
|
||||||
{
|
{
|
||||||
LLVMValueRef maddr, value = NULL;
|
LLVMValueRef maddr, value = NULL;
|
||||||
|
LLVMTypeRef data_type;
|
||||||
|
|
||||||
if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
|
if (!(maddr = aot_check_memory_overflow(comp_ctx, func_ctx, offset, bytes)))
|
||||||
return false;
|
return false;
|
||||||
|
@ -430,29 +443,36 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
BUILD_PTR_CAST(INT64_PTR_TYPE);
|
BUILD_PTR_CAST(INT64_PTR_TYPE);
|
||||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||||
if (atomic)
|
if (atomic)
|
||||||
BUILD_ATOMIC_LOAD(align);
|
BUILD_ATOMIC_LOAD(align, I64_TYPE);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
BUILD_LOAD();
|
BUILD_LOAD(I64_TYPE);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
case 2:
|
case 2:
|
||||||
case 1:
|
case 1:
|
||||||
if (bytes == 4)
|
if (bytes == 4) {
|
||||||
BUILD_PTR_CAST(INT32_PTR_TYPE);
|
BUILD_PTR_CAST(INT32_PTR_TYPE);
|
||||||
else if (bytes == 2)
|
data_type = I32_TYPE;
|
||||||
|
}
|
||||||
|
else if (bytes == 2) {
|
||||||
BUILD_PTR_CAST(INT16_PTR_TYPE);
|
BUILD_PTR_CAST(INT16_PTR_TYPE);
|
||||||
else
|
data_type = INT16_TYPE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
BUILD_PTR_CAST(INT8_PTR_TYPE);
|
BUILD_PTR_CAST(INT8_PTR_TYPE);
|
||||||
|
data_type = INT8_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||||
if (atomic) {
|
if (atomic) {
|
||||||
BUILD_ATOMIC_LOAD(align);
|
BUILD_ATOMIC_LOAD(align, data_type);
|
||||||
BUILD_ZERO_EXT(I64_TYPE);
|
BUILD_ZERO_EXT(I64_TYPE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
BUILD_LOAD();
|
BUILD_LOAD(data_type);
|
||||||
if (sign)
|
if (sign)
|
||||||
BUILD_SIGN_EXT(I64_TYPE);
|
BUILD_SIGN_EXT(I64_TYPE);
|
||||||
else
|
else
|
||||||
|
@ -465,6 +485,7 @@ aot_compile_op_i64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
PUSH_I64(value);
|
PUSH_I64(value);
|
||||||
|
(void)data_type;
|
||||||
return true;
|
return true;
|
||||||
fail:
|
fail:
|
||||||
return false;
|
return false;
|
||||||
|
@ -480,7 +501,7 @@ aot_compile_op_f32_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BUILD_PTR_CAST(F32_PTR_TYPE);
|
BUILD_PTR_CAST(F32_PTR_TYPE);
|
||||||
BUILD_LOAD();
|
BUILD_LOAD(F32_TYPE);
|
||||||
PUSH_F32(value);
|
PUSH_F32(value);
|
||||||
return true;
|
return true;
|
||||||
fail:
|
fail:
|
||||||
|
@ -497,7 +518,7 @@ aot_compile_op_f64_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BUILD_PTR_CAST(F64_PTR_TYPE);
|
BUILD_PTR_CAST(F64_PTR_TYPE);
|
||||||
BUILD_LOAD();
|
BUILD_LOAD(F64_TYPE);
|
||||||
PUSH_F64(value);
|
PUSH_F64(value);
|
||||||
return true;
|
return true;
|
||||||
fail:
|
fail:
|
||||||
|
@ -631,8 +652,8 @@ get_memory_curr_page_count(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
mem_size = func_ctx->mem_info[0].mem_cur_page_count_addr;
|
mem_size = func_ctx->mem_info[0].mem_cur_page_count_addr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!(mem_size = LLVMBuildLoad(
|
if (!(mem_size = LLVMBuildLoad2(
|
||||||
comp_ctx->builder,
|
comp_ctx->builder, I32_TYPE,
|
||||||
func_ctx->mem_info[0].mem_cur_page_count_addr, "mem_size"))) {
|
func_ctx->mem_info[0].mem_cur_page_count_addr, "mem_size"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -720,8 +741,8 @@ aot_compile_op_memory_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
/* Call function aot_enlarge_memory() */
|
/* Call function aot_enlarge_memory() */
|
||||||
param_values[0] = func_ctx->aot_inst;
|
param_values[0] = func_ctx->aot_inst;
|
||||||
param_values[1] = delta;
|
param_values[1] = delta;
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 2,
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call"))) {
|
param_values, 2, "call"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -765,9 +786,9 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
mem_base_addr = func_ctx->mem_info[0].mem_base_addr;
|
mem_base_addr = func_ctx->mem_info[0].mem_base_addr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!(mem_base_addr = LLVMBuildLoad(comp_ctx->builder,
|
if (!(mem_base_addr = LLVMBuildLoad2(
|
||||||
func_ctx->mem_info[0].mem_base_addr,
|
comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
"mem_base"))) {
|
func_ctx->mem_info[0].mem_base_addr, "mem_base"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -793,8 +814,9 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
if (mem_data_size > 0 && mem_offset + mem_len <= mem_data_size) {
|
if (mem_data_size > 0 && mem_offset + mem_len <= mem_data_size) {
|
||||||
/* inside memory space */
|
/* inside memory space */
|
||||||
/* maddr = mem_base_addr + moffset */
|
/* maddr = mem_base_addr + moffset */
|
||||||
if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr,
|
if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "maddr"))) {
|
mem_base_addr, &offset, 1,
|
||||||
|
"maddr"))) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -806,9 +828,9 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
mem_size = func_ctx->mem_info[0].mem_data_size_addr;
|
mem_size = func_ctx->mem_info[0].mem_data_size_addr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!(mem_size = LLVMBuildLoad(comp_ctx->builder,
|
if (!(mem_size = LLVMBuildLoad2(
|
||||||
func_ctx->mem_info[0].mem_data_size_addr,
|
comp_ctx->builder, I32_TYPE,
|
||||||
"mem_size"))) {
|
func_ctx->mem_info[0].mem_data_size_addr, "mem_size"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -832,8 +854,8 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* maddr = mem_base_addr + offset */
|
/* maddr = mem_base_addr + offset */
|
||||||
if (!(maddr = LLVMBuildInBoundsGEP(comp_ctx->builder, mem_base_addr,
|
if (!(maddr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "maddr"))) {
|
mem_base_addr, &offset, 1, "maddr"))) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -873,8 +895,8 @@ aot_compile_op_memory_init(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
param_values[2] = offset;
|
param_values[2] = offset;
|
||||||
param_values[3] = len;
|
param_values[3] = len;
|
||||||
param_values[4] = dst;
|
param_values[4] = dst;
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 5,
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call"))) {
|
param_values, 5, "call"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -926,8 +948,8 @@ aot_compile_op_data_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
/* Call function aot_data_drop() */
|
/* Call function aot_data_drop() */
|
||||||
param_values[0] = func_ctx->aot_inst;
|
param_values[0] = func_ctx->aot_inst;
|
||||||
param_values[1] = seg;
|
param_values[1] = seg;
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 2,
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call"))) {
|
param_values, 2, "call"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1001,8 +1023,8 @@ aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
params[0] = dst_addr;
|
params[0] = dst_addr;
|
||||||
params[1] = src_addr;
|
params[1] = src_addr;
|
||||||
params[2] = len;
|
params[2] = len;
|
||||||
if (!(res = LLVMBuildCall(comp_ctx->builder, func, params, 3,
|
if (!(res = LLVMBuildCall2(comp_ctx->builder, func_type, func, params,
|
||||||
"call_memmove"))) {
|
3, "call_memmove"))) {
|
||||||
aot_set_last_error("llvm build memmove failed.");
|
aot_set_last_error("llvm build memmove failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1079,8 +1101,8 @@ aot_compile_op_memory_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
params[0] = dst_addr;
|
params[0] = dst_addr;
|
||||||
params[1] = val;
|
params[1] = val;
|
||||||
params[2] = len;
|
params[2] = len;
|
||||||
if (!(res = LLVMBuildCall(comp_ctx->builder, func, params, 3,
|
if (!(res = LLVMBuildCall2(comp_ctx->builder, func_type, func, params, 3,
|
||||||
"call_memset"))) {
|
"call_memset"))) {
|
||||||
aot_set_last_error("llvm build memset failed.");
|
aot_set_last_error("llvm build memset failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1297,8 +1319,8 @@ aot_compile_op_atomic_wait(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
param_values[2] = expect;
|
param_values[2] = expect;
|
||||||
param_values[3] = timeout;
|
param_values[3] = timeout;
|
||||||
param_values[4] = is_wait64;
|
param_values[4] = is_wait64;
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 5,
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call"))) {
|
param_values, 5, "call"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1360,8 +1382,8 @@ aot_compiler_op_atomic_notify(AOTCompContext *comp_ctx,
|
||||||
param_values[0] = func_ctx->aot_inst;
|
param_values[0] = func_ctx->aot_inst;
|
||||||
param_values[1] = maddr;
|
param_values[1] = maddr;
|
||||||
param_values[2] = count;
|
param_values[2] = count;
|
||||||
if (!(ret_value = LLVMBuildCall(comp_ctx->builder, func, param_values, 3,
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
"call"))) {
|
param_values, 3, "call"))) {
|
||||||
aot_set_last_error("llvm build call failed.");
|
aot_set_last_error("llvm build call failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,10 @@ aot_compile_get_tbl_inst(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tbl_inst = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst,
|
if (!(tbl_inst = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "tbl_inst"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
HANDLE_FAILURE("LLVMBuildGEP");
|
"tbl_inst"))) {
|
||||||
|
HANDLE_FAILURE("LLVMBuildInBoundsGEP");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +91,8 @@ aot_compile_op_elem_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* "" means return void */
|
/* "" means return void */
|
||||||
if (!(ret_value =
|
if (!(ret_value = LLVMBuildCall2(comp_ctx->builder, func_type, func,
|
||||||
LLVMBuildCall(comp_ctx->builder, func, param_values, 2, ""))) {
|
param_values, 2, ""))) {
|
||||||
HANDLE_FAILURE("LLVMBuildCall");
|
HANDLE_FAILURE("LLVMBuildCall");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -115,9 +116,10 @@ aot_check_table_access(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tbl_sz = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst, &offset,
|
if (!(tbl_sz = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
1, "cur_size_i8p"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
HANDLE_FAILURE("LLVMBuildGEP");
|
"cur_size_i8p"))) {
|
||||||
|
HANDLE_FAILURE("LLVMBuildInBoundsGEP");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +129,8 @@ aot_check_table_access(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tbl_sz = LLVMBuildLoad(comp_ctx->builder, tbl_sz, "cur_size"))) {
|
if (!(tbl_sz = LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, tbl_sz,
|
||||||
|
"cur_size"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildLoad");
|
HANDLE_FAILURE("LLVMBuildLoad");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -178,8 +181,9 @@ aot_compile_op_table_get(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst,
|
if (!(table_elem = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "table_elem_i8p"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
|
"table_elem_i8p"))) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -191,14 +195,15 @@ aot_compile_op_table_get(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load function index */
|
/* Load function index */
|
||||||
if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, table_elem, &elem_idx, 1,
|
if (!(table_elem =
|
||||||
"table_elem"))) {
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE, table_elem,
|
||||||
|
&elem_idx, 1, "table_elem"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildNUWAdd");
|
HANDLE_FAILURE("LLVMBuildNUWAdd");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_idx =
|
if (!(func_idx = LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, table_elem,
|
||||||
LLVMBuildLoad(comp_ctx->builder, table_elem, "func_idx"))) {
|
"func_idx"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildLoad");
|
HANDLE_FAILURE("LLVMBuildLoad");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -230,9 +235,10 @@ aot_compile_op_table_set(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst,
|
if (!(table_elem = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "table_elem_i8p"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
HANDLE_FAILURE("LLVMBuildGEP");
|
"table_elem_i8p"))) {
|
||||||
|
HANDLE_FAILURE("LLVMBuildInBoundsGEP");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,9 +249,10 @@ aot_compile_op_table_set(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load function index */
|
/* Load function index */
|
||||||
if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, table_elem, &elem_idx, 1,
|
if (!(table_elem =
|
||||||
"table_elem"))) {
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, I32_TYPE, table_elem,
|
||||||
HANDLE_FAILURE("LLVMBuildGEP");
|
&elem_idx, 1, "table_elem"))) {
|
||||||
|
HANDLE_FAILURE("LLVMBuildInBoundsGEP");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +304,8 @@ aot_compile_op_table_init(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
POP_I32(param_values[5]);
|
POP_I32(param_values[5]);
|
||||||
|
|
||||||
/* "" means return void */
|
/* "" means return void */
|
||||||
if (!(LLVMBuildCall(comp_ctx->builder, func, param_values, 6, ""))) {
|
if (!(LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 6,
|
||||||
|
""))) {
|
||||||
HANDLE_FAILURE("LLVMBuildCall");
|
HANDLE_FAILURE("LLVMBuildCall");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -344,7 +352,8 @@ aot_compile_op_table_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
POP_I32(param_values[5]);
|
POP_I32(param_values[5]);
|
||||||
|
|
||||||
/* "" means return void */
|
/* "" means return void */
|
||||||
if (!(LLVMBuildCall(comp_ctx->builder, func, param_values, 6, ""))) {
|
if (!(LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 6,
|
||||||
|
""))) {
|
||||||
HANDLE_FAILURE("LLVMBuildCall");
|
HANDLE_FAILURE("LLVMBuildCall");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -366,9 +375,10 @@ aot_compile_op_table_size(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tbl_sz = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst, &offset,
|
if (!(tbl_sz = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
1, "tbl_sz_ptr_i8"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
HANDLE_FAILURE("LLVMBuildGEP");
|
"tbl_sz_ptr_i8"))) {
|
||||||
|
HANDLE_FAILURE("LLVMBuildInBoundsGEP");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +388,8 @@ aot_compile_op_table_size(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(tbl_sz = LLVMBuildLoad(comp_ctx->builder, tbl_sz, "tbl_sz"))) {
|
if (!(tbl_sz =
|
||||||
|
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, tbl_sz, "tbl_sz"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildLoad");
|
HANDLE_FAILURE("LLVMBuildLoad");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -417,8 +428,8 @@ aot_compile_op_table_grow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
/* v */
|
/* v */
|
||||||
POP_I32(param_values[3]);
|
POP_I32(param_values[3]);
|
||||||
|
|
||||||
if (!(ret = LLVMBuildCall(comp_ctx->builder, func, param_values, 4,
|
if (!(ret = LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values,
|
||||||
"table_grow"))) {
|
4, "table_grow"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildCall");
|
HANDLE_FAILURE("LLVMBuildCall");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +472,8 @@ aot_compile_op_table_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
POP_I32(param_values[4]);
|
POP_I32(param_values[4]);
|
||||||
|
|
||||||
/* "" means return void */
|
/* "" means return void */
|
||||||
if (!(LLVMBuildCall(comp_ctx->builder, func, param_values, 5, ""))) {
|
if (!(LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values, 5,
|
||||||
|
""))) {
|
||||||
HANDLE_FAILURE("LLVMBuildCall");
|
HANDLE_FAILURE("LLVMBuildCall");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,17 +33,20 @@ aot_compile_op_get_local(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
char name[32];
|
char name[32];
|
||||||
LLVMValueRef value;
|
LLVMValueRef value;
|
||||||
AOTValue *aot_value_top;
|
AOTValue *aot_value_top;
|
||||||
|
uint8 local_type;
|
||||||
|
|
||||||
CHECK_LOCAL(local_idx);
|
CHECK_LOCAL(local_idx);
|
||||||
|
|
||||||
|
local_type = get_local_type(func_ctx, local_idx);
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "%s%d%s", "local", local_idx, "#");
|
snprintf(name, sizeof(name), "%s%d%s", "local", local_idx, "#");
|
||||||
if (!(value = LLVMBuildLoad(comp_ctx->builder, func_ctx->locals[local_idx],
|
if (!(value = LLVMBuildLoad2(comp_ctx->builder, TO_LLVM_TYPE(local_type),
|
||||||
name))) {
|
func_ctx->locals[local_idx], name))) {
|
||||||
aot_set_last_error("llvm build load fail");
|
aot_set_last_error("llvm build load fail");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUSH(value, get_local_type(func_ctx, local_idx));
|
PUSH(value, local_type);
|
||||||
|
|
||||||
aot_value_top =
|
aot_value_top =
|
||||||
func_ctx->block_stack.block_list_end->value_stack.value_list_end;
|
func_ctx->block_stack.block_list_end->value_stack.value_list_end;
|
||||||
|
@ -134,9 +137,9 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = I32_CONST(global_offset);
|
offset = I32_CONST(global_offset);
|
||||||
if (!(global_ptr =
|
if (!(global_ptr = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->aot_inst,
|
func_ctx->aot_inst, &offset, 1,
|
||||||
&offset, 1, "global_ptr_tmp"))) {
|
"global_ptr_tmp"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed.");
|
aot_set_last_error("llvm build in bounds gep failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +175,8 @@ compile_global(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
if (!is_set) {
|
if (!is_set) {
|
||||||
if (!(global =
|
if (!(global =
|
||||||
LLVMBuildLoad(comp_ctx->builder, global_ptr, "global"))) {
|
LLVMBuildLoad2(comp_ctx->builder, TO_LLVM_TYPE(global_type),
|
||||||
|
global_ptr, "global"))) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,9 +232,9 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* aot_inst->memories */
|
/* aot_inst->memories */
|
||||||
if (!(shared_mem_addr =
|
if (!(shared_mem_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->aot_inst,
|
comp_ctx->builder, INT8_TYPE, func_ctx->aot_inst, &offset, 1,
|
||||||
&offset, 1, "shared_mem_addr_offset"))) {
|
"shared_mem_addr_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -245,8 +245,9 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* aot_inst->memories[0] */
|
/* aot_inst->memories[0] */
|
||||||
if (!(shared_mem_addr = LLVMBuildLoad(
|
if (!(shared_mem_addr =
|
||||||
comp_ctx->builder, shared_mem_addr, "shared_mem_addr"))) {
|
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
|
shared_mem_addr, "shared_mem_addr"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -256,29 +257,34 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
aot_set_last_error("llvm build bit cast failed");
|
aot_set_last_error("llvm build bit cast failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(shared_mem_addr = LLVMBuildLoad(
|
if (!(shared_mem_addr =
|
||||||
comp_ctx->builder, shared_mem_addr, "shared_mem_addr"))) {
|
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
|
shared_mem_addr, "shared_mem_addr"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* memories[0]->memory_data */
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, memory_data.ptr));
|
offset = I32_CONST(offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_base_addr =
|
if (!(func_ctx->mem_info[0].mem_base_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, shared_mem_addr,
|
comp_ctx->builder, INT8_TYPE, shared_mem_addr, &offset, 1,
|
||||||
&offset, 1, "mem_base_addr_offset"))) {
|
"mem_base_addr_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* memories[0]->cur_page_count */
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, cur_page_count));
|
offset = I32_CONST(offsetof(AOTMemoryInstance, cur_page_count));
|
||||||
if (!(func_ctx->mem_info[0].mem_cur_page_count_addr =
|
if (!(func_ctx->mem_info[0].mem_cur_page_count_addr =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, shared_mem_addr,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "mem_cur_page_offset"))) {
|
shared_mem_addr, &offset, 1,
|
||||||
|
"mem_cur_page_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/* memories[0]->memory_data_size */
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, memory_data_size));
|
offset = I32_CONST(offsetof(AOTMemoryInstance, memory_data_size));
|
||||||
if (!(func_ctx->mem_info[0].mem_data_size_addr =
|
if (!(func_ctx->mem_info[0].mem_data_size_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, shared_mem_addr,
|
comp_ctx->builder, INT8_TYPE, shared_mem_addr, &offset, 1,
|
||||||
&offset, 1, "mem_data_size_offset"))) {
|
"mem_data_size_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -288,25 +294,26 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
{
|
{
|
||||||
offset = I32_CONST(offsetof(AOTModuleInstance, global_table_data)
|
offset = I32_CONST(offsetof(AOTModuleInstance, global_table_data)
|
||||||
+ offsetof(AOTMemoryInstance, memory_data.ptr));
|
+ offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_base_addr =
|
if (!(func_ctx->mem_info[0].mem_base_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->aot_inst,
|
comp_ctx->builder, INT8_TYPE, func_ctx->aot_inst, &offset, 1,
|
||||||
&offset, 1, "mem_base_addr_offset"))) {
|
"mem_base_addr_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
offset = I32_CONST(offsetof(AOTModuleInstance, global_table_data)
|
offset = I32_CONST(offsetof(AOTModuleInstance, global_table_data)
|
||||||
+ offsetof(AOTMemoryInstance, cur_page_count));
|
+ offsetof(AOTMemoryInstance, cur_page_count));
|
||||||
if (!(func_ctx->mem_info[0].mem_cur_page_count_addr =
|
if (!(func_ctx->mem_info[0].mem_cur_page_count_addr =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->aot_inst,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE,
|
||||||
&offset, 1, "mem_cur_page_offset"))) {
|
func_ctx->aot_inst, &offset, 1,
|
||||||
|
"mem_cur_page_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
offset = I32_CONST(offsetof(AOTModuleInstance, global_table_data)
|
offset = I32_CONST(offsetof(AOTModuleInstance, global_table_data)
|
||||||
+ offsetof(AOTMemoryInstance, memory_data_size));
|
+ offsetof(AOTMemoryInstance, memory_data_size));
|
||||||
if (!(func_ctx->mem_info[0].mem_data_size_addr =
|
if (!(func_ctx->mem_info[0].mem_data_size_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->aot_inst,
|
comp_ctx->builder, INT8_TYPE, func_ctx->aot_inst, &offset, 1,
|
||||||
&offset, 1, "mem_data_size_offset"))) {
|
"mem_data_size_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -333,22 +340,22 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mem_space_unchanged) {
|
if (mem_space_unchanged) {
|
||||||
if (!(func_ctx->mem_info[0].mem_base_addr = LLVMBuildLoad(
|
if (!(func_ctx->mem_info[0].mem_base_addr = LLVMBuildLoad2(
|
||||||
comp_ctx->builder, func_ctx->mem_info[0].mem_base_addr,
|
comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
"mem_base_addr"))) {
|
func_ctx->mem_info[0].mem_base_addr, "mem_base_addr"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(func_ctx->mem_info[0].mem_cur_page_count_addr =
|
if (!(func_ctx->mem_info[0].mem_cur_page_count_addr =
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE,
|
||||||
func_ctx->mem_info[0].mem_cur_page_count_addr,
|
func_ctx->mem_info[0].mem_cur_page_count_addr,
|
||||||
"mem_cur_page_count"))) {
|
"mem_cur_page_count"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(func_ctx->mem_info[0].mem_data_size_addr = LLVMBuildLoad(
|
if (!(func_ctx->mem_info[0].mem_data_size_addr = LLVMBuildLoad2(
|
||||||
comp_ctx->builder, func_ctx->mem_info[0].mem_data_size_addr,
|
comp_ctx->builder, I32_TYPE,
|
||||||
"mem_data_size"))) {
|
func_ctx->mem_info[0].mem_data_size_addr, "mem_data_size"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -357,9 +364,9 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
else if (is_shared_memory) {
|
else if (is_shared_memory) {
|
||||||
/* The base address for shared memory will never changed,
|
/* The base address for shared memory will never changed,
|
||||||
we can load the value here */
|
we can load the value here */
|
||||||
if (!(func_ctx->mem_info[0].mem_base_addr = LLVMBuildLoad(
|
if (!(func_ctx->mem_info[0].mem_base_addr = LLVMBuildLoad2(
|
||||||
comp_ctx->builder, func_ctx->mem_info[0].mem_base_addr,
|
comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
"mem_base_addr"))) {
|
func_ctx->mem_info[0].mem_base_addr, "mem_base_addr"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -374,8 +381,8 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_1byte)
|
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_1byte)
|
||||||
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_1byte =
|
if (!(func_ctx->mem_info[0].mem_bound_check_1byte =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, mem_info_base, &offset, 1,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, mem_info_base,
|
||||||
"bound_check_1byte_offset"))) {
|
&offset, 1, "bound_check_1byte_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -386,10 +393,12 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mem_space_unchanged) {
|
if (mem_space_unchanged) {
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_1byte =
|
if (!(func_ctx->mem_info[0].mem_bound_check_1byte = LLVMBuildLoad2(
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
comp_ctx->builder,
|
||||||
func_ctx->mem_info[0].mem_bound_check_1byte,
|
(comp_ctx->pointer_size == sizeof(uint64)) ? I64_TYPE
|
||||||
"bound_check_1byte"))) {
|
: I32_TYPE,
|
||||||
|
func_ctx->mem_info[0].mem_bound_check_1byte,
|
||||||
|
"bound_check_1byte"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -398,8 +407,8 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_2bytes)
|
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_2bytes)
|
||||||
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_2bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_2bytes =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, mem_info_base, &offset, 1,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, mem_info_base,
|
||||||
"bound_check_2bytes_offset"))) {
|
&offset, 1, "bound_check_2bytes_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -410,10 +419,12 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mem_space_unchanged) {
|
if (mem_space_unchanged) {
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_2bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_2bytes = LLVMBuildLoad2(
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
comp_ctx->builder,
|
||||||
func_ctx->mem_info[0].mem_bound_check_2bytes,
|
(comp_ctx->pointer_size == sizeof(uint64)) ? I64_TYPE
|
||||||
"bound_check_2bytes"))) {
|
: I32_TYPE,
|
||||||
|
func_ctx->mem_info[0].mem_bound_check_2bytes,
|
||||||
|
"bound_check_2bytes"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -422,8 +433,8 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_4bytes)
|
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_4bytes)
|
||||||
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_4bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_4bytes =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, mem_info_base, &offset, 1,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, mem_info_base,
|
||||||
"bound_check_4bytes_offset"))) {
|
&offset, 1, "bound_check_4bytes_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -434,10 +445,12 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mem_space_unchanged) {
|
if (mem_space_unchanged) {
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_4bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_4bytes = LLVMBuildLoad2(
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
comp_ctx->builder,
|
||||||
func_ctx->mem_info[0].mem_bound_check_4bytes,
|
(comp_ctx->pointer_size == sizeof(uint64)) ? I64_TYPE
|
||||||
"bound_check_4bytes"))) {
|
: I32_TYPE,
|
||||||
|
func_ctx->mem_info[0].mem_bound_check_4bytes,
|
||||||
|
"bound_check_4bytes"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -446,8 +459,8 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_8bytes)
|
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_8bytes)
|
||||||
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_8bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_8bytes =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, mem_info_base, &offset, 1,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, mem_info_base,
|
||||||
"bound_check_8bytes_offset"))) {
|
&offset, 1, "bound_check_8bytes_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -458,10 +471,12 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mem_space_unchanged) {
|
if (mem_space_unchanged) {
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_8bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_8bytes = LLVMBuildLoad2(
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
comp_ctx->builder,
|
||||||
func_ctx->mem_info[0].mem_bound_check_8bytes,
|
(comp_ctx->pointer_size == sizeof(uint64)) ? I64_TYPE
|
||||||
"bound_check_8bytes"))) {
|
: I32_TYPE,
|
||||||
|
func_ctx->mem_info[0].mem_bound_check_8bytes,
|
||||||
|
"bound_check_8bytes"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -469,9 +484,9 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_16bytes)
|
offset = I32_CONST(offsetof(AOTMemoryInstance, mem_bound_check_16bytes)
|
||||||
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
- offsetof(AOTMemoryInstance, memory_data.ptr));
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_16bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_16bytes = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, mem_info_base, &offset, 1,
|
comp_ctx->builder, INT8_TYPE, mem_info_base, &offset, 1,
|
||||||
"bound_check_16bytes_offset"))) {
|
"bound_check_16bytes_offset"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -482,10 +497,12 @@ create_memory_info(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mem_space_unchanged) {
|
if (mem_space_unchanged) {
|
||||||
if (!(func_ctx->mem_info[0].mem_bound_check_16bytes =
|
if (!(func_ctx->mem_info[0].mem_bound_check_16bytes = LLVMBuildLoad2(
|
||||||
LLVMBuildLoad(comp_ctx->builder,
|
comp_ctx->builder,
|
||||||
func_ctx->mem_info[0].mem_bound_check_16bytes,
|
(comp_ctx->pointer_size == sizeof(uint64)) ? I64_TYPE
|
||||||
"bound_check_16bytes"))) {
|
: I32_TYPE,
|
||||||
|
func_ctx->mem_info[0].mem_bound_check_16bytes,
|
||||||
|
"bound_check_16bytes"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -500,8 +517,9 @@ create_cur_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
LLVMValueRef offset;
|
LLVMValueRef offset;
|
||||||
|
|
||||||
offset = I32_CONST(offsetof(AOTModuleInstance, cur_exception));
|
offset = I32_CONST(offsetof(AOTModuleInstance, cur_exception));
|
||||||
func_ctx->cur_exception = LLVMBuildInBoundsGEP(
|
func_ctx->cur_exception =
|
||||||
comp_ctx->builder, func_ctx->aot_inst, &offset, 1, "cur_exception");
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, func_ctx->aot_inst,
|
||||||
|
&offset, 1, "cur_exception");
|
||||||
if (!func_ctx->cur_exception) {
|
if (!func_ctx->cur_exception) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed.");
|
aot_set_last_error("llvm build in bounds gep failed.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -517,8 +535,8 @@ create_func_type_indexes(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
|
|
||||||
offset = I32_CONST(offsetof(AOTModuleInstance, func_type_indexes.ptr));
|
offset = I32_CONST(offsetof(AOTModuleInstance, func_type_indexes.ptr));
|
||||||
func_type_indexes_ptr =
|
func_type_indexes_ptr =
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->aot_inst, &offset, 1,
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, func_ctx->aot_inst,
|
||||||
"func_type_indexes_ptr");
|
&offset, 1, "func_type_indexes_ptr");
|
||||||
if (!func_type_indexes_ptr) {
|
if (!func_type_indexes_ptr) {
|
||||||
aot_set_last_error("llvm build add failed.");
|
aot_set_last_error("llvm build add failed.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -537,8 +555,9 @@ create_func_type_indexes(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
func_ctx->func_type_indexes = LLVMBuildLoad(
|
func_ctx->func_type_indexes =
|
||||||
comp_ctx->builder, func_ctx->func_type_indexes, "func_type_indexes");
|
LLVMBuildLoad2(comp_ctx->builder, INT32_PTR_TYPE,
|
||||||
|
func_ctx->func_type_indexes, "func_type_indexes");
|
||||||
if (!func_ctx->func_type_indexes) {
|
if (!func_ctx->func_type_indexes) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -552,8 +571,9 @@ create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
LLVMValueRef offset;
|
LLVMValueRef offset;
|
||||||
|
|
||||||
offset = I32_CONST(offsetof(AOTModuleInstance, func_ptrs));
|
offset = I32_CONST(offsetof(AOTModuleInstance, func_ptrs));
|
||||||
func_ctx->func_ptrs = LLVMBuildInBoundsGEP(
|
func_ctx->func_ptrs =
|
||||||
comp_ctx->builder, func_ctx->aot_inst, &offset, 1, "func_ptrs_offset");
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, func_ctx->aot_inst,
|
||||||
|
&offset, 1, "func_ptrs_offset");
|
||||||
if (!func_ctx->func_ptrs) {
|
if (!func_ctx->func_ptrs) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed.");
|
aot_set_last_error("llvm build in bounds gep failed.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -566,8 +586,8 @@ create_func_ptrs(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
func_ctx->func_ptrs =
|
func_ctx->func_ptrs = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
LLVMBuildLoad(comp_ctx->builder, func_ctx->func_ptrs, "func_ptrs_ptr");
|
func_ctx->func_ptrs, "func_ptrs_ptr");
|
||||||
if (!func_ctx->func_ptrs) {
|
if (!func_ctx->func_ptrs) {
|
||||||
aot_set_last_error("llvm build load failed.");
|
aot_set_last_error("llvm build load failed.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -648,24 +668,24 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||||
|
|
||||||
/* Get aot inst address, the layout of exec_env is:
|
/* Get aot inst address, the layout of exec_env is:
|
||||||
exec_env->next, exec_env->prev, exec_env->module_inst, and argv_buf */
|
exec_env->next, exec_env->prev, exec_env->module_inst, and argv_buf */
|
||||||
if (!(aot_inst_addr =
|
if (!(aot_inst_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->exec_env,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
|
||||||
&aot_inst_offset, 1, "aot_inst_addr"))) {
|
&aot_inst_offset, 1, "aot_inst_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load aot inst */
|
/* Load aot inst */
|
||||||
if (!(func_ctx->aot_inst =
|
if (!(func_ctx->aot_inst = LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
LLVMBuildLoad(comp_ctx->builder, aot_inst_addr, "aot_inst"))) {
|
aot_inst_addr, "aot_inst"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get argv buffer address */
|
/* Get argv buffer address */
|
||||||
if (!(argv_buf_addr =
|
if (!(argv_buf_addr = LLVMBuildInBoundsGEP2(
|
||||||
LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->exec_env,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
|
||||||
&argv_buf_offset, 1, "argv_buf_addr"))) {
|
&argv_buf_offset, 1, "argv_buf_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -682,30 +702,31 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_ctx->argv_buf =
|
if (!(func_ctx->argv_buf = LLVMBuildLoad2(comp_ctx->builder, INT32_PTR_TYPE,
|
||||||
LLVMBuildLoad(comp_ctx->builder, argv_buf_addr, "argv_buf"))) {
|
argv_buf_addr, "argv_buf"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get native stack boundary address */
|
/* Get native stack boundary address */
|
||||||
if (!(stack_bound_addr = LLVMBuildInBoundsGEP(
|
if (!(stack_bound_addr = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->exec_env, &stack_bound_offset, 1,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
|
||||||
"stack_bound_addr"))) {
|
&stack_bound_offset, 1, "stack_bound_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_ctx->native_stack_bound = LLVMBuildLoad(
|
if (!(func_ctx->native_stack_bound =
|
||||||
comp_ctx->builder, stack_bound_addr, "native_stack_bound"))) {
|
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, stack_bound_addr,
|
||||||
|
"native_stack_bound"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get aux stack boundary address */
|
/* Get aux stack boundary address */
|
||||||
if (!(aux_stack_bound_addr = LLVMBuildInBoundsGEP(
|
if (!(aux_stack_bound_addr = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->exec_env, &aux_stack_bound_offset, 1,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
|
||||||
"aux_stack_bound_addr"))) {
|
&aux_stack_bound_offset, 1, "aux_stack_bound_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -717,16 +738,17 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_ctx->aux_stack_bound = LLVMBuildLoad(
|
if (!(func_ctx->aux_stack_bound =
|
||||||
comp_ctx->builder, aux_stack_bound_addr, "aux_stack_bound"))) {
|
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, aux_stack_bound_addr,
|
||||||
|
"aux_stack_bound"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get aux stack bottom address */
|
/* Get aux stack bottom address */
|
||||||
if (!(aux_stack_bottom_addr = LLVMBuildInBoundsGEP(
|
if (!(aux_stack_bottom_addr = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->exec_env, &aux_stack_bottom_offset,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
|
||||||
1, "aux_stack_bottom_addr"))) {
|
&aux_stack_bottom_offset, 1, "aux_stack_bottom_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -737,21 +759,23 @@ aot_create_func_context(AOTCompData *comp_data, AOTCompContext *comp_ctx,
|
||||||
aot_set_last_error("llvm build bit cast failed");
|
aot_set_last_error("llvm build bit cast failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (!(func_ctx->aux_stack_bottom = LLVMBuildLoad(
|
if (!(func_ctx->aux_stack_bottom =
|
||||||
comp_ctx->builder, aux_stack_bottom_addr, "aux_stack_bottom"))) {
|
LLVMBuildLoad2(comp_ctx->builder, I32_TYPE, aux_stack_bottom_addr,
|
||||||
|
"aux_stack_bottom"))) {
|
||||||
aot_set_last_error("llvm build load failed");
|
aot_set_last_error("llvm build load failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(native_symbol_addr = LLVMBuildInBoundsGEP(
|
if (!(native_symbol_addr = LLVMBuildInBoundsGEP2(
|
||||||
comp_ctx->builder, func_ctx->exec_env, &native_symbol_offset, 1,
|
comp_ctx->builder, OPQ_PTR_TYPE, func_ctx->exec_env,
|
||||||
"native_symbol_addr"))) {
|
&native_symbol_offset, 1, "native_symbol_addr"))) {
|
||||||
aot_set_last_error("llvm build in bounds gep failed");
|
aot_set_last_error("llvm build in bounds gep failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_ctx->native_symbol = LLVMBuildLoad(
|
if (!(func_ctx->native_symbol =
|
||||||
comp_ctx->builder, native_symbol_addr, "native_symbol_tmp"))) {
|
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE,
|
||||||
|
native_symbol_addr, "native_symbol_tmp"))) {
|
||||||
aot_set_last_error("llvm build bit cast failed");
|
aot_set_last_error("llvm build bit cast failed");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -2581,9 +2605,14 @@ __call_llvm_intrinsic(const AOTCompContext *comp_ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR >= 14
|
||||||
|
func_type =
|
||||||
|
LLVMFunctionType(ret_type, param_types, (uint32)param_count, false);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Call the LLVM intrinsic function */
|
/* Call the LLVM intrinsic function */
|
||||||
if (!(ret = LLVMBuildCall(comp_ctx->builder, func, param_values,
|
if (!(ret = LLVMBuildCall2(comp_ctx->builder, func_type, func, param_values,
|
||||||
(uint32)param_count, "call"))) {
|
(uint32)param_count, "call"))) {
|
||||||
aot_set_last_error("llvm build intrinsic call failed.");
|
aot_set_last_error("llvm build intrinsic call failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2666,13 +2695,15 @@ aot_get_func_from_table(const AOTCompContext *comp_ctx, LLVMValueRef base,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(func_addr = LLVMBuildInBoundsGEP(comp_ctx->builder, base, &func_addr,
|
if (!(func_addr =
|
||||||
1, "func_addr"))) {
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE, base,
|
||||||
|
&func_addr, 1, "func_addr"))) {
|
||||||
aot_set_last_error("get function addr by index failed.");
|
aot_set_last_error("get function addr by index failed.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
func = LLVMBuildLoad(comp_ctx->builder, func_addr, "func_tmp");
|
func =
|
||||||
|
LLVMBuildLoad2(comp_ctx->builder, OPQ_PTR_TYPE, func_addr, "func_tmp");
|
||||||
|
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
aot_set_last_error("get function pointer failed.");
|
aot_set_last_error("get function pointer failed.");
|
||||||
|
@ -2695,7 +2726,7 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
|
||||||
const WASMValue *value, uint8 value_type)
|
const WASMValue *value, uint8 value_type)
|
||||||
{
|
{
|
||||||
LLVMValueRef const_index, const_addr, const_value;
|
LLVMValueRef const_index, const_addr, const_value;
|
||||||
LLVMTypeRef const_ptr_type;
|
LLVMTypeRef const_ptr_type, const_type;
|
||||||
char buf[128] = { 0 };
|
char buf[128] = { 0 };
|
||||||
int32 index;
|
int32 index;
|
||||||
|
|
||||||
|
@ -2704,11 +2735,13 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
|
||||||
/* Store the raw int bits of f32 const as a hex string */
|
/* Store the raw int bits of f32 const as a hex string */
|
||||||
snprintf(buf, sizeof(buf), "f32#%08" PRIX32, value->i32);
|
snprintf(buf, sizeof(buf), "f32#%08" PRIX32, value->i32);
|
||||||
const_ptr_type = F32_PTR_TYPE;
|
const_ptr_type = F32_PTR_TYPE;
|
||||||
|
const_type = F32_TYPE;
|
||||||
break;
|
break;
|
||||||
case VALUE_TYPE_F64:
|
case VALUE_TYPE_F64:
|
||||||
/* Store the raw int bits of f64 const as a hex string */
|
/* Store the raw int bits of f64 const as a hex string */
|
||||||
snprintf(buf, sizeof(buf), "f64#%016" PRIX64, value->i64);
|
snprintf(buf, sizeof(buf), "f64#%016" PRIX64, value->i64);
|
||||||
const_ptr_type = F64_PTR_TYPE;
|
const_ptr_type = F64_PTR_TYPE;
|
||||||
|
const_type = F64_TYPE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bh_assert(0);
|
bh_assert(0);
|
||||||
|
@ -2727,8 +2760,9 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(const_addr = LLVMBuildInBoundsGEP(
|
if (!(const_addr =
|
||||||
comp_ctx->builder, base, &const_index, 1, "const_addr_tmp"))) {
|
LLVMBuildInBoundsGEP2(comp_ctx->builder, OPQ_PTR_TYPE, base,
|
||||||
|
&const_index, 1, "const_addr_tmp"))) {
|
||||||
aot_set_last_error("get const addr by index failed.");
|
aot_set_last_error("get const addr by index failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2739,11 +2773,12 @@ aot_load_const_from_table(AOTCompContext *comp_ctx, LLVMValueRef base,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(const_value =
|
if (!(const_value = LLVMBuildLoad2(comp_ctx->builder, const_type,
|
||||||
LLVMBuildLoad(comp_ctx->builder, const_addr, "const_value"))) {
|
const_addr, "const_value"))) {
|
||||||
aot_set_last_error("load const failed.");
|
aot_set_last_error("load const failed.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void)const_type;
|
||||||
return const_value;
|
return const_value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,20 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR < 14
|
||||||
|
#define LLVMBuildLoad2(builder, type, value, name) \
|
||||||
|
LLVMBuildLoad(builder, value, name)
|
||||||
|
|
||||||
|
#define LLVMBuildCall2(builder, type, func, args, num_args, name) \
|
||||||
|
LLVMBuildCall(builder, func, args, num_args, name)
|
||||||
|
|
||||||
|
#define LLVMBuildInBoundsGEP2(builder, type, ptr, indices, num_indices, name) \
|
||||||
|
LLVMBuildInBoundsGEP(builder, ptr, indices, num_indices, name)
|
||||||
|
#else
|
||||||
|
/* Opaque pointer type */
|
||||||
|
#define OPQ_PTR_TYPE INT8_PTR_TYPE
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value in the WASM operation stack, each stack element
|
* Value in the WASM operation stack, each stack element
|
||||||
* is an LLVM value
|
* is an LLVM value
|
||||||
|
|
|
@ -492,7 +492,11 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx)
|
||||||
|
|
||||||
if (!disable_llvm_lto) {
|
if (!disable_llvm_lto) {
|
||||||
/* Apply LTO for AOT mode */
|
/* Apply LTO for AOT mode */
|
||||||
|
#if LLVM_VERSION_MAJOR < 14
|
||||||
MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL));
|
MPM.addPass(PB.buildLTODefaultPipeline(OL, NULL));
|
||||||
|
#else
|
||||||
|
MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(OL));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MPM.addPass(PB.buildPerModuleDefaultPipeline(OL));
|
MPM.addPass(PB.buildPerModuleDefaultPipeline(OL));
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
/* data_length in bytes */
|
/* data_length in bytes */
|
||||||
static LLVMValueRef
|
static LLVMValueRef
|
||||||
simd_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
|
simd_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
|
||||||
uint32 offset, uint32 data_length, LLVMTypeRef ptr_type)
|
uint32 offset, uint32 data_length, LLVMTypeRef ptr_type,
|
||||||
|
LLVMTypeRef data_type)
|
||||||
{
|
{
|
||||||
LLVMValueRef maddr, data;
|
LLVMValueRef maddr, data;
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ simd_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 align,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(data = LLVMBuildLoad(comp_ctx->builder, maddr, "data"))) {
|
if (!(data = LLVMBuildLoad2(comp_ctx->builder, data_type, maddr, "data"))) {
|
||||||
HANDLE_FAILURE("LLVMBuildLoad");
|
HANDLE_FAILURE("LLVMBuildLoad");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ aot_compile_simd_v128_load(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
LLVMValueRef result;
|
LLVMValueRef result;
|
||||||
|
|
||||||
if (!(result = simd_load(comp_ctx, func_ctx, align, offset, 16,
|
if (!(result = simd_load(comp_ctx, func_ctx, align, offset, 16,
|
||||||
V128_PTR_TYPE))) {
|
V128_PTR_TYPE, V128_TYPE))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ aot_compile_simd_load_extend(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
LLVMVectorType(INT16_TYPE, 4), LLVMVectorType(INT16_TYPE, 4),
|
LLVMVectorType(INT16_TYPE, 4), LLVMVectorType(INT16_TYPE, 4),
|
||||||
LLVMVectorType(I32_TYPE, 2), LLVMVectorType(I32_TYPE, 2),
|
LLVMVectorType(I32_TYPE, 2), LLVMVectorType(I32_TYPE, 2),
|
||||||
};
|
};
|
||||||
LLVMTypeRef sub_vector_type;
|
LLVMTypeRef sub_vector_type, sub_vector_ptr_type;
|
||||||
|
|
||||||
bh_assert(opcode_index < 6);
|
bh_assert(opcode_index < 6);
|
||||||
|
|
||||||
|
@ -81,13 +82,13 @@ aot_compile_simd_load_extend(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
/* to vector ptr type */
|
/* to vector ptr type */
|
||||||
if (!sub_vector_type
|
if (!sub_vector_type
|
||||||
|| !(sub_vector_type = LLVMPointerType(sub_vector_type, 0))) {
|
|| !(sub_vector_ptr_type = LLVMPointerType(sub_vector_type, 0))) {
|
||||||
HANDLE_FAILURE("LLVMPointerType");
|
HANDLE_FAILURE("LLVMPointerType");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sub_vector = simd_load(comp_ctx, func_ctx, align, offset, 8,
|
if (!(sub_vector = simd_load(comp_ctx, func_ctx, align, offset, 8,
|
||||||
sub_vector_type))) {
|
sub_vector_ptr_type, sub_vector_type))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +118,8 @@ aot_compile_simd_load_splat(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
LLVMValueRef element, result;
|
LLVMValueRef element, result;
|
||||||
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
|
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
|
||||||
INT32_PTR_TYPE, INT64_PTR_TYPE };
|
INT32_PTR_TYPE, INT64_PTR_TYPE };
|
||||||
|
LLVMTypeRef element_data_types[] = { INT8_TYPE, INT16_TYPE, I32_TYPE,
|
||||||
|
I64_TYPE };
|
||||||
uint32 data_lengths[] = { 1, 2, 4, 8 };
|
uint32 data_lengths[] = { 1, 2, 4, 8 };
|
||||||
LLVMValueRef undefs[] = {
|
LLVMValueRef undefs[] = {
|
||||||
LLVM_CONST(i8x16_undef),
|
LLVM_CONST(i8x16_undef),
|
||||||
|
@ -135,7 +138,8 @@ aot_compile_simd_load_splat(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
|
if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
|
||||||
data_lengths[opcode_index],
|
data_lengths[opcode_index],
|
||||||
element_ptr_types[opcode_index]))) {
|
element_ptr_types[opcode_index],
|
||||||
|
element_data_types[opcode_index]))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +170,8 @@ aot_compile_simd_load_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
uint32 data_lengths[] = { 1, 2, 4, 8 };
|
uint32 data_lengths[] = { 1, 2, 4, 8 };
|
||||||
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
|
LLVMTypeRef element_ptr_types[] = { INT8_PTR_TYPE, INT16_PTR_TYPE,
|
||||||
INT32_PTR_TYPE, INT64_PTR_TYPE };
|
INT32_PTR_TYPE, INT64_PTR_TYPE };
|
||||||
|
LLVMTypeRef element_data_types[] = { INT8_TYPE, INT16_TYPE, I32_TYPE,
|
||||||
|
I64_TYPE };
|
||||||
LLVMTypeRef vector_types[] = { V128_i8x16_TYPE, V128_i16x8_TYPE,
|
LLVMTypeRef vector_types[] = { V128_i8x16_TYPE, V128_i16x8_TYPE,
|
||||||
V128_i32x4_TYPE, V128_i64x2_TYPE };
|
V128_i32x4_TYPE, V128_i64x2_TYPE };
|
||||||
LLVMValueRef lane = simd_lane_id_to_llvm_value(comp_ctx, lane_id);
|
LLVMValueRef lane = simd_lane_id_to_llvm_value(comp_ctx, lane_id);
|
||||||
|
@ -179,7 +185,8 @@ aot_compile_simd_load_lane(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
|
if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
|
||||||
data_lengths[opcode_index],
|
data_lengths[opcode_index],
|
||||||
element_ptr_types[opcode_index]))) {
|
element_ptr_types[opcode_index],
|
||||||
|
element_data_types[opcode_index]))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,6 +207,7 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
uint32 opcode_index = opcode - SIMD_v128_load32_zero;
|
uint32 opcode_index = opcode - SIMD_v128_load32_zero;
|
||||||
uint32 data_lengths[] = { 4, 8 };
|
uint32 data_lengths[] = { 4, 8 };
|
||||||
LLVMTypeRef element_ptr_types[] = { INT32_PTR_TYPE, INT64_PTR_TYPE };
|
LLVMTypeRef element_ptr_types[] = { INT32_PTR_TYPE, INT64_PTR_TYPE };
|
||||||
|
LLVMTypeRef element_data_types[] = { I32_TYPE, I64_TYPE };
|
||||||
LLVMValueRef zero[] = {
|
LLVMValueRef zero[] = {
|
||||||
LLVM_CONST(i32x4_vec_zero),
|
LLVM_CONST(i32x4_vec_zero),
|
||||||
LLVM_CONST(i64x2_vec_zero),
|
LLVM_CONST(i64x2_vec_zero),
|
||||||
|
@ -219,7 +227,8 @@ aot_compile_simd_load_zero(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
||||||
|
|
||||||
if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
|
if (!(element = simd_load(comp_ctx, func_ctx, align, offset,
|
||||||
data_lengths[opcode_index],
|
data_lengths[opcode_index],
|
||||||
element_ptr_types[opcode_index]))) {
|
element_ptr_types[opcode_index],
|
||||||
|
element_data_types[opcode_index]))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user