Skip to content

Commit bd9d595

Browse files
committed
[lto] Do not pass in the LLVM_ENABLE_LTO flag to Swift's cmake invocation.
*NOTE* We are still passing this variable into LLVM. Just not into Swift anymore. I originally passed in the variable -DLLVM_ENABLE_LTO=YES to Swift's cmake to ensure that the Swift unittests were compiled with lto. That was the wrong fix. The reason why is that if -DLLVM_ENABLE_LTO is set to YES then HandleLLVMOptions in llvm will append -flto to both CMAKE_C_FLAGS and CMAKE_CXX_FLAGS implying that -flto can not be disabled selectively. This ability to disable flto selectively is something that we need in order to lto host libraries, but not lto target libraries. Thus in this commit, we no longer pass in -DLLVM_ENABLE_LTO=YES to swift's cmake invocation. Instead we apply the lto flag to the unittest target ourselves in add_swift_unittest. rdar://24717107
1 parent b9e6adc commit bd9d595

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ function(add_swift_unittest test_dirname)
1010
# function defined by AddLLVM.cmake.
1111
add_unittest(SwiftUnitTests ${test_dirname} ${ARGN})
1212

13+
# TODO: _add_variant_c_compile_link_flags and these tests should share some
14+
# sort of logic.
15+
#
16+
# *NOTE* The unittests are never built for the target, so we always enable LTO
17+
# *if we are asked to.
18+
if (SWIFT_TOOLS_ENABLE_LTO)
19+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY COMPILE_FLAGS " -flto ")
20+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY LINK_FLAGS " -flto ")
21+
endif()
22+
1323
if(SWIFT_BUILT_STANDALONE AND NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
1424
# Replace target references with full paths, so that we use LLVM's
1525
# build configuration rather than Swift's.

utils/build-script-impl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,6 @@ function set_build_options_for_host() {
588588
)
589589
fi
590590

591-
# We need to also pass in this flag so that parts of LLVM's
592-
# build system that we use (for instance when compiling
593-
# unittests) do not use too many threads when we are using lto.
594-
if [[ $(true_false "${LLVM_ENABLE_LTO}") == "TRUE" ]]; then
595-
swift_cmake_options+=(
596-
"-DLLVM_PARALLEL_LINK_JOBS=${LLVM_NUM_PARALLEL_LTO_LINK_JOBS}"
597-
)
598-
fi
599591
swift_cmake_options+=(
600592
"-DSWIFT_PARALLEL_LINK_JOBS=${SWIFT_TOOLS_NUM_PARALLEL_LTO_LINK_JOBS}"
601593
)
@@ -1864,7 +1856,6 @@ for host in "${ALL_HOSTS[@]}"; do
18641856
-DCMAKE_CXX_FLAGS="$(swift_c_flags ${host})"
18651857
-DCMAKE_BUILD_TYPE:STRING="${SWIFT_BUILD_TYPE}"
18661858
-DLLVM_ENABLE_ASSERTIONS:BOOL=$(true_false "${SWIFT_ENABLE_ASSERTIONS}")
1867-
-DLLVM_ENABLE_LTO=$(true_false "${LLVM_ENABLE_LTO}")
18681859
-DSWIFT_ANALYZE_CODE_COVERAGE:STRING=$(toupper "${SWIFT_ANALYZE_CODE_COVERAGE}")
18691860
-DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}"
18701861
-DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}")

0 commit comments

Comments
 (0)