-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[flang] Use precompiled headers in Frontend, Lower, Parser, Semantics and Evaluate #131137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-flang-parser Author: Kajetan Puchalski (mrkajetanp) ChangesPrecompiling larger headers can save a lot of compile time across various compilation units. Selected compile time & memory improvements are as follows: flang/lib/Parser/Fortran-parsers.cpp: flang/lib/Lower/Bridge.cpp: flang/lib/Lower/PFTBuilder.cpp flang/lib/Lower/Allocatable.cpp flang/lib/Semantics/Semantics.cpp While the newly added precompiled headers are as follows: Parser: Lower: Semantics: Full diff: https://github.com/llvm/llvm-project/pull/131137.diff 3 Files Affected:
diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index 0bd9a47cd040f..bc817ff8f1f3e 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -73,3 +73,14 @@ add_flang_library(FortranLower
MLIRLLVMDialect
MLIRSCFToControlFlow
)
+
+target_precompile_headers(FortranLower PRIVATE
+ [["flang/Lower/ConvertExpr.h"]]
+ [["flang/Lower/SymbolMap.h"]]
+ [["flang/Lower/AbstractConverter.h"]]
+ [["flang/Lower/IterationSpace.h"]]
+ [["flang/Lower/CallInterface.h"]]
+ [["flang/Lower/BoxAnalyzer.h"]]
+ [["flang/Lower/PFTBuilder.h"]]
+ [["flang/Lower/DirectivesCommon.h"]]
+)
diff --git a/flang/lib/Parser/CMakeLists.txt b/flang/lib/Parser/CMakeLists.txt
index 76fe3d7ce6ba4..1855b8a841ba7 100644
--- a/flang/lib/Parser/CMakeLists.txt
+++ b/flang/lib/Parser/CMakeLists.txt
@@ -36,3 +36,11 @@ add_flang_library(FortranParser
omp_gen
acc_gen
)
+
+target_precompile_headers(FortranParser PRIVATE
+ [["flang/Parser/parsing.h"]]
+ [["flang/Parser/parse-tree.h"]]
+ [["flang/Parser/provenance.h"]]
+ [["flang/Parser/message.h"]]
+ [["flang/Parser/parse-tree-visitor.h"]]
+)
diff --git a/flang/lib/Semantics/CMakeLists.txt b/flang/lib/Semantics/CMakeLists.txt
index 93bf0c7c5facd..bd8cc47365f06 100644
--- a/flang/lib/Semantics/CMakeLists.txt
+++ b/flang/lib/Semantics/CMakeLists.txt
@@ -64,3 +64,12 @@ add_flang_library(FortranSemantics
FrontendOpenACC
TargetParser
)
+
+target_precompile_headers(FortranSemantics PRIVATE
+ [["flang/Semantics/semantics.h"]]
+ [["flang/Semantics/type.h"]]
+ [["flang/Semantics/openmp-modifiers.h"]]
+ [["flang/Semantics/expression.h"]]
+ [["flang/Semantics/tools.h"]]
+ [["flang/Semantics/symbol.h"]]
+)
|
Lowering depends on Semantics and the Parser, and Semantics depends on Parser, have you tried using REUSE_FROM https://cmake.org/cmake/help/latest/command/target_precompile_headers.html#reusing-precompile-headers so that lowering can reuse the precompiled headers too? Just curious, I am not familiar with that cmake feature at all. |
We shortly discussed this in a subthread under #130600. Since the main goal is to reduce the memory usage per compilation thread, I didn't want to put too much into the precompiled headers either. If I tried adding the same Semantics headers on top of the Lower ones then the precompiled header for Lower/ would become probably the biggest TU in all of flang. |
Why not Evaluate? It might benefit the most of all of these directories. |
Thanks for the suggestion! No reason not to indeed, I'll add it. |
What is the impact on the size of the build directories? (I am asking because this blog post is pointing out that the build directory size can increase). |
From But then at the same time I think some space might be saved in the specific compilation units that now no longer need to include them, so it might not be the biggest deal. |
Consider that this does not work together with ccache: #130600 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! I can confirm, that (combined with #131397) I can build Flang with -j6
— and basically it'd go with -j12
if not for a few libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
ae83e1f
to
5c706ec
Compare
I reverted #130600 as it was causing some buildbot issues in the absence of the ccache fixes. |
Precompiling larger headers can save a lot of compile time across various compilation units. Selected compile time & memory improvements are as follows: flang/lib/Parser/Fortran-parsers.cpp: Elapsed (wall clock) time (h:mm:ss or m:ss): 0:47.31 -> 0:41.68 Maximum resident set size (kbytes): 2062140 -> 1745584 flang/lib/Lower/Bridge.cpp: Elapsed (wall clock) time (h:mm:ss or m:ss): 1:19.16 -> 0:45.86 Maximum resident set size (kbytes): 3849144 -> 2443476 flang/lib/Lower/PFTBuilder.cpp Elapsed (wall clock) time (h:mm:ss or m:ss): 1:29.24 -> 1:00.99 Maximum resident set size (kbytes): 4218368 -> 2923128 flang/lib/Lower/Allocatable.cpp Elapsed (wall clock) time (h:mm:ss or m:ss): 0:53.03 -> 0:22.50 Maximum resident set size (kbytes): 3092840 -> 2116908 flang/lib/Semantics/Semantics.cpp Elapsed (wall clock) time (h:mm:ss or m:ss): 1:18.75 -> 1:00.20 Maximum resident set size (kbytes): 3527744 -> 2545308 While the newly added precompiled headers are as follows: Parser: Elapsed (wall clock) time (h:mm:ss or m:ss): 0:09.62 Maximum resident set size (kbytes): 1034608 Lower: Elapsed (wall clock) time (h:mm:ss or m:ss): 0:41.33 Maximum resident set size (kbytes): 3615240 Semantics: Elapsed (wall clock) time (h:mm:ss or m:ss): 0:26.69 Maximum resident set size (kbytes): 2403776 Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
flang/lib/Evaluate/check-expression.cpp: Elapsed (wall clock) time (h:mm:ss or m:ss): 1:11.91 -> 1:02.29 Maximum resident set size (kbytes): 2710788 -> 2414740 Similar improvements for other compilation units under Evaluate. cmake_pch.hxx.cxx compilation time: Elapsed (wall clock) time (h:mm:ss or m:ss): 0:13.93 Maximum resident set size (kbytes): 1492744 Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Reland of llvm#130600 which was reverted on account of waiting for required ccache compatibility fixes. Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
5c706ec
to
6edd33b
Compare
With #136856 merged there is now proper ccache support for this on Linux. I added a line here to disable pch on Windows for the time being, meaning this should now be ready to go. |
Precompiling larger headers can save a lot of compile time across various compilation units.
Selected compile time & memory improvements are as follows:
flang/lib/Parser/Fortran-parsers.cpp:
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:47.31 -> 0:41.68
Maximum resident set size (kbytes): 2062140 -> 1745584
flang/lib/Lower/Bridge.cpp:
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:19.16 -> 0:45.86
Maximum resident set size (kbytes): 3849144 -> 2443476
flang/lib/Lower/PFTBuilder.cpp
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:29.24 -> 1:00.99
Maximum resident set size (kbytes): 4218368 -> 2923128
flang/lib/Lower/Allocatable.cpp
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:53.03 -> 0:22.50
Maximum resident set size (kbytes): 3092840 -> 2116908
flang/lib/Semantics/Semantics.cpp
Elapsed (wall clock) time (h:mm:ss or m:ss): 1:18.75 -> 1:00.20
Maximum resident set size (kbytes): 3527744 -> 2545308
While the newly added precompiled headers are as follows:
Parser:
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:09.62
Maximum resident set size (kbytes): 1034608
Lower:
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:41.33
Maximum resident set size (kbytes): 3615240
Semantics:
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:26.69
Maximum resident set size (kbytes): 2403776