From ff2f02e01e292df3bbfc787e1b9716f3ca2285ee Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Fri, 7 Mar 2025 15:35:57 +0000 Subject: [PATCH 1/2] [flang] Use precompiled parsing headers Most of the high memory usage and compilation time in the frontend units is due to including large parsing headers. This commit moves out several of the largest parsing headers into a new precompiled header linked to flangFrontend. The new compilation metrics for FrontendActions.cpp are as follows: User time (seconds): 38.40 System time (seconds): 2.00 Maximum resident set size (kbytes): 2710964 (2.58 GB) (vs 3.78 GB) ParserActions.cpp: User time (seconds): 69.37 System time (seconds): 1.81 Maximum resident set size (kbytes): 2599456 (2.47 GB) (vs 4 GB) Alongside the new precompiled header compilation unit User time (seconds): 41.61 System time (seconds): 2.72 Maximum resident set size (kbytes): 3107644 (2.96 GB) Signed-off-by: Kajetan Puchalski --- flang/lib/Frontend/CMakeLists.txt | 8 ++++++++ flang/lib/Frontend/CompilerInstance.cpp | 1 - flang/lib/Frontend/FrontendActions.cpp | 1 - flang/lib/Frontend/ParserActions.cpp | 4 ---- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt index c80373799b015..e8a098613e26f 100644 --- a/flang/lib/Frontend/CMakeLists.txt +++ b/flang/lib/Frontend/CMakeLists.txt @@ -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"]] +) diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp index b1fa32ecb4cfc..5fd3b76b6741b 100644 --- a/flang/lib/Frontend/CompilerInstance.cpp +++ b/flang/lib/Frontend/CompilerInstance.cpp @@ -13,7 +13,6 @@ #include "flang/Frontend/CompilerInstance.h" #include "flang/Frontend/CompilerInvocation.h" #include "flang/Frontend/TextDiagnosticPrinter.h" -#include "flang/Parser/parsing.h" #include "flang/Parser/provenance.h" #include "flang/Semantics/semantics.h" #include "flang/Support/Fortran-features.h" diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp index 94de376aaf7d6..cd3e206c19550 100644 --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -15,7 +15,6 @@ #include "flang/Frontend/CompilerInvocation.h" #include "flang/Frontend/FrontendOptions.h" #include "flang/Frontend/ParserActions.h" -#include "flang/Lower/Bridge.h" #include "flang/Lower/Support/Verifier.h" #include "flang/Optimizer/Dialect/Support/FIRContext.h" #include "flang/Optimizer/Dialect/Support/KindMapping.h" diff --git a/flang/lib/Frontend/ParserActions.cpp b/flang/lib/Frontend/ParserActions.cpp index cc7e72f696f96..7967832c80ac9 100644 --- a/flang/lib/Frontend/ParserActions.cpp +++ b/flang/lib/Frontend/ParserActions.cpp @@ -12,10 +12,6 @@ #include "flang/Frontend/ParserActions.h" #include "flang/Frontend/CompilerInstance.h" -#include "flang/Lower/Bridge.h" -#include "flang/Lower/PFTBuilder.h" -#include "flang/Parser/dump-parse-tree.h" -#include "flang/Parser/parsing.h" #include "flang/Parser/provenance.h" #include "flang/Parser/source.h" #include "flang/Parser/unparse.h" From f9662a4eea7749b6e58ffbc085ea630ff9ab6b39 Mon Sep 17 00:00:00 2001 From: Kajetan Puchalski Date: Mon, 10 Mar 2025 14:20:51 +0000 Subject: [PATCH 2/2] [flang] Add back precompiled header includes The build system can handle prioritising pre-compiled headers over explicit includes if they are available. There is thus no need to remove the explicit includes. Signed-off-by: Kajetan Puchalski --- flang/lib/Frontend/CompilerInstance.cpp | 1 + flang/lib/Frontend/FrontendActions.cpp | 1 + flang/lib/Frontend/ParserActions.cpp | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp index 5fd3b76b6741b..b1fa32ecb4cfc 100644 --- a/flang/lib/Frontend/CompilerInstance.cpp +++ b/flang/lib/Frontend/CompilerInstance.cpp @@ -13,6 +13,7 @@ #include "flang/Frontend/CompilerInstance.h" #include "flang/Frontend/CompilerInvocation.h" #include "flang/Frontend/TextDiagnosticPrinter.h" +#include "flang/Parser/parsing.h" #include "flang/Parser/provenance.h" #include "flang/Semantics/semantics.h" #include "flang/Support/Fortran-features.h" diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp index cd3e206c19550..94de376aaf7d6 100644 --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -15,6 +15,7 @@ #include "flang/Frontend/CompilerInvocation.h" #include "flang/Frontend/FrontendOptions.h" #include "flang/Frontend/ParserActions.h" +#include "flang/Lower/Bridge.h" #include "flang/Lower/Support/Verifier.h" #include "flang/Optimizer/Dialect/Support/FIRContext.h" #include "flang/Optimizer/Dialect/Support/KindMapping.h" diff --git a/flang/lib/Frontend/ParserActions.cpp b/flang/lib/Frontend/ParserActions.cpp index 7967832c80ac9..cc7e72f696f96 100644 --- a/flang/lib/Frontend/ParserActions.cpp +++ b/flang/lib/Frontend/ParserActions.cpp @@ -12,6 +12,10 @@ #include "flang/Frontend/ParserActions.h" #include "flang/Frontend/CompilerInstance.h" +#include "flang/Lower/Bridge.h" +#include "flang/Lower/PFTBuilder.h" +#include "flang/Parser/dump-parse-tree.h" +#include "flang/Parser/parsing.h" #include "flang/Parser/provenance.h" #include "flang/Parser/source.h" #include "flang/Parser/unparse.h"