Implement AOT static PGO (#2243)
LLVM PGO (Profile-Guided Optimization) allows the compiler to better optimize code
for how it actually runs. This PR implements the AOT static PGO, and is tested on
Linux x86-64 and x86-32. The basic steps are:
1. Use `wamrc --enable-llvm-pgo -o <aot_file_of_pgo> <wasm_file>`
to generate an instrumented aot file.
2. Compile iwasm with `cmake -DWAMR_BUILD_STATIC_PGO=1` and run
`iwasm --gen-prof-file=<raw_profile_file> <aot_file_of_pgo>`
to generate the raw profile file.
3. Run `llvm-profdata merge -output=<profile_file> <raw_profile_file>`
to merge the raw profile file into the profile file.
4. Run `wamrc --use-prof-file=<profile_file> -o <aot_file> <wasm_file>`
to generate the optimized aot file.
5. Run the optimized aot_file: `iwasm <aot_file>`.
The test scripts are also added for each benchmark, run `test_pgo.sh` under
each benchmark's folder to test the AOT static pgo.
This commit is contained in:
@ -65,6 +65,8 @@ print_help()
|
||||
printf(" --enable-indirect-mode Enalbe call function through symbol table but not direct call\n");
|
||||
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(" --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");
|
||||
printf(" flags can be: i32.load, i64.load, f32.load, f64.load, v128.load,\n");
|
||||
@ -329,6 +331,14 @@ main(int argc, char *argv[])
|
||||
else if (!strcmp(argv[0], "--disable-llvm-lto")) {
|
||||
option.disable_llvm_lto = true;
|
||||
}
|
||||
else if (!strcmp(argv[0], "--enable-llvm-pgo")) {
|
||||
option.enable_llvm_pgo = true;
|
||||
}
|
||||
else if (!strncmp(argv[0], "--use-prof-file=", 16)) {
|
||||
if (argv[0][16] == '\0')
|
||||
PRINT_HELP_AND_EXIT();
|
||||
option.use_prof_file = argv[0] + 16;
|
||||
}
|
||||
else if (!strcmp(argv[0], "--enable-segue")) {
|
||||
/* all flags are enabled */
|
||||
option.segue_flags = 0x1F1F;
|
||||
|
||||
Reference in New Issue
Block a user