@@ -569,6 +569,46 @@ aot_gen_commit_values(AOTCompFrame *frame)
569569 return true;
570570}
571571
572+ bool
573+ aot_gen_commit_ip (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx ,
574+ LLVMValueRef ip_value , bool is_64bit )
575+ {
576+ LLVMValueRef cur_frame = func_ctx -> cur_frame ;
577+ LLVMValueRef value_offset , value_addr , value_ptr ;
578+ uint32 offset_ip ;
579+
580+ if (!comp_ctx -> is_jit_mode )
581+ offset_ip = comp_ctx -> pointer_size * 4 ;
582+ else
583+ offset_ip = offsetof(WASMInterpFrame , ip );
584+
585+ if (!(value_offset = I32_CONST (offset_ip ))) {
586+ aot_set_last_error ("llvm build const failed" );
587+ return false;
588+ }
589+
590+ if (!(value_addr =
591+ LLVMBuildInBoundsGEP2 (comp_ctx -> builder , INT8_TYPE , cur_frame ,
592+ & value_offset , 1 , "ip_addr" ))) {
593+ aot_set_last_error ("llvm build in bounds gep failed" );
594+ return false;
595+ }
596+
597+ if (!(value_ptr = LLVMBuildBitCast (
598+ comp_ctx -> builder , value_addr ,
599+ is_64bit ? INT64_PTR_TYPE : INT32_PTR_TYPE , "ip_ptr" ))) {
600+ aot_set_last_error ("llvm build bit cast failed" );
601+ return false;
602+ }
603+
604+ if (!LLVMBuildStore (comp_ctx -> builder , ip_value , value_ptr )) {
605+ aot_set_last_error ("llvm build store failed" );
606+ return false;
607+ }
608+
609+ return true;
610+ }
611+
572612bool
573613aot_gen_commit_sp_ip (AOTCompFrame * frame , bool commit_sp , bool commit_ip )
574614{
@@ -577,40 +617,19 @@ aot_gen_commit_sp_ip(AOTCompFrame *frame, bool commit_sp, bool commit_ip)
577617 LLVMValueRef cur_frame = func_ctx -> cur_frame ;
578618 LLVMValueRef value_offset , value_addr , value_ptr , value ;
579619 LLVMTypeRef int8_ptr_ptr_type ;
580- uint32 offset_ip , offset_sp , n ;
620+ uint32 offset_sp , n ;
581621 bool is_64bit = (comp_ctx -> pointer_size == sizeof (uint64 )) ? true : false;
582622 const AOTValueSlot * sp = frame -> sp ;
583623 const uint8 * ip = frame -> frame_ip ;
584624
585625 if (!comp_ctx -> is_jit_mode ) {
586- offset_ip = frame -> comp_ctx -> pointer_size * 4 ;
587626 offset_sp = frame -> comp_ctx -> pointer_size * 5 ;
588627 }
589628 else {
590- offset_ip = offsetof(WASMInterpFrame , ip );
591629 offset_sp = offsetof(WASMInterpFrame , sp );
592630 }
593631
594632 if (commit_ip ) {
595- if (!(value_offset = I32_CONST (offset_ip ))) {
596- aot_set_last_error ("llvm build const failed" );
597- return false;
598- }
599-
600- if (!(value_addr =
601- LLVMBuildInBoundsGEP2 (comp_ctx -> builder , INT8_TYPE , cur_frame ,
602- & value_offset , 1 , "ip_addr" ))) {
603- aot_set_last_error ("llvm build in bounds gep failed" );
604- return false;
605- }
606-
607- if (!(value_ptr = LLVMBuildBitCast (
608- comp_ctx -> builder , value_addr ,
609- is_64bit ? INT64_PTR_TYPE : INT32_PTR_TYPE , "ip_ptr" ))) {
610- aot_set_last_error ("llvm build bit cast failed" );
611- return false;
612- }
613-
614633 if (!comp_ctx -> is_jit_mode ) {
615634 WASMModule * module = comp_ctx -> comp_data -> wasm_module ;
616635 if (is_64bit )
@@ -630,8 +649,7 @@ aot_gen_commit_sp_ip(AOTCompFrame *frame, bool commit_sp, bool commit_ip)
630649 return false;
631650 }
632651
633- if (!LLVMBuildStore (comp_ctx -> builder , value , value_ptr )) {
634- aot_set_last_error ("llvm build store failed" );
652+ if (!aot_gen_commit_ip (comp_ctx , func_ctx , value , is_64bit )) {
635653 return false;
636654 }
637655 }
0 commit comments