llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Erich Keane (erichkeane)

<details>
<summary>Changes</summary>

A very simple PCH file that seems to gain us about 3% on build time.  On my 
personal build (with a bunch of our other optimizations) it goes from:

real: 7m58  --&gt;7m42
user: 612m53--&gt;585m18
sys:  36m27 --&gt;34m57

I suspect there are more gains to be had by adding other files here, but this 
improvement seems worth doing.

---
Full diff: https://github.com/llvm/llvm-project/pull/222201.diff


6 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CMakeLists.txt (+4) 
- (added) clang/lib/CIR/CodeGen/pch.h (+23) 
- (modified) clang/lib/CIR/Dialect/CMakeLists.txt (+6-1) 
- (modified) clang/lib/CIR/Dialect/IR/CMakeLists.txt (+7) 
- (modified) clang/lib/CIR/Dialect/Transforms/CMakeLists.txt (+4) 
- (added) clang/lib/CIR/Dialect/Transforms/pch.h (+20) 


``````````diff
diff --git a/clang/lib/CIR/CodeGen/CMakeLists.txt 
b/clang/lib/CIR/CodeGen/CMakeLists.txt
index c4bd520fc61b7..3992f7c476b03 100644
--- a/clang/lib/CIR/CodeGen/CMakeLists.txt
+++ b/clang/lib/CIR/CodeGen/CMakeLists.txt
@@ -64,6 +64,10 @@ add_clang_library(clangCIR
   MLIRCIR
   MLIRCIROpInterfacesIncGen
 
+  DISABLE_PCH_REUSE # PCH contains private headers
+  PRECOMPILE_HEADERS
+  [["pch.h"]]
+
   LINK_LIBS
   clangAST
   clangBasic
diff --git a/clang/lib/CIR/CodeGen/pch.h b/clang/lib/CIR/CodeGen/pch.h
new file mode 100644
index 0000000000000..dca5bc15ce0e6
--- /dev/null
+++ b/clang/lib/CIR/CodeGen/pch.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// Precompiled header for clangCIR. Uses private headers.
+///
+//===----------------------------------------------------------------------===//
+
+#include "Address.h"
+#include "CIRGenBuilder.h"
+#include "CIRGenCXXABI.h"
+#include "CIRGenFunction.h"
+#include "CIRGenModule.h"
+#include "CIRGenValue.h"
+#include "mlir/Dialect/OpenACC/OpenACC.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
+#include "clang/AST/pch.h"
+#include "llvm/Support/pch.h"
diff --git a/clang/lib/CIR/Dialect/CMakeLists.txt 
b/clang/lib/CIR/Dialect/CMakeLists.txt
index 6aacd029d845d..8ddfd544cbe44 100644
--- a/clang/lib/CIR/Dialect/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/CMakeLists.txt
@@ -1,5 +1,10 @@
-add_subdirectory(Analysis)
+# IR must be processed first: it defines MLIRCIR, whose PCH other CIR
+# dialect libraries below (Analysis, OpenACC, OpenMP, Transforms) can
+# automatically reuse via llvm_update_pch's LLVM_PCH_PRIORITY dependency
+# scan -- that scan only sees targets that already exist, so MLIRCIR must
+# be defined before anything that wants to reuse its PCH.
 add_subdirectory(IR)
+add_subdirectory(Analysis)
 add_subdirectory(OpenACC)
 add_subdirectory(OpenMP)
 add_subdirectory(Transforms)
diff --git a/clang/lib/CIR/Dialect/IR/CMakeLists.txt 
b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
index c8205ebeabf6c..c5fa438253460 100644
--- a/clang/lib/CIR/Dialect/IR/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
@@ -13,6 +13,13 @@ add_clang_library(MLIRCIR
   MLIRCIROpInterfacesIncGen
   MLIRCIRLoopOpInterfaceIncGen
 
+  # CIRDialect.h is a public header and the most commonly-included header
+  # across the rest of clang/lib/CIR; building it here (rather than as a
+  # private per-library PCH) lets every other CIR library that links
+  # MLIRCIR automatically reuse this PCH too.
+  PRECOMPILE_HEADERS
+  [["clang/CIR/Dialect/IR/CIRDialect.h"]]
+
   LINK_LIBS PUBLIC
   MLIRIR
   MLIRCIRInterfaces
diff --git a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt 
b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
index 82078bf2e8f73..7208537642507 100644
--- a/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/Transforms/CMakeLists.txt
@@ -18,6 +18,10 @@ add_clang_library(MLIRCIRTransforms
   DEPENDS
   MLIRCIRPassIncGen
 
+  DISABLE_PCH_REUSE # PCH contains private headers
+  PRECOMPILE_HEADERS
+  [["pch.h"]]
+
   LINK_LIBS PUBLIC
   clangAST
   clangBasic
diff --git a/clang/lib/CIR/Dialect/Transforms/pch.h 
b/clang/lib/CIR/Dialect/Transforms/pch.h
new file mode 100644
index 0000000000000..df51a30d01e92
--- /dev/null
+++ b/clang/lib/CIR/Dialect/Transforms/pch.h
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// Precompiled header for MLIRCIRTransforms. Uses private headers.
+///
+//===----------------------------------------------------------------------===//
+
+#include "PassDetail.h"
+#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+#include "clang/CIR/Dialect/Transforms/CIRTransformUtils.h"
+#include "clang/CIR/MissingFeatures.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Transforms/DialectConversion.h"

``````````

</details>


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

Reply via email to