[llvm-branch-commits] [mlir] [mlir][LLVM] Reuse a PCH for MLIRLLVMDialect (NFC) (PR #222578)

Mehdi Amini via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Sep 10 03:04:17 PDT 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/222578

Build a private precompiled header from the LLVM dialect and LLVM IR headers and use it for MLIRLLVMDialect. Build dialect libraries before conversions so the PCH is available early and repeated parsing is avoided.

Relative to the MLIRIR PCH parent, clean Release builds of LLVM and MLIR with `ninja -j16` improved as follows:

```
  wall:   420.41s -> 398.79s (-5.14%)
  user:  6125.97s -> 5789.14s (-5.50%)
  system: 481.88s -> 455.05s (-5.57%)
```

Assisted-by: Codex

>From 81b343fb9c047c130744e77e7c04885b715a5031 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 9 Sep 2026 00:45:30 -0700
Subject: [PATCH] [mlir][LLVM] Reuse a PCH for MLIRLLVMDialect (NFC)

Build a private precompiled header from the LLVM dialect and LLVM IR headers
and use it for MLIRLLVMDialect. Build dialect libraries before conversions so
the PCH is available early and repeated parsing is avoided.

Relative to the MLIRIR PCH parent, clean Release builds of LLVM and MLIR with
Ninja -j16 pinned to CPUs 16-31 improved as follows:

  wall:   420.41s -> 398.79s (-5.14%)
  user:  6125.97s -> 5789.14s (-5.50%)
  system: 481.88s -> 455.05s (-5.57%)

Assisted-by: Codex
---
 mlir/include/mlir/Dialect/LLVMIR/pch.h | 14 ++++++++++++++
 mlir/lib/CMakeLists.txt                |  2 +-
 mlir/lib/Dialect/LLVMIR/CMakeLists.txt |  3 +++
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 mlir/include/mlir/Dialect/LLVMIR/pch.h

diff --git a/mlir/include/mlir/Dialect/LLVMIR/pch.h b/mlir/include/mlir/Dialect/LLVMIR/pch.h
new file mode 100644
index 0000000000000..644a670894515
--- /dev/null
+++ b/mlir/include/mlir/Dialect/LLVMIR/pch.h
@@ -0,0 +1,14 @@
+//===- pch.h - Precompiled header for MLIR LLVM dialect --------*- C++ -*-===//
+//
+// 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 MLIRLLVMDialect.
+///
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "llvm/IR/pch.h"
diff --git a/mlir/lib/CMakeLists.txt b/mlir/lib/CMakeLists.txt
index 7adf344099ed2..97adaa3e26631 100644
--- a/mlir/lib/CMakeLists.txt
+++ b/mlir/lib/CMakeLists.txt
@@ -7,9 +7,9 @@ add_subdirectory(ABI)
 add_subdirectory(Analysis)
 add_subdirectory(AsmParser)
 add_subdirectory(Bytecode)
+add_subdirectory(Dialect)
 add_subdirectory(Conversion)
 add_subdirectory(Debug)
-add_subdirectory(Dialect)
 add_subdirectory(Interfaces)
 add_subdirectory(Parser)
 add_subdirectory(Pass)
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index aa65ae820c817..cae75e5c2dfe4 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -28,6 +28,9 @@ add_mlir_dialect_library(MLIRLLVMDialect
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
 
+  PRECOMPILE_HEADERS
+  [["mlir/Dialect/LLVMIR/pch.h"]]
+
   DEPENDS
   MLIRLLVMDialectBytecodeIncGen
   MLIRLLVMInterfacesIncGen



More information about the llvm-branch-commits mailing list