https://github.com/aengelke created 
https://github.com/llvm/llvm-project/pull/173868

Building LLVM is slow and dominated by the C++ front-end. Most time is spent in 
(repeatedly) parsing headers. C++ modules build didn't really help, is fragile, 
and kills parallelism. Therefore, I propose to use PCH for frequently used 
headers (i.e., C++ stdlib, Support, IR, maybe CodeGen). There shouldn't be much 
difference for incremental compilation, as many headers I put into the PCHs 
transitively get included into most source files anyway.

CPU Time breakdown in seconds for llvm/lib/**.cpp (collected with -ftime-trace, 
-O1, -DLLVM_TARGETS_TO_BUILD="X86;AArch64"):

```
Phase                           main    main+TPDE+PCH
------------------------------- ------- -------------
ExecuteCompiler                 11958            6283
Frontend                         9309            4563 (PCH difference)
  Source                         6424            2271
  PerformPendingInstantiations   2210            1493
  CodeGenFunction                 324             364
Backend                          2593            1659
  Optimizer                      1689            1636 (probably just 
measurement noise)
  CodeGenPasses                   896               5 (TPDE fallbacks to LLVM 
for 10 CUs)
  TPDE                              0              13
```
The back-end is not really relevant here, but enabling PCH (this PR) reduces 
the front-end time by 2x. More improvements are possible (>20% parsing time is 
now spent for CodeGen/Machine*.h; unit tests spend a lot of time in parsing 
gtest). Improvements for Clang should also be possible (clang/AST/Decl.h is 
expensive with 1434s), but CMake currently refuses to use PCH for object 
libraries.

I'm opening this PR for early feedback/direction before spending more time on 
this:

- Does this extensive PCH use has a reasonable chance of getting merged?
  - How to deal with newly occuring name collisions? (e.g. llvm::Reloc from 
llvm/Support/CodeGen.h vs. lld::macho::Reloc from lld/MachO/Relocations.h; 
where e.g. lld/MachO/InputSections.cpp uses both namespaces)
- Enable by default vs. not? E.g., CI should probably not use this to catch 
missing includes, but CI should also keep it working as PCHs can lead to new 
errors.
- PCH reuse is currently hard-coded in llvm_add_library, how to make this more 
elegant?

cc @nikic @rnk @boomanaiden154 (not sure who else is interested in LLVM build 
times + looking at CMake)

>From 56134cd1d7445911629b3b32a857cd182c7d0340 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <[email protected]>
Date: Mon, 29 Dec 2025 10:54:18 +0000
Subject: [PATCH 1/3] WIP use pch for component libs

---
 llvm/cmake/modules/AddLLVM.cmake |  11 ++-
 llvm/lib/Support/CMakeLists.txt  | 121 +++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 3 deletions(-)

diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 2480d7373d1a3..58d4cb455fbe9 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -21,9 +21,10 @@ endfunction(get_subproject_title)
 
 function(llvm_update_compile_flags name)
   get_property(sources TARGET ${name} PROPERTY SOURCES)
-  if("${sources}" MATCHES "\\.c(;|$)")
-    set(update_src_props ON)
-  endif()
+  # XXX use generator expressions?
+  #if("${sources}" MATCHES "\\.c(;|$)")
+  #  set(update_src_props ON)
+  #endif()
 
   list(APPEND LLVM_COMPILE_CFLAGS " ${LLVM_COMPILE_FLAGS}")
 
@@ -918,6 +919,10 @@ function(add_llvm_component_library name)
   string(REGEX REPLACE "^LLVM" "" component_name ${name})
   set_property(TARGET ${name} PROPERTY LLVM_COMPONENT_NAME ${component_name})
 
+  if(TARGET LLVMSupport AND NOT ${name} STREQUAL "LLVMSupport")
+    target_precompile_headers(${name} REUSE_FROM LLVMSupport)
+  endif()
+
   if(ARG_COMPONENT_NAME)
     set_property(GLOBAL PROPERTY LLVM_COMPONENT_NAME_${ARG_COMPONENT_NAME} 
${component_name})
   endif()
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 1c397e8c0b766..41068a810e099 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -395,3 +395,124 @@ target_include_directories(LLVMSupport
   PRIVATE
   ${LLVM_THIRD_PARTY_DIR}/siphash/include
 )
+
+target_precompile_headers(LLVMSupport PRIVATE
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/ADL.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/APFloat.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/APInt.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/APSInt.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/ArrayRef.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/BitVector.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/DenseMap.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/Hashing.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/SetVector.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/SmallString.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/SmallVector.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/STLExtras.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/Statistic.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/StringExtras.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/StringRef.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/Twine.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/CommandLine.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/Casting.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/Error.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/FileSystem.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/FormatVariadic.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/JSON.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/ScopedPrinter.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/SourceMgr.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/VersionTuple.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/YAMLTraits.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/raw_ostream.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:<algorithm$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<any$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<array$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<atomic$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<bitset$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cassert$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cctype$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cerrno$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cfenv$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cfloat$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<charconv$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<chrono$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cinttypes$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<climits$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cmath$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<complex.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<complex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<condition_variable$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<csetjmp$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<csignal$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdarg$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdint$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdio$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdlib$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstring$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ctime$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ctype.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cuchar$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cwchar$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cwctype$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<deque$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<errno.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<exception$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<execution$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<fenv.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<filesystem$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<float.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<forward_list$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<fstream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<functional$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<initializer_list$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<iostream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<istream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<iterator$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<limits$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<list$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<map$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<math.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<memory$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<memory_resource$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<mutex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<new$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<numeric$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<optional$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ostream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<queue$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<random$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ratio$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<regex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<scoped_allocator$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<set$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<shared_mutex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<sstream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stack$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdbool.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stddef.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdexcept$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdint.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdio.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdlib.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<streambuf$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<string.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<string$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<string_view$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<system_error$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<tgmath.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<thread$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<tuple$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<type_traits$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<typeindex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<typeinfo$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<uchar.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<unordered_map$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<unordered_set$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<utility$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<valarray$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<variant$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<vector$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<wchar.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<wctype.h$<ANGLE-R>>"
+)

>From d57ed0390b15e597aea06f2784db57ed93b0b599 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <[email protected]>
Date: Mon, 29 Dec 2025 12:37:06 +0000
Subject: [PATCH 2/3] WIP pch for LLVMCore and maybe clang?

---
 clang/lib/DirectoryWatcher/CMakeLists.txt   |   2 +-
 clang/lib/Format/CMakeLists.txt             |   2 +-
 clang/lib/Tooling/Core/CMakeLists.txt       |   2 +-
 clang/lib/Tooling/Inclusions/CMakeLists.txt |   2 +-
 llvm/cmake/modules/AddLLVM.cmake            |  17 ++-
 llvm/lib/IR/CMakeLists.txt                  | 141 ++++++++++++++++++++
 llvm/lib/Support/CMakeLists.txt             |   4 +-
 7 files changed, 159 insertions(+), 11 deletions(-)

diff --git a/clang/lib/DirectoryWatcher/CMakeLists.txt 
b/clang/lib/DirectoryWatcher/CMakeLists.txt
index 5a87969821138..bbdd51b3afbaf 100644
--- a/clang/lib/DirectoryWatcher/CMakeLists.txt
+++ b/clang/lib/DirectoryWatcher/CMakeLists.txt
@@ -1,6 +1,6 @@
 include(CheckIncludeFiles)
 
-set(LLVM_LINK_COMPONENTS support)
+set(LLVM_LINK_COMPONENTS Support)
 
 set(DIRECTORY_WATCHER_SOURCES DirectoryScanner.cpp)
 set(DIRECTORY_WATCHER_LINK_LIBS "")
diff --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 50c0683dc9b7f..9c622486a5214 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS support)
+set(LLVM_LINK_COMPONENTS Support)
 
 add_clang_library(clangFormat
   AffectedRangeManager.cpp
diff --git a/clang/lib/Tooling/Core/CMakeLists.txt 
b/clang/lib/Tooling/Core/CMakeLists.txt
index e523ca45301e2..f102c1cdfca7b 100644
--- a/clang/lib/Tooling/Core/CMakeLists.txt
+++ b/clang/lib/Tooling/Core/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS support)
+set(LLVM_LINK_COMPONENTS Support)
 
 add_clang_library(clangToolingCore
   Diagnostic.cpp
diff --git a/clang/lib/Tooling/Inclusions/CMakeLists.txt 
b/clang/lib/Tooling/Inclusions/CMakeLists.txt
index f9c2e6397ae72..aad5a745a8b5d 100644
--- a/clang/lib/Tooling/Inclusions/CMakeLists.txt
+++ b/clang/lib/Tooling/Inclusions/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(LLVM_LINK_COMPONENTS support)
+set(LLVM_LINK_COMPONENTS Support)
 
 add_clang_library(clangToolingInclusions
   HeaderAnalysis.cpp
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 58d4cb455fbe9..3713dd1e1f9a4 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -529,6 +529,7 @@ function(llvm_add_library name)
     "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
     ${ARGN})
   list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
+  list(APPEND ARG_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
   if(ARG_ADDITIONAL_HEADERS)
     # Pass through ADDITIONAL_HEADERS.
     set(ARG_ADDITIONAL_HEADERS ADDITIONAL_HEADERS ${ARG_ADDITIONAL_HEADERS})
@@ -779,7 +780,6 @@ function(llvm_add_library name)
       endif()
       llvm_map_components_to_libnames(llvm_libs
        ${ARG_LINK_COMPONENTS}
-       ${LLVM_LINK_COMPONENTS}
        )
     endif()
   else()
@@ -790,7 +790,7 @@ function(llvm_add_library name)
     # It would be nice to verify that we have the dependencies for this library
     # name, but using get_property(... SET) doesn't suffice to determine if a
     # property has been set to an empty value.
-    set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS 
${ARG_LINK_COMPONENTS} ${LLVM_LINK_COMPONENTS})
+    set_property(TARGET ${name} PROPERTY LLVM_LINK_COMPONENTS 
${ARG_LINK_COMPONENTS})
 
     # This property is an internal property only used to make sure the
     # link step applied in LLVMBuildResolveComponentsLink uses the same
@@ -798,6 +798,15 @@ function(llvm_add_library name)
     set_property(TARGET ${name} PROPERTY LLVM_LIBTYPE ${libtype})
   endif()
 
+  # Non-default RTTI/EH results in incompatible flags, precluding PCH reuse.
+  if(NOT LLVM_REQUIRES_RTTI AND NOT LLVM_REQUIRES_EH)
+    if("Core" IN_LIST ARG_LINK_COMPONENTS)
+      target_precompile_headers(${name} REUSE_FROM LLVMCore)
+    elseif(NOT ${name} STREQUAL "LLVMCore" AND "Support" IN_LIST 
ARG_LINK_COMPONENTS)
+      target_precompile_headers(${name} REUSE_FROM LLVMSupport)
+    endif()
+  endif()
+
   target_link_libraries(${name} ${libtype}
       ${ARG_LINK_LIBS}
       ${lib_deps}
@@ -919,10 +928,6 @@ function(add_llvm_component_library name)
   string(REGEX REPLACE "^LLVM" "" component_name ${name})
   set_property(TARGET ${name} PROPERTY LLVM_COMPONENT_NAME ${component_name})
 
-  if(TARGET LLVMSupport AND NOT ${name} STREQUAL "LLVMSupport")
-    target_precompile_headers(${name} REUSE_FROM LLVMSupport)
-  endif()
-
   if(ARG_COMPONENT_NAME)
     set_property(GLOBAL PROPERTY LLVM_COMPONENT_NAME_${ARG_COMPONENT_NAME} 
${component_name})
   endif()
diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt
index 31821a2d6b208..529e032f34446 100644
--- a/llvm/lib/IR/CMakeLists.txt
+++ b/llvm/lib/IR/CMakeLists.txt
@@ -96,3 +96,144 @@ add_llvm_component_library(LLVMCore
   Support
   TargetParser
   )
+
+target_precompile_headers(LLVMCore PRIVATE
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/BasicBlock.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/CFG.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Constant.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Constants.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/DebugInfoMetadata.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/DataLayout.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Dominators.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Function.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/IRBuilder.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/InstVisitor.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Instruction.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Instructions.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/IntrinsicInst.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Module.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/ModuleSummaryIndex.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/PassManager.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/PatternMatch.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/IR/Value.h\">"
+
+  # From LLVMSupport
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/ADL.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/APFloat.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/APInt.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/APSInt.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/ArrayRef.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/BitVector.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/DenseMap.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/Hashing.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/SetVector.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/SmallString.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/SmallVector.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/STLExtras.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/Statistic.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/StringExtras.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/StringRef.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/ADT/Twine.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/CommandLine.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/Casting.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/Error.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/FileSystem.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/FormatVariadic.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/JSON.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/ScopedPrinter.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/SourceMgr.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/VersionTuple.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/YAMLTraits.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:\"llvm/Support/raw_ostream.h\">"
+  "$<$<COMPILE_LANGUAGE:CXX>:<algorithm$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<any$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<array$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<atomic$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<bitset$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cassert$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cctype$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cerrno$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cfenv$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cfloat$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<charconv$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<chrono$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cinttypes$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<climits$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cmath$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<complex.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<complex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<condition_variable$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<csetjmp$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<csignal$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdarg$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstddef$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdint$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdio$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstdlib$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cstring$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ctime$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ctype.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cuchar$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cwchar$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<cwctype$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<deque$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<errno.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<exception$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<execution$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<fenv.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<filesystem$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<float.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<forward_list$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<fstream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<functional$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<initializer_list$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<iostream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<istream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<iterator$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<limits$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<list$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<map$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<math.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<memory$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<memory_resource$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<mutex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<new$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<numeric$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<optional$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ostream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<queue$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<random$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<ratio$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<regex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<scoped_allocator$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<set$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<shared_mutex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<sstream$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stack$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdbool.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stddef.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdexcept$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdint.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdio.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<stdlib.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<streambuf$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<string.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<string$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<string_view$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<system_error$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<tgmath.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<thread$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<tuple$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<type_traits$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<typeindex$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<typeinfo$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<uchar.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<unordered_map$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<unordered_set$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<utility$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<valarray$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<variant$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<vector$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<wchar.h$<ANGLE-R>>"
+  "$<$<COMPILE_LANGUAGE:CXX>:<wctype.h$<ANGLE-R>>"
+)
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 41068a810e099..812f4d4878d49 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -135,7 +135,6 @@ if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
 endif()
 
 add_subdirectory(BLAKE3)
-add_subdirectory(LSP)
 
 add_llvm_component_library(LLVMSupport
   ABIBreak.cpp
@@ -516,3 +515,6 @@ target_precompile_headers(LLVMSupport PRIVATE
   "$<$<COMPILE_LANGUAGE:CXX>:<wchar.h$<ANGLE-R>>"
   "$<$<COMPILE_LANGUAGE:CXX>:<wctype.h$<ANGLE-R>>"
 )
+
+# SupportLSP depends on Support and therefore must be included afterwards.
+add_subdirectory(LSP)

>From cd041aa236461b8c125a3887eca6f8918fddcf27 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <[email protected]>
Date: Mon, 29 Dec 2025 13:12:47 +0000
Subject: [PATCH 3/3] [LLVM][CMake][NFC] Use generator expression to separate
 CXXFLAGS

This avoids looking at the individual sources for mixed C/C++ libraries.
---
 llvm/cmake/modules/AddLLVM.cmake | 55 ++++++++------------------------
 1 file changed, 13 insertions(+), 42 deletions(-)

diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 3713dd1e1f9a4..f7ff912ded057 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -20,13 +20,7 @@ function(get_subproject_title outvar)
 endfunction(get_subproject_title)
 
 function(llvm_update_compile_flags name)
-  get_property(sources TARGET ${name} PROPERTY SOURCES)
-  # XXX use generator expressions?
-  #if("${sources}" MATCHES "\\.c(;|$)")
-  #  set(update_src_props ON)
-  #endif()
-
-  list(APPEND LLVM_COMPILE_CFLAGS " ${LLVM_COMPILE_FLAGS}")
+  set(LLVM_COMPILE_CXXFLAGS "")
 
   # LLVM_REQUIRES_EH is an internal flag that individual targets can use to
   # force EH
@@ -36,22 +30,22 @@ function(llvm_update_compile_flags name)
       set(LLVM_REQUIRES_RTTI ON)
     endif()
     if(MSVC)
-      list(APPEND LLVM_COMPILE_FLAGS "/EHsc")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "/EHsc")
     endif()
   else()
     if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
-      list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "-fno-exceptions")
       if(LLVM_ENABLE_UNWIND_TABLES)
-        list(APPEND LLVM_COMPILE_FLAGS "-funwind-tables")
+        list(APPEND LLVM_COMPILE_CXXFLAGS "-funwind-tables")
       else()
-        list(APPEND LLVM_COMPILE_FLAGS "-fno-unwind-tables")
-        list(APPEND LLVM_COMPILE_FLAGS "-fno-asynchronous-unwind-tables")
+        list(APPEND LLVM_COMPILE_CXXFLAGS "-fno-unwind-tables")
+        list(APPEND LLVM_COMPILE_CXXFLAGS "-fno-asynchronous-unwind-tables")
       endif()
     elseif(MSVC)
       list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
-      list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "/EHs-c-")
     elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
-      list(APPEND LLVM_COMPILE_FLAGS "-qnoeh")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "-qnoeh")
     endif()
   endif()
 
@@ -62,40 +56,17 @@ function(llvm_update_compile_flags name)
     set(LLVM_CONFIG_HAS_RTTI NO CACHE INTERNAL "")
     list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_RTTI=0)
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
-      list(APPEND LLVM_COMPILE_FLAGS "-fno-rtti")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "-fno-rtti")
     elseif (MSVC)
-      list(APPEND LLVM_COMPILE_FLAGS "/GR-")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "/GR-")
     elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
-      list(APPEND LLVM_COMPILE_FLAGS "-qnortti")
+      list(APPEND LLVM_COMPILE_CXXFLAGS "-qnortti")
     endif ()
   elseif(MSVC)
-    list(APPEND LLVM_COMPILE_FLAGS "/GR")
-  endif()
-
-  # Assume that;
-  #   - LLVM_COMPILE_FLAGS is list.
-  #   - PROPERTY COMPILE_FLAGS is string.
-  string(REPLACE ";" " " target_compile_flags " ${LLVM_COMPILE_FLAGS}")
-  string(REPLACE ";" " " target_compile_cflags " ${LLVM_COMPILE_CFLAGS}")
-
-  if(update_src_props)
-    foreach(fn ${sources})
-      get_filename_component(suf ${fn} EXT)
-      if("${suf}" STREQUAL ".cpp")
-        set_property(SOURCE ${fn} APPEND_STRING PROPERTY
-          COMPILE_FLAGS "${target_compile_flags}")
-      endif()
-      if("${suf}" STREQUAL ".c")
-        set_property(SOURCE ${fn} APPEND_STRING PROPERTY
-          COMPILE_FLAGS "${target_compile_cflags}")
-      endif()
-    endforeach()
-  else()
-    # Update target props, since all sources are C++.
-    set_property(TARGET ${name} APPEND_STRING PROPERTY
-      COMPILE_FLAGS "${target_compile_flags}")
+    list(APPEND LLVM_COMPILE_CXXFLAGS "/GR")
   endif()
 
+  target_compile_options(${name} PRIVATE ${LLVM_COMPILE_FLAGS} 
$<$<COMPILE_LANGUAGE:CXX>:${LLVM_COMPILE_CXXFLAGS}>)
   set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS 
${LLVM_COMPILE_DEFINITIONS})
 endfunction()
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to