Skip to content

Commit

Permalink
[CMake] Replace clang binary if using clang-bolt target
Browse files Browse the repository at this point in the history
Instead of creating an extra clang-bolt binary and clang++-bolt symlink,
replace the original clang binary with BOLT-optimized one.

This fixes the issue with installing optimized binary as `install-clang`
target now copies the new version.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D139454
  • Loading branch information
aaupov committed Jan 28, 2023
1 parent df34581 commit e67f849
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
17 changes: 2 additions & 15 deletions clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,6 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
set(CLANGXX_PATH ${CLANG_PATH}++)
set(CLANG_INSTRUMENTED ${CLANG_PATH}-bolt.inst)
set(CLANGXX_INSTRUMENTED ${CLANGXX_PATH}-bolt.inst)
set(CLANG_OPTIMIZED ${CLANG_PATH}-bolt)
set(CLANGXX_OPTIMIZED ${CLANGXX_PATH}-bolt)

# Instrument clang with BOLT
add_custom_target(clang-instrumented
Expand Down Expand Up @@ -935,6 +933,7 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
)

# Optimize original (pre-bolt) Clang using the collected profile
set(CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR}/clang.bolt)
add_custom_target(clang-bolt
DEPENDS ${CLANG_OPTIMIZED}
)
Expand All @@ -945,22 +944,10 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
-data ${CMAKE_CURRENT_BINARY_DIR}/prof.fdata
-reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
-split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $<TARGET_FILE:clang>
COMMENT "Optimizing Clang with BOLT"
VERBATIM
)

# Make a symlink from clang-bolt to clang++-bolt
add_custom_target(clang++-bolt
DEPENDS ${CLANGXX_OPTIMIZED}
)
add_custom_command(OUTPUT ${CLANGXX_OPTIMIZED}
DEPENDS clang-bolt
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CLANG_OPTIMIZED}
${CLANGXX_OPTIMIZED}
COMMENT "Creating symlink from BOLT optimized clang to clang++"
VERBATIM
)
endif()

if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
Expand Down
2 changes: 0 additions & 2 deletions clang/cmake/caches/BOLT-PGO.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ set(LLVM_ENABLE_PROJECTS "bolt;clang;lld" CACHE STRING "")

set(CLANG_BOOTSTRAP_TARGETS
stage2-clang-bolt
stage2-clang++-bolt
CACHE STRING "")
set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
clang-bolt
clang++-bolt
CACHE STRING "")

set(PGO_BUILD_CONFIGURATION ${CMAKE_CURRENT_LIST_DIR}/BOLT.cmake CACHE STRING "")
Expand Down
7 changes: 3 additions & 4 deletions llvm/docs/AdvancedBuilds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Then, build the BOLT-optimized binary by running the following ninja command:

.. code-block:: console
$ ninja clang++-bolt
$ ninja clang-bolt
If you're seeing errors in the build process, try building with a recent
version of Clang/LLVM by setting the CMAKE_C_COMPILER and
Expand All @@ -243,12 +243,11 @@ configuration command:
-DBOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD=ON \
-DPGO_INSTRUMENT_LTO=Thin
Then, to build the final optimized binary, build the stage2-clang++-bolt
target:
Then, to build the final optimized binary, build the stage2-clang-bolt target:

.. code-block:: console
$ ninja stage2-clang++-bolt
$ ninja stage2-clang-bolt
3-Stage Non-Determinism
=======================
Expand Down

0 comments on commit e67f849

Please sign in to comment.