Skip to content

Commit

Permalink
Implement AOT static PGO (#2243)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wenyongh committed Jun 5, 2023
1 parent f1e9029 commit 8d88471
Show file tree
Hide file tree
Showing 29 changed files with 1,999 additions and 52 deletions.
2 changes: 1 addition & 1 deletion build-scripts/build_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
"-DLLVM_ENABLE_IDE:BOOL=OFF",
"-DLLVM_ENABLE_LIBEDIT=OFF",
"-DLLVM_ENABLE_TERMINFO:BOOL=OFF",
"-DLLVM_ENABLE_ZLIB:BOOL=OFF",
"-DLLVM_ENABLE_ZLIB:BOOL=ON",
"-DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF",
"-DLLVM_INCLUDE_DOCS:BOOL=OFF",
"-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF",
Expand Down
4 changes: 4 additions & 0 deletions build-scripts/config_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,7 @@ if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
add_definitions (-DCOLLECT_CODE_COVERAGE)
message (" Collect code coverage enabled")
endif ()
if (WAMR_BUILD_STATIC_PGO EQUAL 1)
add_definitions (-DWASM_ENABLE_STATIC_PGO=1)
message (" AOT static PGO enabled")
endif ()
4 changes: 4 additions & 0 deletions core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,8 @@
#define WASM_ENABLE_WASM_CACHE 0
#endif

#ifndef WASM_ENABLE_STATIC_PGO
#define WASM_ENABLE_STATIC_PGO 0
#endif

#endif /* end of _CONFIG_H_ */
Loading

0 comments on commit 8d88471

Please sign in to comment.