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)
This commit is contained in:
YAMAMOTO Takashi 2025-04-28 17:43:53 +09:00 committed by GitHub
parent 6593b3f347
commit 84767f9121
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 4 deletions

View File

@ -711,8 +711,7 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
prefix)))
goto fail;
if (comp_ctx->is_indirect_mode) {
/* avoid LUT relocations ("switch-table") */
if (comp_ctx->disable_llvm_jump_tables) {
LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute(
comp_ctx->context, "no-jump-tables",
(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)
if (option->enable_aux_stack_check)
comp_ctx->enable_aux_stack_check = true;
if (option->is_indirect_mode)
if (option->is_indirect_mode) {
comp_ctx->is_indirect_mode = true;
/* avoid LUT relocations ("switch-table") */
comp_ctx->disable_llvm_jump_tables = true;
}
if (option->disable_llvm_intrinsics)
comp_ctx->disable_llvm_intrinsics = true;
if (option->disable_llvm_jump_tables)
comp_ctx->disable_llvm_jump_tables = true;
if (option->disable_llvm_lto)
comp_ctx->disable_llvm_lto = true;

View File

@ -448,6 +448,9 @@ typedef struct AOTCompContext {
/* Disable LLVM built-in intrinsics */
bool disable_llvm_intrinsics;
/* Disable LLVM jump tables */
bool disable_llvm_jump_tables;
/* Disable LLVM link time optimization */
bool disable_llvm_lto;

View File

@ -73,6 +73,7 @@ typedef struct AOTCompOption {
bool enable_perf_profiling;
bool enable_memory_profiling;
bool disable_llvm_intrinsics;
bool disable_llvm_jump_tables;
bool disable_llvm_lto;
bool enable_llvm_pgo;
bool enable_stack_estimation;
@ -96,4 +97,4 @@ typedef struct AOTCompOption {
}
#endif
#endif /* end of __AOT_COMP_OPTION_H__ */
#endif /* end of __AOT_COMP_OPTION_H__ */

View File

@ -180,6 +180,7 @@ print_help()
printf(" Available flags: all, i32.common, i64.common, f32.common, f64.common,\n");
printf(" i32.clz, i32.ctz, etc, refer to doc/xip.md for full list\n");
printf(" Use comma to separate, please refer to doc/xip.md for full list.\n");
printf(" --disable-llvm-jump-tables Disable the LLVM jump tables similarly to clang's -fno-jump-tables\n");
printf(" --disable-llvm-lto Disable the LLVM link time optimization\n");
printf(" --enable-llvm-pgo Enable LLVM PGO (Profile-Guided Optimization)\n");
printf(" --enable-llvm-passes=<passes>\n");
@ -570,6 +571,9 @@ main(int argc, char *argv[])
PRINT_HELP_AND_EXIT();
option.builtin_intrinsics = argv[0] + 28;
}
else if (!strcmp(argv[0], "--disable-llvm-jump-tables")) {
option.disable_llvm_jump_tables = true;
}
else if (!strcmp(argv[0], "--disable-llvm-lto")) {
option.disable_llvm_lto = true;
}