Skip to content

Commit 43fc921

Browse files
authored
[CMAKE] Enable FatLTO as a build option for LLVM (#80480)
Since LLVM supports `-ffat-lto-objects` we should enable this as an option in the LLVM build. FatLTO should improve the time it takes to build tests for LTO enabled builds of the compiler by not linking w/ the bitcode portion of the object files, which should speed up build times for LTO builds without disabling optimizations.
1 parent 83afcbf commit 43fc921

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
1111

1212
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
1313
set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
14+
set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
1415
set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
1516
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
1617
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,8 +1637,14 @@ function(add_unittest test_suite test_name)
16371637
# The runtime benefits of LTO don't outweight the compile time costs for tests.
16381638
if(LLVM_ENABLE_LTO)
16391639
if((UNIX OR MINGW) AND LINKER_IS_LLD)
1640-
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
1641-
LINK_FLAGS " -Wl,--lto-O0")
1640+
if(LLVM_ENABLE_FATLTO)
1641+
# When using FatLTO, just use relocatable linking.
1642+
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
1643+
LINK_FLAGS " -Wl,--no-fat-lto-objects")
1644+
else()
1645+
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
1646+
LINK_FLAGS " -Wl,--lto-O0")
1647+
endif()
16421648
elseif(LINKER_IS_LLD_LINK)
16431649
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
16441650
LINK_FLAGS " /opt:lldlto=0")

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif()
3232
set(LLVM_ENABLE_LTO OFF CACHE STRING "Build LLVM with LTO. May be specified as Thin or Full to use a particular kind of LTO")
3333
string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
3434

35+
option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
36+
3537
# Ninja Job Pool support
3638
# The following only works with the Ninja generator in CMake >= 3.0.
3739
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1280,6 +1282,13 @@ elseif(LLVM_ENABLE_LTO)
12801282
endif()
12811283
endif()
12821284

1285+
if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
1286+
append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1287+
if(NOT LINKER_IS_LLD_LINK)
1288+
append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS)
1289+
endif()
1290+
endif()
1291+
12831292
# Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are
12841293
# doing dynamic linking (see below).
12851294
set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)

0 commit comments

Comments
 (0)