@@ -1526,60 +1526,87 @@ create_memory_info(const AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
15261526 func_ctx->aot_inst, &offset, 1, \
15271527 #field "_p"))) { \
15281528 aot_set_last_error("llvm build inbounds gep failed"); \
1529- return false; \
1529+ goto fail; \
15301530 } \
15311531 if (!(load_val = \
15321532 LLVMBuildLoad2(comp_ctx->builder, type, field_p, #field))) { \
15331533 aot_set_last_error("llvm build load failed"); \
1534- return false; \
1534+ goto fail; \
15351535 } \
15361536 if (!(func_ctx->field = \
15371537 LLVMBuildAlloca(comp_ctx->builder, type, #field))) { \
15381538 aot_set_last_error("llvm build alloca failed"); \
1539- return false; \
1539+ goto fail; \
15401540 } \
15411541 if (!LLVMBuildStore(comp_ctx->builder, load_val, func_ctx->field)) { \
15421542 aot_set_last_error("llvm build store failed"); \
1543- return false; \
1544- } \
1545- } while (0)
1546-
1547- #define LOAD_MODULE_EXTRA_FIELD (field , type ) \
1548- do { \
1549- get_module_extra_field_offset(field); \
1550- offset = I32_CONST(offset_u32); \
1551- CHECK_LLVM_CONST(offset); \
1552- if (!(field_p = LLVMBuildInBoundsGEP2(comp_ctx->builder, INT8_TYPE, \
1553- func_ctx->aot_inst, &offset, 1, \
1554- #field "_p"))) { \
1555- aot_set_last_error("llvm build inbounds gep failed"); \
1556- return false; \
1557- } \
1558- if (!(func_ctx->field = \
1559- LLVMBuildLoad2(comp_ctx->builder, type, field_p, #field))) { \
1560- aot_set_last_error("llvm build load failed"); \
1561- return false; \
1543+ goto fail; \
15621544 } \
15631545 } while (0)
15641546
15651547static bool
15661548create_shared_heap_info (AOTCompContext * comp_ctx , AOTFuncContext * func_ctx )
15671549{
1568- LLVMValueRef offset , field_p , load_val ;
1550+ LLVMValueRef offset , field_p , load_val , shared_heap_head_p ,
1551+ shared_heap_head ;
1552+ LLVMTypeRef shared_heap_offset_type ;
15691553 uint32 offset_u32 ;
1554+ #if WASM_ENABLE_MEMORY64 == 0
1555+ bool is_memory64 = false;
1556+ #else
1557+ bool is_memory64 = IS_MEMORY64 ;
1558+ #endif
15701559
1571- /* shared_heap_base_addr_adj, shared_heap_start_off, and shared_heap_end_off
1572- * can be updated later, use local variable to represent them */
1560+ shared_heap_offset_type =
1561+ comp_ctx -> pointer_size == sizeof (uint64 ) ? I64_TYPE : I32_TYPE ;
1562+
1563+ /* shared_heap_base_addr_adj, shared_heap_start_off, and
1564+ * shared_heap_end_off can be updated later, use local variable to
1565+ * represent them */
15731566 LOAD_MODULE_EXTRA_FIELD_AND_ALLOCA (shared_heap_base_addr_adj ,
15741567 INT8_PTR_TYPE );
1575- LOAD_MODULE_EXTRA_FIELD_AND_ALLOCA (
1576- shared_heap_start_off ,
1577- comp_ctx -> pointer_size == sizeof (uint64 ) ? I64_TYPE : I32_TYPE );
1578- LOAD_MODULE_EXTRA_FIELD_AND_ALLOCA (
1579- shared_heap_end_off ,
1580- comp_ctx -> pointer_size == sizeof (uint64 ) ? I64_TYPE : I32_TYPE );
1581- /* Shared Heap won't be updated, no need to alloca */
1582- LOAD_MODULE_EXTRA_FIELD (shared_heap , INT8_PTR_TYPE );
1568+ LOAD_MODULE_EXTRA_FIELD_AND_ALLOCA (shared_heap_start_off ,
1569+ shared_heap_offset_type );
1570+ LOAD_MODULE_EXTRA_FIELD_AND_ALLOCA (shared_heap_end_off ,
1571+ shared_heap_offset_type );
1572+
1573+ /* Shared Heap head start off won't be updated, no need to alloca */
1574+ get_module_extra_field_offset (shared_heap );
1575+ offset = I32_CONST (offset_u32 );
1576+ CHECK_LLVM_CONST (offset );
1577+ if (!(shared_heap_head_p = LLVMBuildInBoundsGEP2 (
1578+ comp_ctx -> builder , INT8_TYPE , func_ctx -> aot_inst , & offset , 1 ,
1579+ "shared_heap_head_p" ))) {
1580+ aot_set_last_error ("llvm build inbounds gep failed" );
1581+ goto fail ;
1582+ }
1583+ if (!(shared_heap_head =
1584+ LLVMBuildLoad2 (comp_ctx -> builder , INT8_PTR_TYPE ,
1585+ shared_heap_head_p , "shared_heap_head" ))) {
1586+ aot_set_last_error ("llvm build load failed" );
1587+ goto fail ;
1588+ }
1589+
1590+ if (is_memory64 ) {
1591+ offset_u32 = offsetof(WASMSharedHeap , start_off_mem64 );
1592+ }
1593+ else {
1594+ offset_u32 = offsetof(WASMSharedHeap , start_off_mem32 );
1595+ }
1596+ offset = I32_CONST (offset_u32 );
1597+ CHECK_LLVM_CONST (offset );
1598+ if (!(field_p = LLVMBuildInBoundsGEP2 (comp_ctx -> builder , INT8_TYPE ,
1599+ shared_heap_head , & offset , 1 ,
1600+ "head_start_off_p" ))) {
1601+ aot_set_last_error ("llvm build inbounds gep failed" );
1602+ goto fail ;
1603+ }
1604+ if (!(func_ctx -> shared_heap_head_start_off =
1605+ LLVMBuildLoad2 (comp_ctx -> builder , shared_heap_offset_type ,
1606+ field_p , "shared_heap_head_start_off" ))) {
1607+ aot_set_last_error ("llvm build load failed" );
1608+ goto fail ;
1609+ }
15831610
15841611 return true;
15851612fail :
@@ -2438,7 +2465,7 @@ jit_stack_size_callback(void *user_data, const char *name, size_t namelen,
24382465 stack_consumption_to_call_wrapped_func =
24392466 musttail ? 0
24402467 : aot_estimate_stack_usage_for_function_call (
2441- comp_ctx , func_ctx -> aot_func -> func_type );
2468+ comp_ctx , func_ctx -> aot_func -> func_type );
24422469 LOG_VERBOSE ("func %.*s stack %u + %zu + %u" , (int )namelen , name ,
24432470 stack_consumption_to_call_wrapped_func , stack_size , call_size );
24442471
0 commit comments