Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flang/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function(add_flang_nongtest_unittest test_name)
llvm_map_components_to_libnames(llvm_libs Support)
endif()
target_link_libraries(${test_name}${suffix} ${llvm_libs} ${ARG_UNPARSED_ARGUMENTS})
set_unittest_link_flags(${test_name}${suffix})

if(NOT ARG_SLOW_TEST)
add_dependencies(FlangUnitTests ${test_name}${suffix})
Expand Down
47 changes: 26 additions & 21 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,31 @@ function(add_llvm_implicit_projects)
llvm_add_implicit_projects(LLVM)
endfunction(add_llvm_implicit_projects)

function(set_unittest_link_flags target_name)
# The runtime benefits of LTO don't outweight the compile time costs for
# tests.
if(LLVM_ENABLE_LTO)
if((UNIX OR MINGW) AND LINKER_IS_LLD)
if(LLVM_ENABLE_FATLTO AND NOT APPLE)
# When using FatLTO, just use relocatable linking.
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--no-fat-lto-objects")
else()
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--lto-O0")
endif()
elseif(LINKER_IS_LLD_LINK)
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " /opt:lldlto=0")
elseif(APPLE AND NOT uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-mllvm,-O0")
endif()
endif()

target_link_options(${target_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS}")
endfunction(set_unittest_link_flags)

# Generic support for adding a unittest.
function(add_unittest test_suite test_name)
if( NOT LLVM_BUILD_TESTS )
Expand All @@ -1770,27 +1795,7 @@ function(add_unittest test_suite test_name)
get_subproject_title(subproject_title)
set_target_properties(${test_name} PROPERTIES FOLDER "${subproject_title}/Tests/Unit")

# The runtime benefits of LTO don't outweight the compile time costs for tests.
if(LLVM_ENABLE_LTO)
if((UNIX OR MINGW) AND LINKER_IS_LLD)
if(LLVM_ENABLE_FATLTO AND NOT APPLE)
# When using FatLTO, just use relocatable linking.
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--no-fat-lto-objects")
else()
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--lto-O0")
endif()
elseif(LINKER_IS_LLD_LINK)
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
LINK_FLAGS " /opt:lldlto=0")
elseif(APPLE AND NOT uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-mllvm,-O0")
endif()
endif()

target_link_options(${test_name} PRIVATE "${LLVM_UNITTEST_LINK_FLAGS}")
set_unittest_link_flags(${test_name})

set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir})
Expand Down