Skip to content

Commit a2112e2

Browse files
committed
[CMake][Release] Enable bolt optimization for clang on Linux (#128090)
Also stop buiding the bolt project on other platforms since bolt only supports ELF. (cherry picked from commit 148111f)
1 parent b8b7fce commit a2112e2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.github/workflows/release-binaries.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ jobs:
142142
# 2-3 hours to build on macOS, much slower than on Linux.
143143
# The long build time causes the release build to time out on x86_64,
144144
# so we need to disable flang there.
145-
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;bolt;polly;mlir'"
145+
target_cmake_flags="$target_cmake_flags -DLLVM_RELEASE_ENABLE_PROJECTS='clang;lld;lldb;clang-tools-extra;polly;mlir'"
146146
fi
147147
target_cmake_flags="$target_cmake_flags -DBOOTSTRAP_DARWIN_osx_ARCHS=$arches -DBOOTSTRAP_DARWIN_osx_BUILTIN_ARCHS=$arches"
148148
fi

clang/cmake/caches/Release.cmake

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ endfunction()
2929
# cache file to CMake via -C. e.g.
3030
#
3131
# cmake -D LLVM_RELEASE_ENABLE_PGO=ON -C Release.cmake
32+
33+
set (DEFAULT_PROJECTS "clang;lld;lldb;clang-tools-extra;polly;mlir;flang")
34+
# bolt only supports ELF, so only enable it for Linux.
35+
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
36+
list(APPEND DEFAULT_PROJECTS "bolt")
37+
endif()
38+
3239
set (DEFAULT_RUNTIMES "compiler-rt;libcxx")
3340
if (NOT WIN32)
3441
list(APPEND DEFAULT_RUNTIMES "libcxxabi" "libunwind")
3542
endif()
3643
set(LLVM_RELEASE_ENABLE_LTO THIN CACHE STRING "")
3744
set(LLVM_RELEASE_ENABLE_PGO ON CACHE BOOL "")
3845
set(LLVM_RELEASE_ENABLE_RUNTIMES ${DEFAULT_RUNTIMES} CACHE STRING "")
39-
set(LLVM_RELEASE_ENABLE_PROJECTS "clang;lld;lldb;clang-tools-extra;bolt;polly;mlir;flang" CACHE STRING "")
46+
set(LLVM_RELEASE_ENABLE_PROJECTS ${DEFAULT_PROJECTS} CACHE STRING "")
4047
# Note we don't need to add install here, since it is one of the pre-defined
4148
# steps.
4249
set(LLVM_RELEASE_FINAL_STAGE_TARGETS "clang;package;check-all;check-llvm;check-clang" CACHE STRING "")
@@ -118,13 +125,21 @@ if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
118125
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")
119126
endif()
120127

128+
# Set flags for bolt
129+
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
130+
set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -Wl,--emit-relocs,-znow")
131+
endif()
132+
121133
set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
122134
set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
123135
set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)
124136

125137
# Final Stage Config (stage2)
126138
set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)
127139
set_final_stage_var(LLVM_ENABLE_PROJECTS "${LLVM_RELEASE_ENABLE_PROJECTS}" STRING)
140+
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
141+
set_final_stage_var(CLANG_BOLT "INSTRUMENT" STRING)
142+
endif()
128143
set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
129144
set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)
130145

0 commit comments

Comments
 (0)