[llvm] r297854 - Re-apply r296730, "cmake: Configure the ThinLTO cache directory when using ELF lld or gold."

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 09:28:44 PDT 2017


Author: pcc
Date: Wed Mar 15 11:28:43 2017
New Revision: 297854

URL: http://llvm.org/viewvc/llvm-project?rev=297854&view=rev
Log:
Re-apply r296730, "cmake: Configure the ThinLTO cache directory when using ELF lld or gold."

All known cache-related bugs observed when self hosting have been fixed (r296907
and r297853).

Modified:
    llvm/trunk/cmake/modules/HandleLLVMOptions.cmake

Modified: llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/HandleLLVMOptions.cmake?rev=297854&r1=297853&r2=297854&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/HandleLLVMOptions.cmake (original)
+++ llvm/trunk/cmake/modules/HandleLLVMOptions.cmake Wed Mar 15 11:28:43 2017
@@ -715,11 +715,20 @@ if(uppercase_LLVM_ENABLE_LTO STREQUAL "T
   if(NOT LINKER_IS_LLD_LINK)
     append("-flto=thin" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
   endif()
-  # On darwin, enable the lto cache. This improves initial build time a little
-  # since we re-link a lot of the same objects, and significantly improves
-  # incremental build time.
-  append_if(APPLE "-Wl,-cache_path_lto,${PROJECT_BINARY_DIR}/lto.cache"
-            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+  # If the linker supports it, enable the lto cache. This improves initial build
+  # time a little since we re-link a lot of the same objects, and significantly
+  # improves incremental build time.
+  # FIXME: We should move all this logic into the clang driver.
+  if(APPLE)
+    append("-Wl,-cache_path_lto,${PROJECT_BINARY_DIR}/lto.cache"
+           CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+  elseif(UNIX AND LLVM_USE_LINKER STREQUAL "lld")
+    append("-Wl,--thinlto-cache-dir=${PROJECT_BINARY_DIR}/lto.cache"
+           CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+  elseif(LLVM_USE_LINKER STREQUAL "gold")
+    append("-Wl,--plugin-opt,cache-dir=${PROJECT_BINARY_DIR}/lto.cache"
+           CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+  endif()
 elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
   append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
   if(NOT LINKER_IS_LLD_LINK)




More information about the llvm-commits mailing list