https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/235660
This option forwards -flto or -flto=thin to all runtimes builds as RUNTIMES_LTO_FLAG. This intends to support ThinLTO pipeline for GPU compilation, since ThinLTO Function Import requires runtime libraries to have ThinLTO summaries. RUNTIMES_LTO_FLAG defaults to -flto when not forwarded by the bootstrap, i.e. for direct runtimes and standalone compiler-rt/libclc builds. >From 018a3cc98fc590f467a4f1b79d668156101975e4 Mon Sep 17 00:00:00 2001 From: Wenju He <[email protected]> Date: Mon, 26 Oct 2026 09:33:31 +0100 Subject: [PATCH] [runtimes] Add RUNTIMES_LTO to select the kind of LTO for GPU runtimes This option forwards -flto or -flto=thin to all runtimes builds as RUNTIMES_LTO_FLAG. This intends to support ThinLTO pipeline for GPU compilation, since ThinLTO Function Import requires runtime libraries to have ThinLTO summaries. RUNTIMES_LTO_FLAG defaults to -flto when not forwarded by the bootstrap, i.e. for direct runtimes and standalone compiler-rt/libclc builds. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- compiler-rt/CMakeLists.txt | 5 ++++- compiler-rt/lib/builtins/CMakeLists.txt | 5 ++++- flang-rt/cmake/modules/AddFlangRT.cmake | 8 ++++---- libc/cmake/modules/LLVMLibCCompileOptionRules.cmake | 2 +- libclc/CMakeLists.txt | 5 ++++- llvm/runtimes/CMakeLists.txt | 13 +++++++++++++ openmp/device/CMakeLists.txt | 2 +- openmp/module/CMakeLists.txt | 2 +- runtimes/CMakeLists.txt | 4 ++++ 9 files changed, 36 insertions(+), 10 deletions(-) diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index 0458b17ba38c20..3fb13ba7851860 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -397,7 +397,10 @@ 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(NOT DEFINED RUNTIMES_LTO_FLAG) + set(RUNTIMES_LTO_FLAG -flto) + endif() + append_list_if(COMPILER_RT_HAS_FLTO_FLAG ${RUNTIMES_LTO_FLAG} SANITIZER_COMMON_CFLAGS) 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/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 67427a1f4b8a49..884fb7db6c24c0 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -1111,7 +1111,10 @@ 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(NOT DEFINED RUNTIMES_LTO_FLAG) + set(RUNTIMES_LTO_FLAG -flto) + endif() + append_list_if(COMPILER_RT_HAS_FLTO_FLAG ${RUNTIMES_LTO_FLAG} BUILTIN_CFLAGS) # AMDGPU targets want to use a generic ABI. if(COMPILER_RT_TARGET_AMDGPU) diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake index c033efa46100c3..2ad6d9b6603dff 100644 --- a/flang-rt/cmake/modules/AddFlangRT.cmake +++ b/flang-rt/cmake/modules/AddFlangRT.cmake @@ -297,13 +297,13 @@ function (add_flangrt_library name) # Add target specific options if necessary. if ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^amdgpu|^amdgcn") target_compile_options(${tgtname} PRIVATE - $<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden> - $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib -flto> + $<$<COMPILE_LANGUAGE:CXX>:-nogpulib ${RUNTIMES_LTO_FLAG} -fvisibility=hidden> + $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib ${RUNTIMES_LTO_FLAG}> ) elseif ("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx") target_compile_options(${tgtname} PRIVATE - $<$<COMPILE_LANGUAGE:CXX>:-nogpulib -flto -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63> - $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib -flto> + $<$<COMPILE_LANGUAGE:CXX>:-nogpulib ${RUNTIMES_LTO_FLAG} -fvisibility=hidden -Wno-unknown-cuda-version --cuda-feature=+ptx63> + $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib ${RUNTIMES_LTO_FLAG}> ) elseif (APPLE) # Clang on Darwin enables non-POSIX extensions by default. diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake index b26c1957880a5f..f1a050da8a6063 100644 --- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake +++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake @@ -352,7 +352,7 @@ function(_get_common_compile_options_impl output_var) list(APPEND compile_options "-nogpulib") list(APPEND compile_options "-fvisibility=hidden") list(APPEND compile_options "-fconvergent-functions") - list(APPEND compile_options "-flto") + list(APPEND compile_options "${RUNTIMES_LTO_FLAG}") list(APPEND compile_options "-Wno-multi-gpu") if(LIBC_TARGET_ARCHITECTURE_IS_NVPTX) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 5829bd9b39eac0..ff01a441721b9a 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -165,8 +165,11 @@ if(LIBCLC_TARGET_ARCH IN_LIST LIBCLC_ARCHS_AMDGPU OR LIBCLC_TARGET_ARCH IN_LIST endif() # Common compile options shared by CLC and OpenCL libraries. +if(NOT DEFINED RUNTIMES_LTO_FLAG) + set(RUNTIMES_LTO_FLAG -flto) +endif() set(compile_flags - -flto + ${RUNTIMES_LTO_FLAG} --target=${clang_triple} -nostdlib -nostdlibinc diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index fcb85ec96e265c..81557de8fd5f82 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -91,6 +91,19 @@ macro(set_enable_per_target_runtime_dir) endif() endmacro() +set(RUNTIMES_LTO "full" CACHE STRING + "Kind of LTO used by runtimes that always use LTO: full or thin") +string(TOUPPER "${RUNTIMES_LTO}" uppercase_RUNTIMES_LTO) +if(uppercase_RUNTIMES_LTO STREQUAL "THIN") + set(RUNTIMES_LTO_FLAG "-flto=thin") +elseif(uppercase_RUNTIMES_LTO STREQUAL "FULL") + set(RUNTIMES_LTO_FLAG "-flto") +else() + message(FATAL_ERROR "RUNTIMES_LTO must be full or thin, got '${RUNTIMES_LTO}'") +endif() + +list(APPEND COMMON_CMAKE_ARGS "-DRUNTIMES_LTO_FLAG=${RUNTIMES_LTO_FLAG}") + macro(append_passthrough_options out type names) get_cmake_property(variable_names VARIABLES) diff --git a/openmp/device/CMakeLists.txt b/openmp/device/CMakeLists.txt index 1c486be1ef12af..c450e9a41e40e0 100644 --- a/openmp/device/CMakeLists.txt +++ b/openmp/device/CMakeLists.txt @@ -24,7 +24,7 @@ set(src_files ${CMAKE_CURRENT_SOURCE_DIR}/src/Workshare.cpp ) -list(APPEND compile_options -flto) +list(APPEND compile_options ${RUNTIMES_LTO_FLAG}) list(APPEND compile_options -fvisibility=hidden) list(APPEND compile_options -nogpulib) list(APPEND compile_options -nostdlibinc) diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt index 3d7128dee11171..11383cbb5dd091 100644 --- a/openmp/module/CMakeLists.txt +++ b/openmp/module/CMakeLists.txt @@ -28,7 +28,7 @@ endif () if (LIBOMP_TARGET_IS_GPU) target_compile_options(libomp-mod PRIVATE - $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib -flto> + $<$<COMPILE_LANGUAGE:Fortran>:-nogpulib ${RUNTIMES_LTO_FLAG}> ) endif () diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt index a0ec44617c9c77..c70ae4a9b32d04 100644 --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -219,6 +219,10 @@ if("${LLVM_DEFAULT_TARGET_TRIPLE}" MATCHES "^nvptx") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c") endif() +if(NOT DEFINED RUNTIMES_LTO_FLAG) + set(RUNTIMES_LTO_FLAG -flto) +endif() + # Avoid checking whether the compiler is working. set(LLVM_COMPILER_CHECKED ON) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
