@@ -278,36 +278,47 @@ aot_check_shared_heap_memory_overflow_common(
278278 /* On 64/32-bit target, the offset is 64/32-bit */
279279 offset_type = is_target_64bit ? I64_TYPE : I32_TYPE ;
280280
281- ADD_BASIC_BLOCK (app_addr_in_shared_heap_chain ,
282- "app_addr_in_shared_heap_chain" );
283281 ADD_BASIC_BLOCK (app_addr_in_cache_shared_heap ,
284282 "app_addr_in_cache_shared_heap" );
285- ADD_BASIC_BLOCK (check_shared_heap_chain , "check_shared_heap_chain" );
286283 ADD_BASIC_BLOCK (app_addr_in_linear_mem , "app_addr_in_linear_mem" );
287284
288- LLVMMoveBasicBlockAfter (app_addr_in_shared_heap_chain , block_curr );
289- LLVMMoveBasicBlockAfter (app_addr_in_cache_shared_heap ,
290- app_addr_in_shared_heap_chain );
291- LLVMMoveBasicBlockAfter (check_shared_heap_chain ,
292- app_addr_in_cache_shared_heap );
293- LLVMMoveBasicBlockAfter (app_addr_in_linear_mem ,
294- app_addr_in_cache_shared_heap );
285+ if (comp_ctx -> enable_shared_heap ) {
286+ LLVMMoveBasicBlockAfter (app_addr_in_cache_shared_heap , block_curr );
287+ LLVMMoveBasicBlockAfter (app_addr_in_linear_mem ,
288+ app_addr_in_cache_shared_heap );
289+ }
290+ else if (comp_ctx -> enable_shared_chain ) {
291+ ADD_BASIC_BLOCK (app_addr_in_shared_heap_chain ,
292+ "app_addr_in_shared_heap_chain" );
293+ ADD_BASIC_BLOCK (check_shared_heap_chain , "check_shared_heap_chain" );
294+ LLVMMoveBasicBlockAfter (app_addr_in_shared_heap_chain , block_curr );
295+ LLVMMoveBasicBlockAfter (app_addr_in_cache_shared_heap ,
296+ app_addr_in_shared_heap_chain );
297+ LLVMMoveBasicBlockAfter (check_shared_heap_chain ,
298+ app_addr_in_cache_shared_heap );
299+ LLVMMoveBasicBlockAfter (app_addr_in_linear_mem ,
300+ app_addr_in_cache_shared_heap );
301+ }
295302
296303 if (!bulk_memory )
297304 LLVMMoveBasicBlockAfter (block_maddr_phi , app_addr_in_linear_mem );
298305 else
299306 LLVMMoveBasicBlockAfter (block_maddr_phi , check_succ );
300307
301- /* Use >= here for func_ctx->shared_heap_head_start_off =
302- * shared_heap_head->start - 1 and use UINT32_MAX/UINT64_MAX value to
303- * indicate invalid value. The shared heap chain oob will be detected in
304- * app_addr_in_shared_heap block or aot_check_shared_heap_chain function */
305- BUILD_ICMP (LLVMIntUGT , start_offset , func_ctx -> shared_heap_head_start_off ,
306- is_in_shared_heap , "shared_heap_lb_cmp" );
307- BUILD_COND_BR (is_in_shared_heap , app_addr_in_shared_heap_chain ,
308- app_addr_in_linear_mem );
308+ if (comp_ctx -> enable_shared_chain ) {
309+ /* Use >= here for func_ctx->shared_heap_head_start_off =
310+ * shared_heap_head->start - 1 and use UINT32_MAX/UINT64_MAX value to
311+ * indicate invalid value. The shared heap chain oob will be detected in
312+ * app_addr_in_shared_heap block or aot_check_shared_heap_chain function
313+ */
314+ BUILD_ICMP (LLVMIntUGT , start_offset ,
315+ func_ctx -> shared_heap_head_start_off , is_in_shared_heap ,
316+ "shared_heap_lb_cmp" );
317+ BUILD_COND_BR (is_in_shared_heap , app_addr_in_shared_heap_chain ,
318+ app_addr_in_linear_mem );
309319
310- SET_BUILD_POS (app_addr_in_shared_heap_chain );
320+ SET_BUILD_POS (app_addr_in_shared_heap_chain );
321+ }
311322 /* Load the local variable of the function */
312323 BUILD_LOAD_PTR (func_ctx -> shared_heap_start_off , offset_type ,
313324 shared_heap_start_off );
@@ -334,17 +345,24 @@ aot_check_shared_heap_memory_overflow_common(
334345 "cmp_cache_shared_heap_end" );
335346 }
336347 BUILD_OP (And , cmp , cmp1 , cmp2 , "is_in_cache_shared_heap" );
337- BUILD_COND_BR (cmp2 , app_addr_in_cache_shared_heap , check_shared_heap_chain );
338-
339- SET_BUILD_POS (check_shared_heap_chain );
340- if (!bulk_memory ) {
341- bytes = is_target_64bit ? I64_CONST (bytes_u32 ) : I32_CONST (bytes_u32 );
342- }
343- if (!aot_check_shared_heap_chain (comp_ctx , func_ctx ,
344- app_addr_in_cache_shared_heap ,
345- start_offset , bytes , is_memory64 )) {
346- aot_set_last_error ("llvm build aot_check_shared_heap_chain failed" );
347- goto fail ;
348+ if (comp_ctx -> enable_shared_heap ) {
349+ BUILD_COND_BR (cmp2 , app_addr_in_cache_shared_heap ,
350+ app_addr_in_linear_mem );
351+ }
352+ else if (comp_ctx -> enable_shared_chain ) {
353+ BUILD_COND_BR (cmp2 , app_addr_in_cache_shared_heap ,
354+ check_shared_heap_chain );
355+ SET_BUILD_POS (check_shared_heap_chain );
356+ if (!bulk_memory ) {
357+ bytes =
358+ is_target_64bit ? I64_CONST (bytes_u32 ) : I32_CONST (bytes_u32 );
359+ }
360+ if (!aot_check_shared_heap_chain (comp_ctx , func_ctx ,
361+ app_addr_in_cache_shared_heap ,
362+ start_offset , bytes , is_memory64 )) {
363+ aot_set_last_error ("llvm build aot_check_shared_heap_chain failed" );
364+ goto fail ;
365+ }
348366 }
349367
350368 SET_BUILD_POS (app_addr_in_cache_shared_heap );
@@ -617,7 +635,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
617635 }
618636
619637#if WASM_ENABLE_SHARED_HEAP != 0
620- if (comp_ctx -> enable_shared_heap /* TODO: && mem_idx == 0 */ ) {
638+ if (comp_ctx -> enable_shared_heap
639+ || comp_ctx -> enable_shared_chain /* TODO: && mem_idx == 0 */ ) {
621640 ADD_BASIC_BLOCK (block_maddr_phi , "maddr_phi" );
622641 SET_BUILD_POS (block_maddr_phi );
623642 if (!(maddr_phi =
@@ -716,7 +735,8 @@ aot_check_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
716735 }
717736
718737#if WASM_ENABLE_SHARED_HEAP != 0
719- if (comp_ctx -> enable_shared_heap /* TODO: && mem_idx == 0 */ ) {
738+ if (comp_ctx -> enable_shared_heap
739+ || comp_ctx -> enable_shared_chain /* TODO: && mem_idx == 0 */ ) {
720740 block_curr = LLVMGetInsertBlock (comp_ctx -> builder );
721741 LLVMAddIncoming (maddr_phi , & maddr , & block_curr , 1 );
722742 if (!LLVMBuildBr (comp_ctx -> builder , block_maddr_phi )) {
@@ -1465,7 +1485,8 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
14651485 }
14661486
14671487#if WASM_ENABLE_SHARED_HEAP != 0
1468- if (comp_ctx -> enable_shared_heap /* TODO: && mem_idx == 0 */ ) {
1488+ if (comp_ctx -> enable_shared_heap
1489+ || comp_ctx -> enable_shared_chain /* TODO: && mem_idx == 0 */ ) {
14691490 ADD_BASIC_BLOCK (block_maddr_phi , "maddr_phi" );
14701491 SET_BUILD_POS (block_maddr_phi );
14711492 if (!(maddr_phi = LLVMBuildPhi (comp_ctx -> builder , INT8_PTR_TYPE ,
@@ -1507,7 +1528,8 @@ check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx,
15071528 }
15081529
15091530#if WASM_ENABLE_SHARED_HEAP != 0
1510- if (comp_ctx -> enable_shared_heap /* TODO: && mem_idx == 0 */ ) {
1531+ if (comp_ctx -> enable_shared_heap
1532+ || comp_ctx -> enable_shared_chain /* TODO: && mem_idx == 0 */ ) {
15111533 block_curr = LLVMGetInsertBlock (comp_ctx -> builder );
15121534 LLVMAddIncoming (maddr_phi , & maddr , & block_curr , 1 );
15131535 if (!LLVMBuildBr (comp_ctx -> builder , block_maddr_phi )) {
0 commit comments