Skip to content

Commit

Permalink
Add "--enable-llvm-passes=<passes>" option to wamrc (#2335)
Browse files Browse the repository at this point in the history
Add "--enable-llvm-passes=<passes>" option to wamrc for customizing LLVM passes
  • Loading branch information
no1wudi committed Jul 4, 2023
1 parent df98d9f commit 44f4b4f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
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 @@ -70,6 +70,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 @@ -342,6 +344,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

0 comments on commit 44f4b4f

Please sign in to comment.