[llvm] r349517 - [CMake] Default options for faster executables on MSVC
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 18 10:17:00 PST 2018
Author: aganea
Date: Tue Dec 18 10:17:00 2018
New Revision: 349517
URL: http://llvm.org/viewvc/llvm-project?rev=349517&view=rev
Log:
[CMake] Default options for faster executables on MSVC
- Disable incremental linking by default. /INCREMENTAL adds extra thunks in the EXE, which makes execution slower.
- Set /MT (static CRT lib) by default instead of CMake's default /MD (dll CRT lib). The previous default /MD 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.
Differential revision: https://reviews.llvm.org/D55056
Modified:
llvm/trunk/CMakeLists.txt
llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake
llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
Modified: llvm/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=349517&r1=349516&r2=349517&view=diff
==============================================================================
--- llvm/trunk/CMakeLists.txt (original)
+++ llvm/trunk/CMakeLists.txt Tue Dec 18 10:17:00 2018
@@ -370,6 +370,10 @@ option(LLVM_ENABLE_LLD "Use lld as C and
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" )
Modified: llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake?rev=349517&r1=349516&r2=349517&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake (original)
+++ llvm/trunk/cmake/modules/ChooseMSVCCRT.cmake Tue Dec 18 10:17:00 2018
@@ -66,6 +66,15 @@ variables (LLVM_USE_CRT_DEBUG, etc) inst
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."
Modified: llvm/trunk/cmake/modules/HandleLLVMOptions.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/HandleLLVMOptions.cmake?rev=349517&r1=349516&r2=349517&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/HandleLLVMOptions.cmake (original)
+++ llvm/trunk/cmake/modules/HandleLLVMOptions.cmake Tue Dec 18 10:17:00 2018
@@ -381,6 +381,14 @@ if( MSVC )
# "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
More information about the llvm-commits
mailing list