Skip to content

Commit 88b4122

Browse files
committed
Merge pull request #2360 from gottesmm/lto-changes-for-upstream
Lto changes for upstream
2 parents 4466574 + 4e6648d commit 88b4122

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ else()
301301
endif()
302302

303303
# lipo is used to create universal binaries.
304-
find_program(LIPO "lipo")
304+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
305+
include(SwiftDarwin)
306+
find_toolchain_tool(LIPO "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" lipo)
307+
endif()
305308

306309
if("${SWIFT_NATIVE_LLVM_TOOLS_PATH}" STREQUAL "")
307310
set(SWIFT_CROSS_COMPILING FALSE)

cmake/modules/SwiftDarwin.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ function(get_default_toolchain_dir result_var_name)
1111
set("${result_var_name}" "${toolchain_dir}" PARENT_SCOPE)
1212
endfunction()
1313

14+
function(find_toolchain_tool result_var_name toolchain tool)
15+
execute_process(
16+
COMMAND "xcrun" "--toolchain" "${toolchain}" "--find" "${tool}"
17+
OUTPUT_VARIABLE tool_path
18+
OUTPUT_STRIP_TRAILING_WHITESPACE)
19+
set("${result_var_name}" "${tool_path}" PARENT_SCOPE)
20+
endfunction()

utils/build-script-impl

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,15 @@ function float_min() {
277277
function num_llvm_parallel_lto_link_jobs() {
278278
case "$(uname -s -m)" in
279279
Darwin\ x86_64)
280-
# Currently with -gline-tables-only clang is ~3.5GB on Darwin. Use
281-
# the formula GB Memory/3.5GB to get the number of parallel link
282-
# threads we can support.
283-
local NUM_MEMORY_THREADS=$(echo $(system_memory_in_bytes)/1000000000.0/3.5 | bc)
280+
# *WARNING! HUERISTIC!*
281+
#
282+
# Use the formula (GB Memory - 3)/6.0GB to get the number of
283+
# parallel link threads we can support. This gives the OS 3 GB of
284+
# room to work with.
285+
#
286+
# This is a bit conservative, but I have found that this number
287+
# prevents me from swapping on my test machine.
288+
local NUM_MEMORY_THREADS=$(echo \( $(system_memory_in_bytes)/1000000000.0 - 3.0 \) / 6.0 | bc)
284289
echo $(float_min "${NUM_MEMORY_THREADS}" "${BUILD_JOBS}")
285290
;;
286291
*)
@@ -293,10 +298,15 @@ function num_llvm_parallel_lto_link_jobs() {
293298
function num_swift_parallel_lto_link_jobs() {
294299
case "$(uname -s -m)" in
295300
Darwin\ x86_64)
296-
# Currently with -gline-tables-only swift is ~5-6GB on Darwin. Use
297-
# the formula GB Memory/6GB to get the number of parallel link
298-
# threads we can support.
299-
local NUM_MEMORY_THREADS=$(echo $(system_memory_in_bytes)/1000000000/6.0 | bc)
301+
# *WARNING! HUERISTIC!*
302+
#
303+
# Use the formula (GB Memory - 3)/8.0GB to get the number of
304+
# parallel link threads we can support. This gives the OS 3 GB of
305+
# room to work with.
306+
#
307+
# This is a bit conservative, but I have found that this number
308+
# prevents me from swapping on my test machine.
309+
local NUM_MEMORY_THREADS=$(echo \( $(system_memory_in_bytes)/1000000000 - 3.0 \) / 8.0 | bc)
300310
echo $(float_min "${NUM_MEMORY_THREADS}" "${BUILD_JOBS}")
301311
;;
302312
*)
@@ -531,10 +541,6 @@ function set_deployment_target_based_options() {
531541
fi
532542

533543
llvm_cmake_options+=(
534-
"-DCMAKE_C_FLAGS=-O2 -flto -gline-tables-only -fno-stack-protector "
535-
"-DCMAKE_CXX_FLAGS=-O2 -flto -gline-tables-only -fno-stack-protector "
536-
"-DCMAKE_C_FLAGS_RELWITHDEBINFO=-O2 -flto -gline-tables-only -fno-stack-protector "
537-
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-O2 -flto -gline-tables-only -fno-stack-protector "
538544
"-DLLVM_PARALLEL_LINK_JOBS=$(num_llvm_parallel_lto_link_jobs)"
539545
)
540546
fi
@@ -1239,6 +1245,9 @@ function llvm_c_flags() {
12391245
if [[ $(is_cmake_release_build_type "${LLVM_BUILD_TYPE}") ]] ; then
12401246
echo -n " -fno-stack-protector"
12411247
fi
1248+
if [[ $(true_false "${LLVM_ENABLE_LTO}") ]] ; then
1249+
echo -n " -gline-tables-only"
1250+
fi
12421251
}
12431252

12441253
function cmark_c_flags() {
@@ -1527,6 +1536,7 @@ for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"
15271536
-DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS_TO_BUILD}"
15281537
-DLLVM_INCLUDE_TESTS:BOOL=$(true_false "${SOURCE_TREE_INCLUDES_TESTS}")
15291538
-DLLVM_INCLUDE_DOCS:BOOL=TRUE
1539+
-DLLVM_ENABLE_LTO=$(true_false "${LLVM_ENABLE_LTO}")
15301540
"${llvm_cmake_options[@]}"
15311541
)
15321542
if [[ $(is_cross_tools_deployment_target ${deployment_target}) ]] ; then
@@ -1619,6 +1629,7 @@ for deployment_target in "${HOST_TARGET}" "${CROSS_TOOLS_DEPLOYMENT_TARGETS[@]}"
16191629
-DCMAKE_CXX_FLAGS="$(swift_c_flags ${deployment_target})"
16201630
-DCMAKE_BUILD_TYPE:STRING="${SWIFT_BUILD_TYPE}"
16211631
-DLLVM_ENABLE_ASSERTIONS:BOOL=$(true_false "${SWIFT_ENABLE_ASSERTIONS}")
1632+
-DLLVM_ENABLE_LTO=$(true_false "${LLVM_ENABLE_LTO}")
16221633
-DSWIFT_ANALYZE_CODE_COVERAGE:STRING=$(toupper "${SWIFT_ANALYZE_CODE_COVERAGE}")
16231634
-DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}"
16241635
-DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}")

0 commit comments

Comments
 (0)