[llvm] [cmake] Optimize RelWithDebInfo compiler options on windows (PR #101533)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 10:46:36 PDT 2024


https://github.com/GkvJwa created https://github.com/llvm/llvm-project/pull/101533

Due to the default cmake Release does not contain pdb, and RelWithDebInfo compilation parameter does not enable linking and compilation optimization. As a result, if we use RelWithDebInfo to compile on the windows, the generated clang will be larger in size and have slightly poorer performance.

Therefore, enable some compilation optimizations to improve performance and build size
compared:
```
size:
Default: 115 MB (121,020,928 bytes)
Optimized: 74.3 MB (77,987,840 bytes)

build time:compiling the same project can shorten 2~3 minutes(11min -> 8min)
```

This is equivalent to adding generate pdb to Release:
```
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
```

In addition, cross-compilation should require additional parameters to be set

>From 6983b3af81b2c06dcc8716a9fa1072636a248895 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Fri, 2 Aug 2024 01:26:02 +0800
Subject: [PATCH] [cmake] Optimize compiler options on windows

---
 llvm/CMakeLists.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 699de1ccd870c..129233c9ee925 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -842,6 +842,9 @@ if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
 endif()
 
 if(MSVC)
+  set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /O2 /Ob2 /Oy- /Zc:inline /Gw /Oi /Gy /FS /bigobj")
+  set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF /INCREMENTAL:NO /FIXED:NO /DEBUG")
+  set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF /INCREMENTAL:NO /FIXED:NO /DEBUG")
   option(LLVM_BUILD_LLVM_C_DYLIB "Build LLVM-C.dll (Windows only)" ON)
   # Set this variable to OFF here so it can't be set with a command-line
   # argument.



More information about the llvm-commits mailing list