Skip to content

Commit 62fc486

Browse files
authored
Refine aot compiler check suspend_flags and fix issue of multi-tier jit (#2111)
In LLVM AOT/JIT compiler, only need to check the suspend_flags when memory is a shared memory since the shared memory must be enabled for multi-threading, so as not to impact the performance in non-multi-threading memory mode. Also refine the LLVM IRs to check the suspend_flags. And fix an issue of multi-tier jit for multi-threading, the instance of the child thread should be removed from the instance list before it is de-instantiated.
1 parent 9adc694 commit 62fc486

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

core/iwasm/compilation/aot_emit_control.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,16 @@ bool
671671
check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
672672
{
673673
LLVMValueRef terminate_addr, terminate_flags, flag, offset, res;
674-
LLVMBasicBlockRef terminate_check_block, non_terminate_block;
674+
LLVMBasicBlockRef terminate_block, non_terminate_block;
675675
AOTFuncType *aot_func_type = func_ctx->aot_func->func_type;
676-
LLVMBasicBlockRef terminate_block;
676+
bool is_shared_memory =
677+
comp_ctx->comp_data->memories[0].memory_flags & 0x02 ? true : false;
678+
679+
/* Only need to check the suspend flags when memory is shared since
680+
shared memory must be enabled for multi-threading */
681+
if (!is_shared_memory) {
682+
return true;
683+
}
677684

678685
/* Offset of suspend_flags */
679686
offset = I32_FIVE;
@@ -701,29 +708,20 @@ check_suspend_flags(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
701708
will always be loaded from memory rather than register */
702709
LLVMSetVolatile(terminate_flags, true);
703710

704-
CREATE_BLOCK(terminate_check_block, "terminate_check");
705-
MOVE_BLOCK_AFTER_CURR(terminate_check_block);
711+
if (!(flag = LLVMBuildAnd(comp_ctx->builder, terminate_flags, I32_ONE,
712+
"termination_flag"))) {
713+
aot_set_last_error("llvm build AND failed");
714+
return false;
715+
}
706716

707717
CREATE_BLOCK(non_terminate_block, "non_terminate");
708718
MOVE_BLOCK_AFTER_CURR(non_terminate_block);
709719

710-
BUILD_ICMP(LLVMIntSGT, terminate_flags, I32_ZERO, res, "need_terminate");
711-
BUILD_COND_BR(res, terminate_check_block, non_terminate_block);
712-
713-
/* Move builder to terminate check block */
714-
SET_BUILDER_POS(terminate_check_block);
715-
716720
CREATE_BLOCK(terminate_block, "terminate");
717721
MOVE_BLOCK_AFTER_CURR(terminate_block);
718722

719-
if (!(flag = LLVMBuildAnd(comp_ctx->builder, terminate_flags, I32_ONE,
720-
"termination_flag"))) {
721-
aot_set_last_error("llvm build AND failed");
722-
return false;
723-
}
724-
725-
BUILD_ICMP(LLVMIntSGT, flag, I32_ZERO, res, "need_terminate");
726-
BUILD_COND_BR(res, terminate_block, non_terminate_block);
723+
BUILD_ICMP(LLVMIntEQ, flag, I32_ZERO, res, "flag_terminate");
724+
BUILD_COND_BR(res, non_terminate_block, terminate_block);
727725

728726
/* Move builder to terminate block */
729727
SET_BUILDER_POS(terminate_block);

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst)
21782178
func_ptrs and fast_jit_func_ptrs of the instance, to avoid
21792179
accessing the freed memory in the jit backend compilation
21802180
threads */
2181-
if (!is_sub_inst) {
2181+
{
21822182
WASMModule *module = module_inst->module;
21832183
WASMModuleInstance *instance_prev = NULL, *instance;
21842184
os_mutex_lock(&module->instance_list_lock);

0 commit comments

Comments
 (0)