|
@@ -9,14 +9,14 @@
|
|
|
#include "aot_emit_table.h"
|
|
#include "aot_emit_table.h"
|
|
|
#include "../aot/aot_runtime.h"
|
|
#include "../aot/aot_runtime.h"
|
|
|
|
|
|
|
|
-#define ADD_BASIC_BLOCK(block, name) do { \
|
|
|
|
|
- if (!(block = LLVMAppendBasicBlockInContext(comp_ctx->context, \
|
|
|
|
|
- func_ctx->func, \
|
|
|
|
|
- name))) { \
|
|
|
|
|
- aot_set_last_error("llvm add basic block failed."); \
|
|
|
|
|
- goto fail; \
|
|
|
|
|
- } \
|
|
|
|
|
- } while (0)
|
|
|
|
|
|
|
+#define ADD_BASIC_BLOCK(block, name) \
|
|
|
|
|
+ do { \
|
|
|
|
|
+ if (!(block = LLVMAppendBasicBlockInContext(comp_ctx->context, \
|
|
|
|
|
+ func_ctx->func, name))) { \
|
|
|
|
|
+ aot_set_last_error("llvm add basic block failed."); \
|
|
|
|
|
+ goto fail; \
|
|
|
|
|
+ } \
|
|
|
|
|
+ } while (0)
|
|
|
|
|
|
|
|
static bool
|
|
static bool
|
|
|
create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|
create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|
@@ -26,15 +26,15 @@ create_func_return_block(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|
|
|
|
|
|
|
/* Create function return block if it isn't created */
|
|
/* Create function return block if it isn't created */
|
|
|
if (!func_ctx->func_return_block) {
|
|
if (!func_ctx->func_return_block) {
|
|
|
- if (!(func_ctx->func_return_block =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func, "func_ret"))) {
|
|
|
|
|
|
|
+ if (!(func_ctx->func_return_block = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "func_ret"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Create return IR */
|
|
/* Create return IR */
|
|
|
- LLVMPositionBuilderAtEnd(comp_ctx->builder, func_ctx->func_return_block);
|
|
|
|
|
|
|
+ LLVMPositionBuilderAtEnd(comp_ctx->builder,
|
|
|
|
|
+ func_ctx->func_return_block);
|
|
|
if (!aot_build_zero_function_ret(comp_ctx, func_ctx, aot_func_type)) {
|
|
if (!aot_build_zero_function_ret(comp_ctx, func_ctx, aot_func_type)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -59,16 +59,15 @@ check_exception_thrown(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|
|
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 = LLVMBuildLoad(comp_ctx->builder, func_ctx->cur_exception,
|
|
|
"exce_value"))
|
|
"exce_value"))
|
|
|
- || !(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ,
|
|
|
|
|
- value, I8_ZERO, "cmp"))) {
|
|
|
|
|
|
|
+ || !(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ, value, I8_ZERO,
|
|
|
|
|
+ "cmp"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Add check exection success block */
|
|
/* Add check exection success block */
|
|
|
- if (!(check_exce_succ = LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func,
|
|
|
|
|
- "check_exce_succ"))) {
|
|
|
|
|
|
|
+ if (!(check_exce_succ = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "check_exce_succ"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -78,8 +77,8 @@ check_exception_thrown(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|
|
|
|
|
|
|
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
|
|
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
|
|
|
/* Create condition br */
|
|
/* Create condition br */
|
|
|
- if (!LLVMBuildCondBr(comp_ctx->builder, cmp,
|
|
|
|
|
- check_exce_succ, func_ctx->func_return_block)) {
|
|
|
|
|
|
|
+ if (!LLVMBuildCondBr(comp_ctx->builder, cmp, check_exce_succ,
|
|
|
|
|
+ func_ctx->func_return_block)) {
|
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -100,16 +99,15 @@ check_call_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
if (!create_func_return_block(comp_ctx, func_ctx))
|
|
if (!create_func_return_block(comp_ctx, func_ctx))
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
- if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntNE,
|
|
|
|
|
- res, I8_ZERO, "cmp"))) {
|
|
|
|
|
|
|
+ if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntNE, res, I8_ZERO,
|
|
|
|
|
+ "cmp"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Add check exection success block */
|
|
/* Add check exection success block */
|
|
|
- if (!(check_call_succ = LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func,
|
|
|
|
|
- "check_call_succ"))) {
|
|
|
|
|
|
|
+ if (!(check_call_succ = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "check_call_succ"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -119,8 +117,8 @@ check_call_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
|
|
|
|
|
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
|
|
LLVMPositionBuilderAtEnd(comp_ctx->builder, block_curr);
|
|
|
/* Create condition br */
|
|
/* Create condition br */
|
|
|
- if (!LLVMBuildCondBr(comp_ctx->builder, cmp,
|
|
|
|
|
- check_call_succ, func_ctx->func_return_block)) {
|
|
|
|
|
|
|
+ if (!LLVMBuildCondBr(comp_ctx->builder, cmp, check_call_succ,
|
|
|
|
|
+ func_ctx->func_return_block)) {
|
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -132,10 +130,11 @@ check_call_return(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
static bool
|
|
static bool
|
|
|
call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
LLVMValueRef func_idx, AOTFuncType *aot_func_type,
|
|
LLVMValueRef func_idx, AOTFuncType *aot_func_type,
|
|
|
- LLVMTypeRef *param_types, LLVMValueRef *param_values,
|
|
|
|
|
- uint32 param_count, uint32 param_cell_num,
|
|
|
|
|
- LLVMTypeRef ret_type, uint8 wasm_ret_type,
|
|
|
|
|
- LLVMValueRef *p_value_ret, LLVMValueRef *p_res)
|
|
|
|
|
|
|
+ LLVMTypeRef *param_types,
|
|
|
|
|
+ LLVMValueRef *param_values, uint32 param_count,
|
|
|
|
|
+ uint32 param_cell_num, LLVMTypeRef ret_type,
|
|
|
|
|
+ uint8 wasm_ret_type, LLVMValueRef *p_value_ret,
|
|
|
|
|
+ LLVMValueRef *p_res)
|
|
|
{
|
|
{
|
|
|
LLVMTypeRef func_type, func_ptr_type, func_param_types[4];
|
|
LLVMTypeRef func_type, func_ptr_type, func_param_types[4];
|
|
|
LLVMTypeRef ret_ptr_type, elem_ptr_type;
|
|
LLVMTypeRef ret_ptr_type, elem_ptr_type;
|
|
@@ -145,11 +144,12 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
uint32 i, cell_num = 0;
|
|
uint32 i, cell_num = 0;
|
|
|
|
|
|
|
|
/* prepare function type of aot_invoke_native */
|
|
/* prepare function type of aot_invoke_native */
|
|
|
- func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
|
|
|
|
|
- func_param_types[1] = I32_TYPE; /* func_idx */
|
|
|
|
|
- func_param_types[2] = I32_TYPE; /* argc */
|
|
|
|
|
- func_param_types[3] = INT32_PTR_TYPE; /* argv */
|
|
|
|
|
- if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 4, false))) {
|
|
|
|
|
|
|
+ func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
|
|
|
|
|
+ func_param_types[1] = I32_TYPE; /* func_idx */
|
|
|
|
|
+ func_param_types[2] = I32_TYPE; /* argc */
|
|
|
|
|
+ func_param_types[3] = INT32_PTR_TYPE; /* argv */
|
|
|
|
|
+ if (!(func_type =
|
|
|
|
|
+ LLVMFunctionType(INT8_TYPE, func_param_types, 4, false))) {
|
|
|
aot_set_last_error("llvm add function type failed.");
|
|
aot_set_last_error("llvm add function type failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -174,8 +174,7 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
aot_set_last_error("create LLVM function type failed.");
|
|
aot_set_last_error("create LLVM function type failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- func_index =
|
|
|
|
|
- aot_get_native_symbol_index(comp_ctx, func_name);
|
|
|
|
|
|
|
+ func_index = aot_get_native_symbol_index(comp_ctx, func_name);
|
|
|
if (func_index < 0) {
|
|
if (func_index < 0) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -187,7 +186,7 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
else {
|
|
else {
|
|
|
if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
|
|
if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
|
|
|
&& !(func =
|
|
&& !(func =
|
|
|
- LLVMAddFunction(comp_ctx->module, func_name, func_type))) {
|
|
|
|
|
|
|
+ LLVMAddFunction(comp_ctx->module, func_name, func_type))) {
|
|
|
aot_set_last_error("add LLVM function failed.");
|
|
aot_set_last_error("add LLVM function failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -208,15 +207,16 @@ 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(comp_ctx->builder,
|
|
|
|
|
- func_ctx->argv_buf, &elem_idx, 1, buf))
|
|
|
|
|
|
|
+ if (!(elem_ptr = LLVMBuildInBoundsGEP(
|
|
|
|
|
+ comp_ctx->builder, 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.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(res = LLVMBuildStore(comp_ctx->builder, param_values[i], elem_ptr))) {
|
|
|
|
|
|
|
+ if (!(res = LLVMBuildStore(comp_ctx->builder, param_values[i],
|
|
|
|
|
+ elem_ptr))) {
|
|
|
aot_set_last_error("llvm build store failed.");
|
|
aot_set_last_error("llvm build store failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -236,8 +236,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, "res"))) {
|
|
|
|
|
|
|
+ if (!(res = LLVMBuildCall(comp_ctx->builder, func, 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;
|
|
|
}
|
|
}
|
|
@@ -249,13 +249,14 @@ call_aot_invoke_native_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(value_ret = LLVMBuildBitCast(comp_ctx->builder, func_ctx->argv_buf,
|
|
|
|
|
- ret_ptr_type, "argv_ret"))) {
|
|
|
|
|
|
|
+ if (!(value_ret =
|
|
|
|
|
+ LLVMBuildBitCast(comp_ctx->builder, func_ctx->argv_buf,
|
|
|
|
|
+ ret_ptr_type, "argv_ret"))) {
|
|
|
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 = LLVMBuildLoad(comp_ctx->builder, value_ret,
|
|
|
|
|
- "value_ret"))) {
|
|
|
|
|
|
|
+ if (!(*p_value_ret =
|
|
|
|
|
+ LLVMBuildLoad(comp_ctx->builder, value_ret, "value_ret"))) {
|
|
|
aot_set_last_error("llvm build load failed.");
|
|
aot_set_last_error("llvm build load failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -285,15 +286,14 @@ 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 = LLVMBuildCall(comp_ctx->builder, func, param_values, 2,
|
|
|
"call_aot_alloc_frame"))) {
|
|
"call_aot_alloc_frame"))) {
|
|
|
aot_set_last_error("llvm build call failed.");
|
|
aot_set_last_error("llvm build call failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(ret_value = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGT,
|
|
|
|
|
- ret_value, I8_ZERO, "frame_alloc_ret"))) {
|
|
|
|
|
|
|
+ if (!(ret_value = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGT, ret_value,
|
|
|
|
|
+ I8_ZERO, "frame_alloc_ret"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -304,8 +304,8 @@ call_aot_alloc_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
LLVMMoveBasicBlockAfter(frame_alloc_fail, block_curr);
|
|
LLVMMoveBasicBlockAfter(frame_alloc_fail, block_curr);
|
|
|
LLVMMoveBasicBlockAfter(frame_alloc_success, block_curr);
|
|
LLVMMoveBasicBlockAfter(frame_alloc_success, block_curr);
|
|
|
|
|
|
|
|
- if (!LLVMBuildCondBr(comp_ctx->builder, ret_value,
|
|
|
|
|
- frame_alloc_success, frame_alloc_fail)) {
|
|
|
|
|
|
|
+ if (!LLVMBuildCondBr(comp_ctx->builder, ret_value, frame_alloc_success,
|
|
|
|
|
+ frame_alloc_fail)) {
|
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -338,8 +338,7 @@ 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 = LLVMBuildCall(comp_ctx->builder, func, param_values, 1,
|
|
|
"call_aot_free_frame"))) {
|
|
"call_aot_free_frame"))) {
|
|
|
aot_set_last_error("llvm build call failed.");
|
|
aot_set_last_error("llvm build call failed.");
|
|
|
return false;
|
|
return false;
|
|
@@ -347,7 +346,7 @@ call_aot_free_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
-#endif /* end of (WASM_ENABLE_DUMP_CALL_STACK != 0)
|
|
|
|
|
|
|
+#endif /* end of (WASM_ENABLE_DUMP_CALL_STACK != 0) \
|
|
|
|| (WASM_ENABLE_PERF_PROFILING != 0) */
|
|
|| (WASM_ENABLE_PERF_PROFILING != 0) */
|
|
|
|
|
|
|
|
static bool
|
|
static bool
|
|
@@ -363,17 +362,15 @@ check_stack_boundary(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(stack_bound = LLVMBuildInBoundsGEP(comp_ctx->builder,
|
|
|
|
|
- func_ctx->native_stack_bound,
|
|
|
|
|
- &callee_local_size, 1,
|
|
|
|
|
- "stack_bound"))) {
|
|
|
|
|
|
|
+ if (!(stack_bound = LLVMBuildInBoundsGEP(
|
|
|
|
|
+ comp_ctx->builder, func_ctx->native_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;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(check_stack = LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func,
|
|
|
|
|
- "check_stack"))) {
|
|
|
|
|
|
|
+ if (!(check_stack = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "check_stack"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -381,14 +378,12 @@ check_stack_boundary(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
LLVMMoveBasicBlockAfter(check_stack, block_curr);
|
|
LLVMMoveBasicBlockAfter(check_stack, block_curr);
|
|
|
|
|
|
|
|
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT,
|
|
if (!(cmp = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT,
|
|
|
- func_ctx->last_alloca, stack_bound,
|
|
|
|
|
- "cmp"))) {
|
|
|
|
|
|
|
+ func_ctx->last_alloca, stack_bound, "cmp"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!aot_emit_exception(comp_ctx, func_ctx,
|
|
|
|
|
- EXCE_NATIVE_STACK_OVERFLOW,
|
|
|
|
|
|
|
+ if (!aot_emit_exception(comp_ctx, func_ctx, EXCE_NATIVE_STACK_OVERFLOW,
|
|
|
true, cmp, check_stack)) {
|
|
true, cmp, check_stack)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -439,8 +434,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
if (func_idx < import_func_count)
|
|
if (func_idx < import_func_count)
|
|
|
func_type = import_funcs[func_idx].func_type;
|
|
func_type = import_funcs[func_idx].func_type;
|
|
|
else
|
|
else
|
|
|
- func_type = func_ctxes[func_idx - import_func_count]->
|
|
|
|
|
- aot_func->func_type;
|
|
|
|
|
|
|
+ func_type =
|
|
|
|
|
+ func_ctxes[func_idx - import_func_count]->aot_func->func_type;
|
|
|
|
|
|
|
|
/* Get param cell number */
|
|
/* Get param cell number */
|
|
|
param_cell_num = func_type->param_cell_num;
|
|
param_cell_num = func_type->param_cell_num;
|
|
@@ -467,8 +462,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
param_count = (int32)func_type->param_count;
|
|
param_count = (int32)func_type->param_count;
|
|
|
result_count = (int32)func_type->result_count;
|
|
result_count = (int32)func_type->result_count;
|
|
|
ext_ret_count = result_count > 1 ? result_count - 1 : 0;
|
|
ext_ret_count = result_count > 1 ? result_count - 1 : 0;
|
|
|
- total_size = sizeof(LLVMValueRef) * (uint64)(param_count + 1
|
|
|
|
|
- + ext_ret_count);
|
|
|
|
|
|
|
+ total_size =
|
|
|
|
|
+ sizeof(LLVMValueRef) * (uint64)(param_count + 1 + ext_ret_count);
|
|
|
if (total_size >= UINT32_MAX
|
|
if (total_size >= UINT32_MAX
|
|
|
|| !(param_values = wasm_runtime_malloc((uint32)total_size))) {
|
|
|| !(param_values = wasm_runtime_malloc((uint32)total_size))) {
|
|
|
aot_set_last_error("allocate memory failed.");
|
|
aot_set_last_error("allocate memory failed.");
|
|
@@ -498,7 +493,7 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
for (i = 0; i < ext_ret_count; i++) {
|
|
for (i = 0; i < ext_ret_count; i++) {
|
|
|
if (!(ext_ret_idx = I32_CONST(cell_num))
|
|
if (!(ext_ret_idx = I32_CONST(cell_num))
|
|
|
|| !(ext_ret_ptr_type =
|
|
|| !(ext_ret_ptr_type =
|
|
|
- LLVMPointerType(TO_LLVM_TYPE(ext_ret_types[i]), 0))) {
|
|
|
|
|
|
|
+ LLVMPointerType(TO_LLVM_TYPE(ext_ret_types[i]), 0))) {
|
|
|
aot_set_last_error("llvm add const or pointer type failed.");
|
|
aot_set_last_error("llvm add const or pointer type failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -511,9 +506,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
snprintf(buf, sizeof(buf), "ext_ret%d_ptr_cast", i);
|
|
snprintf(buf, sizeof(buf), "ext_ret%d_ptr_cast", i);
|
|
|
- if (!(ext_ret_ptr = LLVMBuildBitCast(comp_ctx->builder,
|
|
|
|
|
- ext_ret_ptr, ext_ret_ptr_type,
|
|
|
|
|
- buf))) {
|
|
|
|
|
|
|
+ if (!(ext_ret_ptr = LLVMBuildBitCast(comp_ctx->builder, ext_ret_ptr,
|
|
|
|
|
+ ext_ret_ptr_type, buf))) {
|
|
|
aot_set_last_error("llvm build bit cast failed.");
|
|
aot_set_last_error("llvm build bit cast failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -552,13 +546,14 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* call aot_invoke_native() */
|
|
/* call aot_invoke_native() */
|
|
|
- if (!call_aot_invoke_native_func(comp_ctx, func_ctx, import_func_idx, func_type,
|
|
|
|
|
- param_types + 1, param_values + 1,
|
|
|
|
|
- param_count, param_cell_num,
|
|
|
|
|
- ret_type, wasm_ret_type, &value_ret, &res))
|
|
|
|
|
|
|
+ if (!call_aot_invoke_native_func(
|
|
|
|
|
+ comp_ctx, func_ctx, import_func_idx, func_type, param_types + 1,
|
|
|
|
|
+ param_values + 1, param_count, param_cell_num, ret_type,
|
|
|
|
|
+ wasm_ret_type, &value_ret, &res))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
|
|
|
|
|
- /* Check whether there was exception thrown when executing the function */
|
|
|
|
|
|
|
+ /* Check whether there was exception thrown when executing
|
|
|
|
|
+ the function */
|
|
|
if (!check_call_return(comp_ctx, func_ctx, res))
|
|
if (!check_call_return(comp_ctx, func_ctx, res))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -567,7 +562,8 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
LLVMTypeRef func_ptr_type;
|
|
LLVMTypeRef func_ptr_type;
|
|
|
|
|
|
|
|
if (!(func_ptr_type = LLVMPointerType(
|
|
if (!(func_ptr_type = LLVMPointerType(
|
|
|
- func_ctxes[func_idx - import_func_count]->func_type, 0))) {
|
|
|
|
|
|
|
+ func_ctxes[func_idx - import_func_count]->func_type,
|
|
|
|
|
+ 0))) {
|
|
|
aot_set_last_error("construct func ptr type failed.");
|
|
aot_set_last_error("construct func ptr type failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -580,31 +576,32 @@ aot_compile_op_call(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
func = func_ctxes[func_idx - import_func_count]->func;
|
|
func = func_ctxes[func_idx - import_func_count]->func;
|
|
|
}
|
|
}
|
|
|
aot_func = func_ctxes[func_idx - import_func_count]->aot_func;
|
|
aot_func = func_ctxes[func_idx - import_func_count]->aot_func;
|
|
|
- callee_cell_num = aot_func->param_cell_num + aot_func->local_cell_num + 1;
|
|
|
|
|
|
|
+ callee_cell_num =
|
|
|
|
|
+ aot_func->param_cell_num + aot_func->local_cell_num + 1;
|
|
|
|
|
|
|
|
if (comp_ctx->enable_bound_check
|
|
if (comp_ctx->enable_bound_check
|
|
|
&& !check_stack_boundary(comp_ctx, func_ctx, callee_cell_num))
|
|
&& !check_stack_boundary(comp_ctx, func_ctx, callee_cell_num))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Call the function */
|
|
/* Call the function */
|
|
|
- if (!(value_ret = LLVMBuildCall(comp_ctx->builder, func,
|
|
|
|
|
- param_values,
|
|
|
|
|
- (uint32)param_count + 1 + ext_ret_count,
|
|
|
|
|
- (func_type->result_count > 0
|
|
|
|
|
- ? "call" : "")))) {
|
|
|
|
|
|
|
+ if (!(value_ret =
|
|
|
|
|
+ LLVMBuildCall(comp_ctx->builder, func, param_values,
|
|
|
|
|
+ (uint32)param_count + 1 + ext_ret_count,
|
|
|
|
|
+ (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;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /* Set calling convention for the call with the func's calling convention */
|
|
|
|
|
|
|
+ /* Set calling convention for the call with the func's calling
|
|
|
|
|
+ convention */
|
|
|
LLVMSetInstructionCallConv(value_ret, LLVMGetFunctionCallConv(func));
|
|
LLVMSetInstructionCallConv(value_ret, LLVMGetFunctionCallConv(func));
|
|
|
|
|
|
|
|
if (tail_call)
|
|
if (tail_call)
|
|
|
LLVMSetTailCall(value_ret, true);
|
|
LLVMSetTailCall(value_ret, true);
|
|
|
|
|
|
|
|
- /* Check whether there was exception thrown when executing the function */
|
|
|
|
|
- if (!tail_call
|
|
|
|
|
- && !check_exception_thrown(comp_ctx, func_ctx))
|
|
|
|
|
|
|
+ /* Check whether there was exception thrown when executing
|
|
|
|
|
+ the function */
|
|
|
|
|
+ if (!tail_call && !check_exception_thrown(comp_ctx, func_ctx))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -614,9 +611,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 = LLVMBuildLoad(comp_ctx->builder,
|
|
|
|
|
- param_values[1 + param_count + i],
|
|
|
|
|
- buf))) {
|
|
|
|
|
|
|
+ if (!(ext_ret =
|
|
|
|
|
+ LLVMBuildLoad(comp_ctx->builder,
|
|
|
|
|
+ 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;
|
|
|
}
|
|
}
|
|
@@ -642,12 +639,14 @@ fail:
|
|
|
|
|
|
|
|
static bool
|
|
static bool
|
|
|
call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
- AOTFuncType *aot_func_type, LLVMValueRef func_type_idx,
|
|
|
|
|
- LLVMValueRef table_idx, LLVMValueRef table_elem_idx,
|
|
|
|
|
- LLVMTypeRef *param_types, LLVMValueRef *param_values,
|
|
|
|
|
- uint32 param_count, uint32 param_cell_num,
|
|
|
|
|
- uint32 result_count, uint8 *wasm_ret_types,
|
|
|
|
|
- LLVMValueRef *value_rets, LLVMValueRef *p_res)
|
|
|
|
|
|
|
+ AOTFuncType *aot_func_type,
|
|
|
|
|
+ LLVMValueRef func_type_idx, LLVMValueRef table_idx,
|
|
|
|
|
+ LLVMValueRef table_elem_idx,
|
|
|
|
|
+ LLVMTypeRef *param_types,
|
|
|
|
|
+ LLVMValueRef *param_values, uint32 param_count,
|
|
|
|
|
+ uint32 param_cell_num, uint32 result_count,
|
|
|
|
|
+ uint8 *wasm_ret_types, LLVMValueRef *value_rets,
|
|
|
|
|
+ LLVMValueRef *p_res)
|
|
|
{
|
|
{
|
|
|
LLVMTypeRef func_type, func_ptr_type, func_param_types[6];
|
|
LLVMTypeRef func_type, func_ptr_type, func_param_types[6];
|
|
|
LLVMTypeRef ret_type, ret_ptr_type, elem_ptr_type;
|
|
LLVMTypeRef ret_type, ret_ptr_type, elem_ptr_type;
|
|
@@ -657,12 +656,13 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
uint32 i, cell_num = 0, ret_cell_num, argv_cell_num;
|
|
uint32 i, cell_num = 0, ret_cell_num, argv_cell_num;
|
|
|
|
|
|
|
|
/* prepare function type of aot_call_indirect */
|
|
/* prepare function type of aot_call_indirect */
|
|
|
- func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
|
|
|
|
|
- func_param_types[1] = I32_TYPE; /* table_idx */
|
|
|
|
|
- func_param_types[2] = I32_TYPE; /* table_elem_idx */
|
|
|
|
|
- func_param_types[3] = I32_TYPE; /* argc */
|
|
|
|
|
- func_param_types[4] = INT32_PTR_TYPE; /* argv */
|
|
|
|
|
- if (!(func_type = LLVMFunctionType(INT8_TYPE, func_param_types, 5, false))) {
|
|
|
|
|
|
|
+ func_param_types[0] = comp_ctx->exec_env_type; /* exec_env */
|
|
|
|
|
+ func_param_types[1] = I32_TYPE; /* table_idx */
|
|
|
|
|
+ func_param_types[2] = I32_TYPE; /* table_elem_idx */
|
|
|
|
|
+ func_param_types[3] = I32_TYPE; /* argc */
|
|
|
|
|
+ func_param_types[4] = INT32_PTR_TYPE; /* argv */
|
|
|
|
|
+ if (!(func_type =
|
|
|
|
|
+ LLVMFunctionType(INT8_TYPE, func_param_types, 5, false))) {
|
|
|
aot_set_last_error("llvm add function type failed.");
|
|
aot_set_last_error("llvm add function type failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -687,8 +687,7 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
aot_set_last_error("create LLVM function type failed.");
|
|
aot_set_last_error("create LLVM function type failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- func_index =
|
|
|
|
|
- aot_get_native_symbol_index(comp_ctx, func_name);
|
|
|
|
|
|
|
+ func_index = aot_get_native_symbol_index(comp_ctx, func_name);
|
|
|
if (func_index < 0) {
|
|
if (func_index < 0) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -699,15 +698,16 @@ call_aot_call_indirect_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
|
|
if (!(func = LLVMGetNamedFunction(comp_ctx->module, func_name))
|
|
|
- && !(func = LLVMAddFunction(comp_ctx->module,
|
|
|
|
|
- func_name, func_type))) {
|
|
|
|
|
|
|
+ && !(func =
|
|
|
|
|
+ LLVMAddFunction(comp_ctx->module, func_name, func_type))) {
|
|
|
aot_set_last_error("add LLVM function failed.");
|
|
aot_set_last_error("add LLVM function failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ret_cell_num = wasm_get_cell_num(wasm_ret_types, result_count);
|
|
ret_cell_num = wasm_get_cell_num(wasm_ret_types, result_count);
|
|
|
- argv_cell_num = param_cell_num > ret_cell_num ? param_cell_num : ret_cell_num;
|
|
|
|
|
|
|
+ argv_cell_num =
|
|
|
|
|
+ param_cell_num > ret_cell_num ? param_cell_num : ret_cell_num;
|
|
|
if (argv_cell_num > 64) {
|
|
if (argv_cell_num > 64) {
|
|
|
aot_set_last_error("prepare native arguments failed: "
|
|
aot_set_last_error("prepare native arguments failed: "
|
|
|
"maximum 64 parameter cell number supported.");
|
|
"maximum 64 parameter cell number supported.");
|
|
@@ -723,15 +723,16 @@ 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(comp_ctx->builder,
|
|
|
|
|
- func_ctx->argv_buf, &elem_idx, 1, buf))
|
|
|
|
|
|
|
+ if (!(elem_ptr = LLVMBuildInBoundsGEP(
|
|
|
|
|
+ comp_ctx->builder, 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.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(res = LLVMBuildStore(comp_ctx->builder, param_values[i], elem_ptr))) {
|
|
|
|
|
|
|
+ if (!(res = LLVMBuildStore(comp_ctx->builder, param_values[i],
|
|
|
|
|
+ elem_ptr))) {
|
|
|
aot_set_last_error("llvm build store failed.");
|
|
aot_set_last_error("llvm build store failed.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -752,8 +753,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, "res"))) {
|
|
|
|
|
|
|
+ if (!(res = LLVMBuildCall(comp_ctx->builder, func, 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;
|
|
|
}
|
|
}
|
|
@@ -769,8 +770,8 @@ 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(comp_ctx->builder,
|
|
|
|
|
- func_ctx->argv_buf, &ret_idx, 1, buf))
|
|
|
|
|
|
|
+ if (!(ret_ptr = LLVMBuildInBoundsGEP(
|
|
|
|
|
+ comp_ctx->builder, 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.");
|
|
@@ -846,38 +847,35 @@ 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, &offset, 1,
|
|
|
|
|
- "cur_size_i8p"))) {
|
|
|
|
|
|
|
+ if (!(table_size_const = LLVMBuildGEP(comp_ctx->builder, func_ctx->aot_inst,
|
|
|
|
|
+ &offset, 1, "cur_size_i8p"))) {
|
|
|
HANDLE_FAILURE("LLVMBuildGEP");
|
|
HANDLE_FAILURE("LLVMBuildGEP");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!(table_size_const =
|
|
if (!(table_size_const =
|
|
|
- LLVMBuildBitCast(comp_ctx->builder, table_size_const,
|
|
|
|
|
- INT32_PTR_TYPE, "cur_siuze_i32p"))) {
|
|
|
|
|
|
|
+ LLVMBuildBitCast(comp_ctx->builder, table_size_const,
|
|
|
|
|
+ INT32_PTR_TYPE, "cur_siuze_i32p"))) {
|
|
|
HANDLE_FAILURE("LLVMBuildBitCast");
|
|
HANDLE_FAILURE("LLVMBuildBitCast");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(table_size_const = LLVMBuildLoad(comp_ctx->builder, table_size_const, "cur_size"))) {
|
|
|
|
|
|
|
+ if (!(table_size_const =
|
|
|
|
|
+ LLVMBuildLoad(comp_ctx->builder, table_size_const, "cur_size"))) {
|
|
|
HANDLE_FAILURE("LLVMBuildLoad");
|
|
HANDLE_FAILURE("LLVMBuildLoad");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Check if (uint32)elem index >= table size */
|
|
/* Check if (uint32)elem index >= table size */
|
|
|
- if (!(cmp_elem_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE,
|
|
|
|
|
- elem_idx, table_size_const,
|
|
|
|
|
- "cmp_elem_idx"))) {
|
|
|
|
|
|
|
+ if (!(cmp_elem_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntUGE, elem_idx,
|
|
|
|
|
+ table_size_const, "cmp_elem_idx"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Throw exception if elem index >= table size */
|
|
/* Throw exception if elem index >= table size */
|
|
|
- if (!(check_elem_idx_succ =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func,
|
|
|
|
|
- "check_elem_idx_succ"))) {
|
|
|
|
|
|
|
+ if (!(check_elem_idx_succ = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "check_elem_idx_succ"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -885,8 +883,8 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
LLVMMoveBasicBlockAfter(check_elem_idx_succ,
|
|
LLVMMoveBasicBlockAfter(check_elem_idx_succ,
|
|
|
LLVMGetInsertBlock(comp_ctx->builder));
|
|
LLVMGetInsertBlock(comp_ctx->builder));
|
|
|
|
|
|
|
|
- if (!(aot_emit_exception(comp_ctx, func_ctx, EXCE_UNDEFINED_ELEMENT,
|
|
|
|
|
- true, cmp_elem_idx, check_elem_idx_succ)))
|
|
|
|
|
|
|
+ if (!(aot_emit_exception(comp_ctx, func_ctx, EXCE_UNDEFINED_ELEMENT, true,
|
|
|
|
|
+ cmp_elem_idx, check_elem_idx_succ)))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
|
|
|
|
|
/* load data as i32* */
|
|
/* load data as i32* */
|
|
@@ -909,31 +907,28 @@ 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, "table_elem"))) {
|
|
|
|
|
|
|
+ if (!(table_elem = LLVMBuildGEP(comp_ctx->builder, table_elem, &elem_idx, 1,
|
|
|
|
|
+ "table_elem"))) {
|
|
|
HANDLE_FAILURE("LLVMBuildNUWAdd");
|
|
HANDLE_FAILURE("LLVMBuildNUWAdd");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(func_idx = LLVMBuildLoad(comp_ctx->builder,
|
|
|
|
|
- table_elem, "func_idx"))) {
|
|
|
|
|
|
|
+ if (!(func_idx =
|
|
|
|
|
+ LLVMBuildLoad(comp_ctx->builder, table_elem, "func_idx"))) {
|
|
|
aot_set_last_error("llvm build load failed.");
|
|
aot_set_last_error("llvm build load failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Check if func_idx == -1 */
|
|
/* Check if func_idx == -1 */
|
|
|
- if (!(cmp_func_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ,
|
|
|
|
|
- func_idx, I32_NEG_ONE,
|
|
|
|
|
- "cmp_func_idx"))) {
|
|
|
|
|
|
|
+ if (!(cmp_func_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntEQ, func_idx,
|
|
|
|
|
+ I32_NEG_ONE, "cmp_func_idx"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Throw exception if func_idx == -1 */
|
|
/* Throw exception if func_idx == -1 */
|
|
|
- if (!(check_func_idx_succ =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func,
|
|
|
|
|
- "check_func_idx_succ"))) {
|
|
|
|
|
|
|
+ if (!(check_func_idx_succ = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "check_func_idx_succ"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -946,33 +941,29 @@ 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(comp_ctx->builder,
|
|
|
|
|
- func_ctx->func_type_indexes,
|
|
|
|
|
- &func_idx, 1,
|
|
|
|
|
- "ftype_idx_ptr"))) {
|
|
|
|
|
|
|
+ if (!(ftype_idx_ptr = LLVMBuildInBoundsGEP(
|
|
|
|
|
+ comp_ctx->builder, func_ctx->func_type_indexes, &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 = LLVMBuildLoad(comp_ctx->builder, ftype_idx_ptr,
|
|
|
|
|
- "ftype_idx"))) {
|
|
|
|
|
|
|
+ if (!(ftype_idx =
|
|
|
|
|
+ LLVMBuildLoad(comp_ctx->builder, ftype_idx_ptr, "ftype_idx"))) {
|
|
|
aot_set_last_error("llvm build load failed.");
|
|
aot_set_last_error("llvm build load failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Check if function type index not equal */
|
|
/* Check if function type index not equal */
|
|
|
- if (!(cmp_ftype_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntNE,
|
|
|
|
|
- ftype_idx, ftype_idx_const,
|
|
|
|
|
- "cmp_ftype_idx"))) {
|
|
|
|
|
|
|
+ if (!(cmp_ftype_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntNE, ftype_idx,
|
|
|
|
|
+ ftype_idx_const, "cmp_ftype_idx"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Throw exception if ftype_idx != ftype_idx_const */
|
|
/* Throw exception if ftype_idx != ftype_idx_const */
|
|
|
- if (!(check_ftype_idx_succ =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
- func_ctx->func,
|
|
|
|
|
- "check_ftype_idx_succ"))) {
|
|
|
|
|
|
|
+ if (!(check_ftype_idx_succ = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "check_ftype_idx_succ"))) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -981,17 +972,17 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
LLVMGetInsertBlock(comp_ctx->builder));
|
|
LLVMGetInsertBlock(comp_ctx->builder));
|
|
|
|
|
|
|
|
if (!(aot_emit_exception(comp_ctx, func_ctx,
|
|
if (!(aot_emit_exception(comp_ctx, func_ctx,
|
|
|
- EXCE_INVALID_FUNCTION_TYPE_INDEX,
|
|
|
|
|
- true, cmp_ftype_idx, check_ftype_idx_succ)))
|
|
|
|
|
|
|
+ EXCE_INVALID_FUNCTION_TYPE_INDEX, true,
|
|
|
|
|
+ cmp_ftype_idx, check_ftype_idx_succ)))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Initialize parameter types of the LLVM function */
|
|
/* Initialize parameter types of the LLVM function */
|
|
|
total_param_count = 1 + func_param_count;
|
|
total_param_count = 1 + func_param_count;
|
|
|
|
|
|
|
|
/* Extra function results' addresses (except the first one) are
|
|
/* Extra function results' addresses (except the first one) are
|
|
|
- * appended to aot function parameters. */
|
|
|
|
|
|
|
+ appended to aot function parameters. */
|
|
|
if (func_result_count > 1)
|
|
if (func_result_count > 1)
|
|
|
- total_param_count += func_result_count - 1;
|
|
|
|
|
|
|
+ total_param_count += func_result_count - 1;
|
|
|
|
|
|
|
|
total_size = sizeof(LLVMTypeRef) * (uint64)total_param_count;
|
|
total_size = sizeof(LLVMTypeRef) * (uint64)total_param_count;
|
|
|
if (total_size >= UINT32_MAX
|
|
if (total_size >= UINT32_MAX
|
|
@@ -1007,8 +998,7 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
param_types[j++] = TO_LLVM_TYPE(func_type->types[i]);
|
|
param_types[j++] = TO_LLVM_TYPE(func_type->types[i]);
|
|
|
|
|
|
|
|
for (i = 1; i < func_result_count; i++, j++) {
|
|
for (i = 1; i < func_result_count; i++, j++) {
|
|
|
- param_types[j] =
|
|
|
|
|
- TO_LLVM_TYPE(func_type->types[func_param_count + i]);
|
|
|
|
|
|
|
+ param_types[j] = TO_LLVM_TYPE(func_type->types[func_param_count + i]);
|
|
|
if (!(param_types[j] = LLVMPointerType(param_types[j], 0))) {
|
|
if (!(param_types[j] = LLVMPointerType(param_types[j], 0))) {
|
|
|
aot_set_last_error("llvm get pointer type failed.");
|
|
aot_set_last_error("llvm get pointer type failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
@@ -1048,25 +1038,24 @@ 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 = LLVMBuildInBoundsGEP(comp_ctx->builder,
|
|
|
|
|
- func_ctx->argv_buf,
|
|
|
|
|
- &ext_ret_offset, 1, buf))) {
|
|
|
|
|
|
|
+ if (!(ext_ret_ptr =
|
|
|
|
|
+ LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->argv_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;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ext_ret_ptr_type = param_types[func_param_count + i];
|
|
ext_ret_ptr_type = param_types[func_param_count + i];
|
|
|
snprintf(buf, sizeof(buf), "ext_ret%d_ptr_cast", i - 1);
|
|
snprintf(buf, sizeof(buf), "ext_ret%d_ptr_cast", i - 1);
|
|
|
- if (!(ext_ret_ptr = LLVMBuildBitCast(comp_ctx->builder,
|
|
|
|
|
- ext_ret_ptr, ext_ret_ptr_type,
|
|
|
|
|
- buf))) {
|
|
|
|
|
|
|
+ if (!(ext_ret_ptr = LLVMBuildBitCast(comp_ctx->builder, ext_ret_ptr,
|
|
|
|
|
+ ext_ret_ptr_type, buf))) {
|
|
|
aot_set_last_error("llvm build bit cast failed.");
|
|
aot_set_last_error("llvm build bit cast failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
param_values[func_param_count + i] = ext_ret_ptr;
|
|
param_values[func_param_count + i] = ext_ret_ptr;
|
|
|
- ext_cell_num += wasm_value_type_cell_num(
|
|
|
|
|
- func_type->types[func_param_count + i]);
|
|
|
|
|
|
|
+ ext_cell_num +=
|
|
|
|
|
+ wasm_value_type_cell_num(func_type->types[func_param_count + i]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (ext_cell_num > 64) {
|
|
if (ext_cell_num > 64) {
|
|
@@ -1091,15 +1080,12 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
/* Add basic blocks */
|
|
/* Add basic blocks */
|
|
|
- block_call_import =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context, func_ctx->func,
|
|
|
|
|
- "call_import");
|
|
|
|
|
- block_call_non_import =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context, func_ctx->func,
|
|
|
|
|
- "call_non_import");
|
|
|
|
|
- block_return =
|
|
|
|
|
- LLVMAppendBasicBlockInContext(comp_ctx->context, func_ctx->func,
|
|
|
|
|
- "func_return");
|
|
|
|
|
|
|
+ block_call_import = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "call_import");
|
|
|
|
|
+ block_call_non_import = LLVMAppendBasicBlockInContext(
|
|
|
|
|
+ comp_ctx->context, func_ctx->func, "call_non_import");
|
|
|
|
|
+ block_return = LLVMAppendBasicBlockInContext(comp_ctx->context,
|
|
|
|
|
+ func_ctx->func, "func_return");
|
|
|
if (!block_call_import || !block_call_non_import || !block_return) {
|
|
if (!block_call_import || !block_call_non_import || !block_return) {
|
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
aot_set_last_error("llvm add basic block failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
@@ -1114,17 +1100,16 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
CHECK_LLVM_CONST(import_func_count);
|
|
CHECK_LLVM_CONST(import_func_count);
|
|
|
|
|
|
|
|
/* Check if func_idx < import_func_count */
|
|
/* Check if func_idx < import_func_count */
|
|
|
- if (!(cmp_func_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT,
|
|
|
|
|
- func_idx, import_func_count,
|
|
|
|
|
- "cmp_func_idx"))) {
|
|
|
|
|
|
|
+ if (!(cmp_func_idx = LLVMBuildICmp(comp_ctx->builder, LLVMIntULT, func_idx,
|
|
|
|
|
+ import_func_count, "cmp_func_idx"))) {
|
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
aot_set_last_error("llvm build icmp failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* If func_idx < import_func_count, jump to call import block,
|
|
/* If func_idx < import_func_count, jump to call import block,
|
|
|
else jump to call non-import block */
|
|
else jump to call non-import block */
|
|
|
- if (!LLVMBuildCondBr(comp_ctx->builder, cmp_func_idx,
|
|
|
|
|
- block_call_import, block_call_non_import)) {
|
|
|
|
|
|
|
+ if (!LLVMBuildCondBr(comp_ctx->builder, cmp_func_idx, block_call_import,
|
|
|
|
|
+ block_call_non_import)) {
|
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
aot_set_last_error("llvm build cond br failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -1143,8 +1128,8 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
for (i = 0; i < func_result_count; i++) {
|
|
for (i = 0; i < func_result_count; i++) {
|
|
|
LLVMTypeRef tmp_type =
|
|
LLVMTypeRef tmp_type =
|
|
|
TO_LLVM_TYPE(func_type->types[func_param_count + i]);
|
|
TO_LLVM_TYPE(func_type->types[func_param_count + i]);
|
|
|
- if (!(result_phis[i] = LLVMBuildPhi(comp_ctx->builder,
|
|
|
|
|
- tmp_type, "phi"))) {
|
|
|
|
|
|
|
+ if (!(result_phis[i] =
|
|
|
|
|
+ LLVMBuildPhi(comp_ctx->builder, tmp_type, "phi"))) {
|
|
|
aot_set_last_error("llvm build phi failed.");
|
|
aot_set_last_error("llvm build phi failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -1174,13 +1159,10 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!call_aot_call_indirect_func(comp_ctx, func_ctx,
|
|
|
|
|
- func_type, ftype_idx,
|
|
|
|
|
- tbl_idx_value, elem_idx,
|
|
|
|
|
- param_types + 1, param_values + 1,
|
|
|
|
|
- func_param_count, param_cell_num,
|
|
|
|
|
- func_result_count, wasm_ret_types,
|
|
|
|
|
- value_rets, &res))
|
|
|
|
|
|
|
+ if (!call_aot_call_indirect_func(
|
|
|
|
|
+ comp_ctx, func_ctx, func_type, ftype_idx, tbl_idx_value, elem_idx,
|
|
|
|
|
+ param_types + 1, param_values + 1, func_param_count, param_cell_num,
|
|
|
|
|
+ func_result_count, wasm_ret_types, value_rets, &res))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Check whether exception was thrown when executing the function */
|
|
/* Check whether exception was thrown when executing the function */
|
|
@@ -1202,14 +1184,16 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
|
|
|
|
|
if (comp_ctx->enable_bound_check
|
|
if (comp_ctx->enable_bound_check
|
|
|
&& !check_stack_boundary(comp_ctx, func_ctx,
|
|
&& !check_stack_boundary(comp_ctx, func_ctx,
|
|
|
- param_cell_num + ext_cell_num + 1
|
|
|
|
|
- /* Reserve some local variables */
|
|
|
|
|
- + 16))
|
|
|
|
|
|
|
+ param_cell_num + ext_cell_num
|
|
|
|
|
+ + 1
|
|
|
|
|
+ /* Reserve some local variables */
|
|
|
|
|
+ + 16))
|
|
|
goto fail;
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Load function pointer */
|
|
/* Load function pointer */
|
|
|
- if (!(func_ptr = LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->func_ptrs,
|
|
|
|
|
- &func_idx, 1, "func_ptr_tmp"))) {
|
|
|
|
|
|
|
+ if (!(func_ptr =
|
|
|
|
|
+ LLVMBuildInBoundsGEP(comp_ctx->builder, func_ctx->func_ptrs,
|
|
|
|
|
+ &func_idx, 1, "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;
|
|
|
}
|
|
}
|
|
@@ -1219,24 +1203,22 @@ aot_compile_op_call_indirect(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(llvm_func_type = LLVMFunctionType(ret_type, param_types,
|
|
|
|
|
- total_param_count, false))
|
|
|
|
|
|
|
+ if (!(llvm_func_type =
|
|
|
|
|
+ LLVMFunctionType(ret_type, param_types, total_param_count, false))
|
|
|
|| !(llvm_func_ptr_type = LLVMPointerType(llvm_func_type, 0))) {
|
|
|| !(llvm_func_ptr_type = LLVMPointerType(llvm_func_type, 0))) {
|
|
|
aot_set_last_error("llvm add function type failed.");
|
|
aot_set_last_error("llvm add function type failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(func = LLVMBuildBitCast(comp_ctx->builder,
|
|
|
|
|
- func_ptr, llvm_func_ptr_type,
|
|
|
|
|
- "indirect_func"))) {
|
|
|
|
|
|
|
+ if (!(func = LLVMBuildBitCast(comp_ctx->builder, func_ptr,
|
|
|
|
|
+ llvm_func_ptr_type, "indirect_func"))) {
|
|
|
aot_set_last_error("llvm build bit cast failed.");
|
|
aot_set_last_error("llvm build bit cast failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!(value_ret = LLVMBuildCall(comp_ctx->builder, func,
|
|
|
|
|
- param_values, total_param_count,
|
|
|
|
|
- func_result_count > 0
|
|
|
|
|
- ? "ret" : ""))) {
|
|
|
|
|
|
|
+ if (!(value_ret = LLVMBuildCall(comp_ctx->builder, func, param_values,
|
|
|
|
|
+ total_param_count,
|
|
|
|
|
+ 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;
|
|
|
}
|
|
}
|
|
@@ -1254,9 +1236,9 @@ 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++) {
|
|
|
snprintf(buf, sizeof(buf), "ext_ret%d", i - 1);
|
|
snprintf(buf, sizeof(buf), "ext_ret%d", i - 1);
|
|
|
- if (!(ext_ret = LLVMBuildLoad(comp_ctx->builder,
|
|
|
|
|
- param_values[func_param_count + i],
|
|
|
|
|
- buf))) {
|
|
|
|
|
|
|
+ if (!(ext_ret =
|
|
|
|
|
+ LLVMBuildLoad(comp_ctx->builder,
|
|
|
|
|
+ param_values[func_param_count + i], buf))) {
|
|
|
aot_set_last_error("llvm build load failed.");
|
|
aot_set_last_error("llvm build load failed.");
|
|
|
goto fail;
|
|
goto fail;
|
|
|
}
|
|
}
|
|
@@ -1333,8 +1315,7 @@ fail:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
bool
|
|
|
-aot_compile_op_ref_func(AOTCompContext *comp_ctx,
|
|
|
|
|
- AOTFuncContext *func_ctx,
|
|
|
|
|
|
|
+aot_compile_op_ref_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
|
|
|
uint32 func_idx)
|
|
uint32 func_idx)
|
|
|
{
|
|
{
|
|
|
LLVMValueRef ref_idx;
|
|
LLVMValueRef ref_idx;
|