[clang] [llvm] [CMAKE] Enable FatLTO as a build option for LLVM (PR #80480)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 16:28:35 PDT 2024
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/80480
>From 043e8a33f10905d456e42b71801f0ab1b24a8b36 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Tue, 22 Aug 2023 15:24:03 +0000
Subject: [PATCH 1/6] [CMAKE] Enable FatLTO as a build option for LLVM
---
clang/cmake/caches/Fuchsia-stage2.cmake | 1 +
llvm/cmake/modules/AddLLVM.cmake | 11 +++++++++--
llvm/cmake/modules/HandleLLVMOptions.cmake | 6 ++++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index db7430b3344c3e..d5546e20873b3c 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -11,6 +11,7 @@ set(LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
+set(LLVM_ENABLE_FATLTO ON CACHE BOOL "")
set(LLVM_ENABLE_HTTPLIB ON CACHE BOOL "")
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 5610880da71079..6fc02c993a924c 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1637,8 +1637,15 @@ function(add_unittest test_suite test_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)
- set_property(TARGET ${test_name} APPEND_STRING PROPERTY
- LINK_FLAGS " -Wl,--lto-O0")
+ if(LLVM_ENABLE_FATLTO)
+ # When using FatLTO, just use relocatable linking.
+ set_property(TARGET ${test_name} APPEND_STRING PROPERTY
+ LINK_FLAGS " -Wl,--no-fat-lto-objects")
+ set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS " -fno-lto")
+ 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")
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 745a8354f11896..a03a92b70ac300 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -32,6 +32,8 @@ endif()
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")
string(TOUPPER "${LLVM_ENABLE_LTO}" uppercase_LLVM_ENABLE_LTO)
+option(LLVM_ENABLE_FATLTO "Build LLVM with -ffat-lto-objects." OFF)
+
# Ninja Job Pool support
# The following only works with the Ninja generator in CMake >= 3.0.
set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
@@ -1280,6 +1282,10 @@ elseif(LLVM_ENABLE_LTO)
endif()
endif()
+if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+ append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+endif()
+
# Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are
# doing dynamic linking (see below).
set(LLVM_EXPORT_SYMBOLS_FOR_PLUGINS_AIX_default OFF)
>From fcec28e7b2352a9a1d92e16b4dbf1952d83049ec Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Fri, 2 Feb 2024 13:09:18 -0800
Subject: [PATCH 2/6] Add -ffat-lto-objects to CMAKE_C_FLAGS and
CMAKE_CXX_FLAGS
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index a03a92b70ac300..cec45365462044 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1283,7 +1283,10 @@ elseif(LLVM_ENABLE_LTO)
endif()
if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
+ append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ if(NOT LINKER_IS_LLD_LINK)
append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ endif()
endif()
# Set an AIX default for LLVM_EXPORT_SYMBOLS_FOR_PLUGINS based on whether we are
>From e273686a4b127fa844af2423b4fb1c17e6552621 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Tue, 5 Mar 2024 10:08:26 -0800
Subject: [PATCH 3/6] [cmake] Append -ffat-lto-objects to
CMAKE_MODULE_LINKER_FLAGS
---
llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index cec45365462044..92fa9839db652d 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -1285,7 +1285,7 @@ endif()
if(LLVM_ENABLE_FATLTO AND (FUCHSIA OR UNIX))
append("-ffat-lto-objects" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(NOT LINKER_IS_LLD_LINK)
- append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ append("-ffat-lto-objects" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS)
endif()
endif()
>From 334bd32068dc4d6e09937b5dd61e4af434d6eab9 Mon Sep 17 00:00:00 2001
From: AtariDreams <83477269+AtariDreams at users.noreply.github.com>
Date: Fri, 8 Mar 2024 08:43:45 -0500
Subject: [PATCH 4/6] [Hexagon] Use LiveRegUnits (#84112)
>From 9c6c9adbd5386fcfd65e68140642f07a93198e88 Mon Sep 17 00:00:00 2001
From: Amy Huang <akhuang at google.com>
Date: Wed, 13 Mar 2024 15:17:11 -0700
Subject: [PATCH 5/6] =?UTF-8?q?Unrevert=20"[Clang][C++23]=20Implement=20P2?=
=?UTF-8?q?448R2:=20Relaxing=20some=20constexpr=20re=E2=80=A6=20(#85140)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Unrevert commit
https://github.com/llvm/llvm-project/commit/2f67dfb012038678dd0b873394a55bd5c937f843
as there were already dependent changes in the codebase that now fail.
>From d4520222ff87cde34f7b4fbba7d742409c0c2bc7 Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Fri, 15 Mar 2024 23:15:47 +0000
Subject: [PATCH 6/6] Remove -fno-lto from COMPILE_FLAGS
---
llvm/cmake/modules/AddLLVM.cmake | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 6fc02c993a924c..d84d9d7cca68cf 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -1641,7 +1641,6 @@ function(add_unittest test_suite test_name)
# When using FatLTO, just use relocatable linking.
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--no-fat-lto-objects")
- set_property(TARGET ${test_name} APPEND_STRING PROPERTY COMPILE_FLAGS " -fno-lto")
else()
set_property(TARGET ${test_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,--lto-O0")
More information about the llvm-commits
mailing list