[compiler-rt] [compiler-rt] Add COMPILER_RT_GPU_THIN_LTO to build with -flto=thin (PR #226916)

Wenju He via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 00:03:59 PDT 2026


https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/226916

>From 588a654239794837df56d9987bf629b18dd9cff3 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Mon, 28 Sep 2026 09:46:02 +0200
Subject: [PATCH 1/2] [compiler-rt] Add COMPILER_RT_GPU_THIN_LTO to build with
 -flto=thin

COMPILER_RT_GPU_THIN_LTO option (default: off) allows to build
compiler-rt GPU runtime with -flto=thin instead of -flto.
ThinLTO Function Import requires runtime libraries to have ThinLTO
summaries.
This flag intends to support downstream ThinLTO pipeline for GPU
compilation. There is no upstream user of the flag yet.
---
 compiler-rt/CMakeLists.txt        | 8 +++++++-
 compiler-rt/cmake/config-ix.cmake | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 0458b17ba38c2..82d7bddb987a4 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -194,6 +194,8 @@ else()
 endif()
 
 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
+option(COMPILER_RT_GPU_THIN_LTO
+  "Build GPU runtimes with -flto=thin instead of -flto" OFF)
 option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
   "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
 # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
@@ -397,7 +399,11 @@ if(COMPILER_RT_GPU_BUILD)
   append_list_if(UBSAN_COMMON_SUPPORTED_ARCH -ffreestanding SANITIZER_COMMON_CFLAGS)
   append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib SANITIZER_COMMON_CFLAGS)
   append_list_if(COMPILER_RT_HAS_NOSTDLIBINC_FLAG -nostdlibinc SANITIZER_COMMON_CFLAGS)
-  append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto SANITIZER_COMMON_CFLAGS)
+  if(COMPILER_RT_GPU_THIN_LTO)
+    append_list_if(COMPILER_RT_HAS_FLTO_THIN_FLAG -flto=thin SANITIZER_COMMON_CFLAGS)
+  else()
+    append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto SANITIZER_COMMON_CFLAGS)
+  endif()
   if(COMPILER_RT_TARGET_AMDGPU)
     append_list_if(COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG
                    "SHELL:-Xclang -mcode-object-version=none" SANITIZER_COMMON_CFLAGS)
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index e1abc7eb5c44e..76b32a6a2cab2 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -119,6 +119,7 @@ check_cxx_compiler_flag("-Werror;-ftrivial-auto-var-init=pattern" COMPILER_RT_HA
 check_c_compiler_flag(-nogpulib             COMPILER_RT_HAS_NOGPULIB_FLAG)
 check_c_compiler_flag(-nostdlibinc          COMPILER_RT_HAS_NOSTDLIBINC_FLAG)
 check_c_compiler_flag(-flto                 COMPILER_RT_HAS_FLTO_FLAG)
+check_c_compiler_flag(-flto=thin            COMPILER_RT_HAS_FLTO_THIN_FLAG)
 check_c_compiler_flag("-Xclang;-mcode-object-version=none" COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG)
 
 if(NOT WIN32 AND NOT CYGWIN)

>From c8358700b85e802a833977ab4cedcf0d0f8a465b Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Tue, 29 Sep 2026 09:00:41 +0200
Subject: [PATCH 2/2] Rename to COMPILER_RT_THIN_LTO and update for builtins

---
 compiler-rt/CMakeLists.txt              | 4 ++--
 compiler-rt/lib/builtins/CMakeLists.txt | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 82d7bddb987a4..aa4ef510694c2 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -194,7 +194,7 @@ else()
 endif()
 
 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
-option(COMPILER_RT_GPU_THIN_LTO
+option(COMPILER_RT_THIN_LTO
   "Build GPU runtimes with -flto=thin instead of -flto" OFF)
 option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
   "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
@@ -399,7 +399,7 @@ if(COMPILER_RT_GPU_BUILD)
   append_list_if(UBSAN_COMMON_SUPPORTED_ARCH -ffreestanding SANITIZER_COMMON_CFLAGS)
   append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib SANITIZER_COMMON_CFLAGS)
   append_list_if(COMPILER_RT_HAS_NOSTDLIBINC_FLAG -nostdlibinc SANITIZER_COMMON_CFLAGS)
-  if(COMPILER_RT_GPU_THIN_LTO)
+  if(COMPILER_RT_THIN_LTO)
     append_list_if(COMPILER_RT_HAS_FLTO_THIN_FLAG -flto=thin SANITIZER_COMMON_CFLAGS)
   else()
     append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto SANITIZER_COMMON_CFLAGS)
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 12a3b068b3373..8e42edd5034d1 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -1093,7 +1093,11 @@ else ()
   if(COMPILER_RT_GPU_BUILD)
     append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS)
     append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib BUILTIN_CFLAGS)
-    append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto BUILTIN_CFLAGS)
+    if(COMPILER_RT_THIN_LTO)
+      append_list_if(COMPILER_RT_HAS_FLTO_THIN_FLAG -flto=thin BUILTIN_CFLAGS)
+    else()
+      append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto BUILTIN_CFLAGS)
+    endif()
 
     # AMDGPU targets want to use a generic ABI.
     if(COMPILER_RT_TARGET_AMDGPU)



More information about the llvm-commits mailing list