[PATCH] D30240: enable building with LTO on Windows using clang-cl and lld
Bob Haarman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 20:11:27 PST 2017
inglorion created this revision.
Herald added subscribers: mehdi_amini, mgorny.
With clang-cl gaining support for link-time optimization, we can now enable builds using LTO when using clang-cl and lld on Windows. To do this, we must not pass the -flto flag to the linker; lld-link does not understand it, but will perform LTO automatically when it encounters bitcode files. We also don't pass /Brepro when using LTO - the compiler doesn't generate object files for LTO, so passing the flag would only result in a warning about it being unused.
https://reviews.llvm.org/D30240
Files:
cmake/modules/HandleLLVMOptions.cmake
Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -407,11 +407,13 @@
# "Enforce type conversion rules".
append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
- if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT LLVM_ENABLE_LTO)
# clang-cl and cl by default produce non-deterministic binaries because
# link.exe /incremental requires a timestamp in the .obj file. clang-cl
# has the flag /Brepro to force deterministic binaries. We want to pass that
- # whenever you're building with clang unless you're passing /incremental.
+ # whenever you're building with clang unless you're passing /incremental
+ # or using LTO (/Brepro with LTO would result in a warning about the flag
+ # being unused, because we're not generating object files).
# This checks CMAKE_CXX_COMPILER_ID in addition to check_cxx_compiler_flag()
# because cl.exe does not emit an error on flags it doesn't understand,
# letting check_cxx_compiler_flag() claim it understands all flags.
@@ -700,19 +702,25 @@
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(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
- append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
- CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ append("-flto=thin" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+ if(NOT CMAKE_LINKER MATCHES "link.exe$")
+ 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)
elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
- append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
- CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+ if(NOT CMAKE_LINKER MATCHES "link.exe$")
+ append("-flto=full" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ endif()
elseif(LLVM_ENABLE_LTO)
- append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS
- CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ append("-flto" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
+ if(NOT CMAKE_LINKER MATCHES "link.exe$")
+ append("-flto" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
+ endif()
endif()
# This option makes utils/extract_symbols.py be used to determine the list of
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30240.89316.patch
Type: text/x-patch
Size: 2841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170222/7fd9bb2a/attachment.bin>
More information about the llvm-commits
mailing list