[clang] [CIR] Enable PCH Build- (PR #222201)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 8 17:04:14 PDT 2026
https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/222201
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 -->7m42
user: 612m53-->585m18
sys: 36m27 -->34m57
I suspect there are more gains to be had by adding other files here, but this improvement seems worth doing.
>From 91a6f188abe06810f2722c7e116e584ccce88bd5 Mon Sep 17 00:00:00 2001
From: erichkeane <ekeane at nvidia.com>
Date: Tue, 8 Sep 2026 16:15:46 -0700
Subject: [PATCH] [CIR] Enable PCH Build-
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 -->7m42
user: 612m53-->585m18
sys: 36m27 -->34m57
I suspect there are more gains to be had by adding other files here, but
this improvement seems worth doing.
---
clang/lib/CIR/CodeGen/CMakeLists.txt | 4 ++++
clang/lib/CIR/CodeGen/pch.h | 23 +++++++++++++++++++
clang/lib/CIR/Dialect/CMakeLists.txt | 7 +++++-
clang/lib/CIR/Dialect/IR/CMakeLists.txt | 7 ++++++
.../lib/CIR/Dialect/Transforms/CMakeLists.txt | 4 ++++
clang/lib/CIR/Dialect/Transforms/pch.h | 20 ++++++++++++++++
6 files changed, 64 insertions(+), 1 deletion(-)
create mode 100644 clang/lib/CIR/CodeGen/pch.h
create mode 100644 clang/lib/CIR/Dialect/Transforms/pch.h
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"
More information about the cfe-commits
mailing list