[PATCH] D55056: [CMake] Default options for faster executables on MSVC
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 29 08:25:17 PST 2018
aganea created this revision.
aganea added reviewers: beanz, rnk.
Herald added subscribers: llvm-commits, mgorny.
This patch:
- Disables incremental linking by default. /INCREMENTAL <https://docs.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally?view=vs-2017> adds extra thunks in the EXE, which makes execution slower.
- Sets /MT (static CRT lib) by default instead of CMake's default /MD (dll CRT lib). The previous default /MD <https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017> makes all DLL functions to be thunked, thus making execution slower (memcmp, memset, etc.)
- Adds LLVM_ENABLE_INCREMENTAL_LINK which is set to OFF by default.
DLL thunks:
F7623159: dll_thunk.png <https://reviews.llvm.org/F7623159>
/INCREMENTAL thunks:
F7623162: incremental_thunk.png <https://reviews.llvm.org/F7623162>
I thought it'd be better if Clang / LLVM / LLD would be fast out-of-the-box, instead of people having to dig for "good" settings.
Below are timings for linking a large DLL with LLD. The type merging pass is dominant, and is affected by those two options, because of the tight merge loop. I currently have several optimisations in that loop that tend to increase the gap.
Without this patch (default cmake settings):
Type Merging: 23174 ms ( 56.9%)
With this patch (new default cmake settings):
Type Merging: 22338 ms ( 52.2%)
This is a MSVC-only change.
Repository:
rL LLVM
https://reviews.llvm.org/D55056
Files:
llvm/trunk/CMakeLists.txt
llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake
llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
Index: llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
@@ -381,6 +381,14 @@
# "Enforce type conversion rules".
append("/Zc:rvalueCast" CMAKE_CXX_FLAGS)
+ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND NOT LLVM_ENABLE_INCREMENTAL_LINK)
+ foreach(CONFIG RELEASE RELWITHDEBINFO MINSIZEREL)
+ foreach(FLAG EXE MODULE SHARED STATIC)
+ string(REGEX REPLACE "[-/](INCREMENTAL:YES|INCREMENTAL:NO|INCREMENTAL)" "/INCREMENTAL:NO" CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG} "${CMAKE_${FLAG}_LINKER_FLAGS_${CONFIG}}")
+ endforeach()
+ endforeach()
+ endif()
+
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
Index: llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake
===================================================================
--- llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake
+++ llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake
@@ -66,6 +66,15 @@
get_current_crt(LLVM_USE_CRT_${build}
MSVC_CRT_REGEX
CMAKE_CXX_FLAGS_${build})
+
+ # Make /MT the default in Release builds to make them faster
+ # and avoid the DLL function thunking.
+ if ((${build} STREQUAL "MINSIZEREL") OR
+ (${build} STREQUAL "RELEASE") OR
+ (${build} STREQUAL "RELWITHDEBINFO"))
+ set(LLVM_USE_CRT_${build} "MT")
+ endif()
+
set(LLVM_USE_CRT_${build}
"${LLVM_USE_CRT_${build}}"
CACHE STRING "Specify VC++ CRT to use for ${build_type} configurations."
Index: llvm/trunk/CMakeLists.txt
===================================================================
--- llvm/trunk/CMakeLists.txt
+++ llvm/trunk/CMakeLists.txt
@@ -365,6 +365,10 @@
option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
+if (MSVC)
+ option(LLVM_ENABLE_INCREMENTAL_LINK "Link incrementally. Enabling it might produce slower executables." OFF)
+endif()
+
option(LLVM_ENABLE_DUMP "Enable dump functions even when assertions are disabled" OFF)
if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55056.175858.patch
Type: text/x-patch
Size: 2348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181129/a616df28/attachment.bin>
More information about the llvm-commits
mailing list