[flang-commits] [flang] [flang] Use precompiled parsing headers (PR #130600)
David Truby via flang-commits
flang-commits at lists.llvm.org
Mon Mar 10 06:51:20 PDT 2025
================
@@ -72,3 +72,11 @@ add_flang_library(flangFrontend
clangBasic
clangDriver
)
+
+target_precompile_headers(flangFrontend PRIVATE
+ [["flang/Parser/parsing.h"]]
+ [["flang/Parser/parse-tree.h"]]
+ [["flang/Parser/dump-parse-tree.h"]]
+ [["flang/Lower/PFTBuilder.h"]]
+ [["flang/Lower/Bridge.h"]]
+)
----------------
DavidTruby wrote:
In general it's only safe to have one precompiled header per TU, so that's all CMake (and most compilers) support. CMake isn't so much compiling the "Lower" headers _here_ though, conceptually (at least, not any more than including them in other files is).
CMake does something like the following
1. creates a `flangFrontend_headers.h` file that just contains `#include "flang/Parser/parsing.h` etc
2. asks the compiler to compile that single header into `flangFrontend_headers.pch` making sure to use exactly the same flags as will be used for each object file in the target
3. Includes that flangFrontend_headers.pch file in all the TUs in that target.
So there's nothing visible to outside this process that indicates that the "Lower" headers are being "built" here really.
As a result if you wanted to share a single `.pch` for the entire project, you have to do something like
```
target_precompile_headers(flangLowering REUSE-FROM flangFrontend)
```
because even if you list the exact same files, CMake will follow the process above by default and not re-use them, because each file isn't being treated individually but as part of a single `.pch` file for the whole target.
https://github.com/llvm/llvm-project/pull/130600
More information about the flang-commits
mailing list