From 95da3656bae124598c15d0f22e1456e27bdcfcbe Mon Sep 17 00:00:00 2001 From: Bob Haarman Date: Fri, 28 Apr 2017 20:17:15 +0000 Subject: [PATCH] limit to 2 parallel links when using thinlto Summary: When using ThinLTO, the linker performs its own parallelism. This change limits the number of parallel link jobs that Ninja will issue to keep the total number of threads reasonable when linking with ThinLTO. Reviewers: hans, ruiu Subscribers: mgorny, mehdi_amini, Prazek Differential Revision: https://reviews.llvm.org/D31990 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301676 91177308-0d34-0410-b5e6-96231b3b80d8 --- cmake/modules/HandleLLVMOptions.cmake | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake index 882d68e6b60..3dd16d51f0b 100644 --- a/cmake/modules/HandleLLVMOptions.cmake +++ b/cmake/modules/HandleLLVMOptions.cmake @@ -17,6 +17,9 @@ else() set(LINKER_IS_LLD_LINK FALSE) 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) + # Ninja Job Pool support # The following only works with the Ninja generator in CMake >= 3.0. set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING @@ -32,16 +35,19 @@ endif() set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING "Define the maximum number of concurrent link jobs.") -if(LLVM_PARALLEL_LINK_JOBS) - if(NOT CMAKE_MAKE_PROGRAM MATCHES "ninja") - message(WARNING "Job pooling is only available with Ninja generators.") - else() +if(CMAKE_MAKE_PROGRAM MATCHES "ninja") + if(NOT LLVM_PARALLEL_LINK_JOBS AND uppercase_LLVM_ENABLE_LTO STREQUAL "THIN") + message(STATUS "ThinLTO provides its own parallel linking - limiting parallel link jobs to 2.") + set(LLVM_PARALLEL_LINK_JOBS "2") + endif() + if(LLVM_PARALLEL_LINK_JOBS) set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS}) set(CMAKE_JOB_POOL_LINK link_job_pool) endif() +elseif(LLVM_PARALLEL_LINK_JOBS) + message(WARNING "Job pooling is only available with Ninja generators.") endif() - if (LINKER_IS_LLD_LINK) # Pass /MANIFEST:NO so that CMake doesn't run mt.exe on our binaries. Adding # manifests with mt.exe breaks LLD's symbol tables and takes as much time as @@ -724,8 +730,6 @@ append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate='${LLVM_PRO CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS) -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) if(LLVM_ENABLE_LTO AND LLVM_ON_WIN32 AND NOT LINKER_IS_LLD_LINK) message(FATAL_ERROR "When compiling for Windows, LLVM_ENABLE_LTO requires using lld as the linker (point CMAKE_LINKER at lld-link.exe)") endif()