refactoring: Re-use commit IP functionality between exception handling and other cases (#3768)

This commit is contained in:
Marcin Kolny
2024-09-05 09:18:47 +01:00
committed by GitHub
parent 65521b188d
commit b4380fb3b1
3 changed files with 54 additions and 66 deletions

View File

@ -4,49 +4,10 @@
*/
#include "aot_emit_exception.h"
#include "aot_compiler.h"
#include "../interpreter/wasm_runtime.h"
#include "../aot/aot_runtime.h"
static bool
commit_ip(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
LLVMValueRef exce_ip, bool is_64bit)
{
LLVMValueRef cur_frame = func_ctx->cur_frame;
LLVMValueRef value_offset, value_addr, value_ptr;
uint32 offset_ip;
if (!comp_ctx->is_jit_mode)
offset_ip = comp_ctx->pointer_size * 4;
else
offset_ip = offsetof(WASMInterpFrame, ip);
if (!(value_offset = I32_CONST(offset_ip))) {
aot_set_last_error("llvm build const failed");
return false;
}
if (!(value_addr =
LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, cur_frame,
&value_offset, 1, "ip_addr"))) {
aot_set_last_error("llvm build in bounds gep failed");
return false;
}
if (!(value_ptr = LLVMBuildBitCast(
comp_ctx->builder, value_addr,
is_64bit ? INT64_PTR_TYPE : INT32_PTR_TYPE, "ip_ptr"))) {
aot_set_last_error("llvm build bit cast failed");
return false;
}
if (!LLVMBuildStore(comp_ctx->builder, exce_ip, value_ptr)) {
aot_set_last_error("llvm build store failed");
return false;
}
return true;
}
bool
aot_emit_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
int32 exception_id, bool is_cond_br, LLVMValueRef cond_br_if,
@ -90,8 +51,8 @@ aot_emit_exception(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
}
/* Commit ip to current frame */
if (!commit_ip(comp_ctx, func_ctx, func_ctx->exception_ip_phi,
is_64bit)) {
if (!aot_gen_commit_ip(comp_ctx, func_ctx,
func_ctx->exception_ip_phi, is_64bit)) {
return false;
}
}