-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds `CLANG_BOLT_INSTRUMENT` option that applies BOLT instrumentation to Clang, performs a bootstrap build with the resulting Clang, merges resulting fdata files into a single profile file, and uses it to perform BOLT optimization on the original Clang binary. The projects and targets used for bootstrap/profile collection are configurable via `CLANG_BOLT_INSTRUMENT_PROJECTS` and `CLANG_BOLT_INSTRUMENT_TARGETS`. The defaults are "llvm" and "count" respectively, which results in a profile with ~5.3B dynamically executed instructions. The intended use of the functionality is through BOLT CMake cache file, similar to PGO 2-stage build: ``` cmake <llvm-project>/llvm -C <llvm-project>/clang/cmake/caches/BOLT.cmake ninja clang++-bolt # pulls clang-bolt ``` Stats with a recent checkout (clang-16), pre-built BOLT and Clang, 72vCPU/224G | CMake configure with host Clang + BOLT.cmake | 1m6.592s | Instrumenting Clang with BOLT | 2m50.508s | CMake configure `llvm` with instrumented Clang | 5m46.364s (~5x slowdown) | CMake build `not` with instrumented Clang |0m6.456s | Merging fdata files | 0m9.439s | Optimizing Clang with BOLT | 0m39.201s Building Clang: ```cmake ../llvm-project/llvm -DCMAKE_C_COMPILER=... -DCMAKE_CXX_COMPILER=... -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=Native -GNinja``` | | Release | BOLT-optimized | cmake | 0m24.016s | 0m22.333s | ninja clang | 5m55.692s | 4m35.122s I know it's not rigorous, but shows a ballpark figure. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D132975
- Loading branch information
Showing
3 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set(CMAKE_BUILD_TYPE Release CACHE STRING "") | ||
set(CLANG_BOLT_INSTRUMENT ON CACHE BOOL "") | ||
set(CLANG_BOLT_INSTRUMENT_PROJECTS "llvm" CACHE STRING "") | ||
set(CLANG_BOLT_INSTRUMENT_TARGETS "count" CACHE STRING "") | ||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "") | ||
set(CLANG_BOLT_INSTRUMENT_EXTRA_CMAKE_FLAGS "" CACHE STRING "") | ||
|
||
set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "") | ||
set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "") | ||
|
||
# Disable function splitting enabled by default in GCC8+ | ||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-reorder-blocks-and-partition") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-reorder-blocks-and-partition") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters