Skip to content

Commit 84767f9

Browse files
authored
wamrc: add --disable-llvm-jump-tables option (#4224)
while ideally a user should not need to care this kind of optimization details, in reality i guess it's sometimes useful. both of clang and GCC expose a similar option. (-fno-jump-tables)
1 parent 6593b3f commit 84767f9

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

core/iwasm/compilation/aot_llvm.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,7 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
711711
prefix)))
712712
goto fail;
713713

714-
if (comp_ctx->is_indirect_mode) {
715-
/* avoid LUT relocations ("switch-table") */
714+
if (comp_ctx->disable_llvm_jump_tables) {
716715
LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute(
717716
comp_ctx->context, "no-jump-tables",
718717
(uint32)strlen("no-jump-tables"), "true", (uint32)strlen("true"));
@@ -2664,12 +2663,18 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
26642663
if (option->enable_aux_stack_check)
26652664
comp_ctx->enable_aux_stack_check = true;
26662665

2667-
if (option->is_indirect_mode)
2666+
if (option->is_indirect_mode) {
26682667
comp_ctx->is_indirect_mode = true;
2668+
/* avoid LUT relocations ("switch-table") */
2669+
comp_ctx->disable_llvm_jump_tables = true;
2670+
}
26692671

26702672
if (option->disable_llvm_intrinsics)
26712673
comp_ctx->disable_llvm_intrinsics = true;
26722674

2675+
if (option->disable_llvm_jump_tables)
2676+
comp_ctx->disable_llvm_jump_tables = true;
2677+
26732678
if (option->disable_llvm_lto)
26742679
comp_ctx->disable_llvm_lto = true;
26752680

core/iwasm/compilation/aot_llvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ typedef struct AOTCompContext {
448448
/* Disable LLVM built-in intrinsics */
449449
bool disable_llvm_intrinsics;
450450

451+
/* Disable LLVM jump tables */
452+
bool disable_llvm_jump_tables;
453+
451454
/* Disable LLVM link time optimization */
452455
bool disable_llvm_lto;
453456

core/iwasm/include/aot_comp_option.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef struct AOTCompOption {
7373
bool enable_perf_profiling;
7474
bool enable_memory_profiling;
7575
bool disable_llvm_intrinsics;
76+
bool disable_llvm_jump_tables;
7677
bool disable_llvm_lto;
7778
bool enable_llvm_pgo;
7879
bool enable_stack_estimation;
@@ -96,4 +97,4 @@ typedef struct AOTCompOption {
9697
}
9798
#endif
9899

99-
#endif /* end of __AOT_COMP_OPTION_H__ */
100+
#endif /* end of __AOT_COMP_OPTION_H__ */

wamr-compiler/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ print_help()
180180
printf(" Available flags: all, i32.common, i64.common, f32.common, f64.common,\n");
181181
printf(" i32.clz, i32.ctz, etc, refer to doc/xip.md for full list\n");
182182
printf(" Use comma to separate, please refer to doc/xip.md for full list.\n");
183+
printf(" --disable-llvm-jump-tables Disable the LLVM jump tables similarly to clang's -fno-jump-tables\n");
183184
printf(" --disable-llvm-lto Disable the LLVM link time optimization\n");
184185
printf(" --enable-llvm-pgo Enable LLVM PGO (Profile-Guided Optimization)\n");
185186
printf(" --enable-llvm-passes=<passes>\n");
@@ -570,6 +571,9 @@ main(int argc, char *argv[])
570571
PRINT_HELP_AND_EXIT();
571572
option.builtin_intrinsics = argv[0] + 28;
572573
}
574+
else if (!strcmp(argv[0], "--disable-llvm-jump-tables")) {
575+
option.disable_llvm_jump_tables = true;
576+
}
573577
else if (!strcmp(argv[0], "--disable-llvm-lto")) {
574578
option.disable_llvm_lto = true;
575579
}

0 commit comments

Comments
 (0)