]> granicus.if.org Git - llvm/commitdiff
[CMake] Default options for faster executables on MSVC
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Tue, 18 Dec 2018 18:17:00 +0000 (18:17 +0000)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Tue, 18 Dec 2018 18:17:00 +0000 (18:17 +0000)
- 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349517 91177308-0d34-0410-b5e6-96231b3b80d8

CMakeLists.txt
cmake/modules/ChooseMSVCCRT.cmake
cmake/modules/HandleLLVMOptions.cmake

index e2e35dcebdb5a2e326c4a1146b7a086061d03b8c..15f95d2e580c94ec4592b6c9c6bfa5cf16de136c 100644 (file)
@@ -370,6 +370,10 @@ option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
 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" )
index 0e6e1aa55254e51480ba489e54c545c7a6accc25..cdd7deec4c84ce1790efb5c80432b73ff327e91b 100644 (file)
@@ -66,6 +66,15 @@ variables (LLVM_USE_CRT_DEBUG, etc) instead.")
       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 49db3088bbc4ff3a453968ab1c260a01f14fa2f3..e8b0e27e000d2414a19ca2f481dfb23cae0e02b4 100644 (file)
@@ -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