Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new option to wamrc for customizing LLVM passes #2335

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option)
if (option->enable_stack_estimation)
comp_ctx->enable_stack_estimation = true;

if (option->llvm_passes)
comp_ctx->llvm_passes = option->llvm_passes;

comp_ctx->opt_level = option->opt_level;
comp_ctx->size_level = option->size_level;

Expand Down
2 changes: 2 additions & 0 deletions core/iwasm/compilation/aot_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ typedef struct AOTCompContext {

const char *stack_usage_file;
char stack_usage_temp_file[64];
const char *llvm_passes;
} AOTCompContext;

enum {
Expand Down Expand Up @@ -455,6 +456,7 @@ typedef struct AOTCompOption {
char **custom_sections;
uint32 custom_sections_count;
const char *stack_usage_file;
const char *llvm_passes;
} AOTCompOption, *aot_comp_option_t;

bool
Expand Down
4 changes: 4 additions & 0 deletions core/iwasm/compilation/aot_llvm_extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ aot_apply_llvm_new_pass_manager(AOTCompContext *comp_ctx, LLVMModuleRef module)

MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));

if (comp_ctx->llvm_passes) {
ExitOnErr(PB.parsePassPipeline(MPM, comp_ctx->llvm_passes));
}

if (!disable_llvm_lto) {
/* Apply LTO for AOT mode */
if (comp_ctx->comp_data->func_count >= 10
Expand Down
1 change: 1 addition & 0 deletions core/iwasm/include/aot_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef struct AOTCompOption {
char **custom_sections;
uint32_t custom_sections_count;
const char *stack_usage_file;
const char *llvm_passes;
} AOTCompOption, *aot_comp_option_t;

bool
Expand Down
7 changes: 7 additions & 0 deletions wamr-compiler/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ print_help()
printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\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");
printf(" Enable the specified LLVM passes, using comma to separate\n");
printf(" --use-prof-file=<file> Use profile file collected by LLVM PGO (Profile-Guided Optimization)\n");
printf(" --enable-segue[=<flags>] Enable using segment register GS as the base address of linear memory,\n");
printf(" only available on linux/linux-sgx x86-64, which may improve performance,\n");
Expand Down Expand Up @@ -337,6 +339,11 @@ main(int argc, char *argv[])
else if (!strcmp(argv[0], "--enable-llvm-pgo")) {
option.enable_llvm_pgo = true;
}
else if (!strncmp(argv[0], "--enable-llvm-passes=", 21)) {
if (argv[0][21] == '\0')
PRINT_HELP_AND_EXIT();
option.llvm_passes = argv[0] + 21;
}
else if (!strncmp(argv[0], "--use-prof-file=", 16)) {
if (argv[0][16] == '\0')
PRINT_HELP_AND_EXIT();
Expand Down