[Mlir-commits] [mlir] [mlir] Reuse a precompiled header for MLIRIR (NFC) (PR #222576)

Mehdi Amini llvmlistbot at llvm.org
Thu Sep 10 03:03:08 PDT 2026


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

Build a private precompiled header from the common MLIR IR headers and use it for MLIRIR. Build Support and IR first so the PCH is available early, and qualify the LLVM LSP Location name that the broader header surface exposes.

On current main, clean Release builds of LLVM and MLIR with `ninja -j16`  improved as follows:

```
  wall:   535.99s -> 420.41s (-21.56%)
  user:  7550.29s -> 6125.97s (-18.86%)
  system: 569.85s -> 481.88s (-15.44%)
```

Assisted-by: Codex

>From cdf702dcad4ec051a0fbb22215ddd8bf579ccba0 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Tue, 8 Sep 2026 23:42:40 -0700
Subject: [PATCH] [mlir] Reuse a precompiled header for MLIRIR (NFC)

Build a private precompiled header from the common MLIR IR headers and use it
for MLIRIR. Build Support and IR first so the PCH is available early, and
qualify the LLVM LSP Location name that the broader header surface exposes.

On current main, clean Release builds of LLVM and MLIR with Ninja -j16 pinned
to CPUs 16-31 improved as follows:

  wall:   535.99s -> 420.41s (-21.56%)
  user:  7550.29s -> 6125.97s (-18.86%)
  system: 569.85s -> 481.88s (-15.44%)

Assisted-by: Codex
---
 mlir/include/mlir/IR/pch.h                   | 20 ++++++++++++++++++++
 mlir/lib/CMakeLists.txt                      |  4 ++--
 mlir/lib/IR/CMakeLists.txt                   |  3 +++
 mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp | 16 ++++++++--------
 4 files changed, 33 insertions(+), 10 deletions(-)
 create mode 100644 mlir/include/mlir/IR/pch.h

diff --git a/mlir/include/mlir/IR/pch.h b/mlir/include/mlir/IR/pch.h
new file mode 100644
index 0000000000000..214839dd9352e
--- /dev/null
+++ b/mlir/include/mlir/IR/pch.h
@@ -0,0 +1,20 @@
+//===- pch.h - Precompiled header for MLIR core ---------------*- 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 MLIRIR.
+///
+//===----------------------------------------------------------------------===//
+
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/IR/SymbolTable.h"
diff --git a/mlir/lib/CMakeLists.txt b/mlir/lib/CMakeLists.txt
index 576942b78f4a8..7adf344099ed2 100644
--- a/mlir/lib/CMakeLists.txt
+++ b/mlir/lib/CMakeLists.txt
@@ -1,6 +1,8 @@
 # Enable errors for any global constructors.
 add_flag_if_supported("-Werror=global-constructors" WERROR_GLOBAL_CONSTRUCTOR)
 
+add_subdirectory(Support)
+add_subdirectory(IR)
 add_subdirectory(ABI)
 add_subdirectory(Analysis)
 add_subdirectory(AsmParser)
@@ -8,7 +10,6 @@ add_subdirectory(Bytecode)
 add_subdirectory(Conversion)
 add_subdirectory(Debug)
 add_subdirectory(Dialect)
-add_subdirectory(IR)
 add_subdirectory(Interfaces)
 add_subdirectory(Parser)
 add_subdirectory(Pass)
@@ -16,7 +17,6 @@ add_subdirectory(Query)
 add_subdirectory(Reducer)
 add_subdirectory(Remark)
 add_subdirectory(Rewrite)
-add_subdirectory(Support)
 add_subdirectory(TableGen)
 add_subdirectory(Target)
 add_subdirectory(Tools)
diff --git a/mlir/lib/IR/CMakeLists.txt b/mlir/lib/IR/CMakeLists.txt
index 9c9727fb8e981..01c80dafcd21a 100644
--- a/mlir/lib/IR/CMakeLists.txt
+++ b/mlir/lib/IR/CMakeLists.txt
@@ -50,6 +50,9 @@ add_mlir_library(MLIRIR
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
 
+  PRECOMPILE_HEADERS
+  [["mlir/IR/pch.h"]]
+
   DEPENDS
   MLIRBuiltinAttributesIncGen
   MLIRBuiltinAttributeInterfacesIncGen
diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
index 73ebe6a6b1f09..9df65dd61488e 100644
--- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp
@@ -32,7 +32,6 @@ using llvm::lsp::Hover;
 using llvm::lsp::InitializedParams;
 using llvm::lsp::InitializeParams;
 using llvm::lsp::JSONTransport;
-using llvm::lsp::Location;
 using llvm::lsp::Logger;
 using llvm::lsp::MessageHandler;
 using llvm::lsp::MLIRConvertBytecodeParams;
@@ -72,9 +71,9 @@ struct LSPServer {
   // Definitions and References
 
   void onGoToDefinition(const TextDocumentPositionParams &params,
-                        Callback<std::vector<Location>> reply);
+                        Callback<std::vector<llvm::lsp::Location>> reply);
   void onReference(const ReferenceParams &params,
-                   Callback<std::vector<Location>> reply);
+                   Callback<std::vector<llvm::lsp::Location>> reply);
 
   //===--------------------------------------------------------------------===//
   // Hover
@@ -240,16 +239,17 @@ void LSPServer::onDocumentDidChange(const DidChangeTextDocumentParams &params) {
 // Definitions and References
 //===----------------------------------------------------------------------===//
 
-void LSPServer::onGoToDefinition(const TextDocumentPositionParams &params,
-                                 Callback<std::vector<Location>> reply) {
-  std::vector<Location> locations;
+void LSPServer::onGoToDefinition(
+    const TextDocumentPositionParams &params,
+    Callback<std::vector<llvm::lsp::Location>> reply) {
+  std::vector<llvm::lsp::Location> locations;
   server.getLocationsOf(params.textDocument.uri, params.position, locations);
   reply(std::move(locations));
 }
 
 void LSPServer::onReference(const ReferenceParams &params,
-                            Callback<std::vector<Location>> reply) {
-  std::vector<Location> locations;
+                            Callback<std::vector<llvm::lsp::Location>> reply) {
+  std::vector<llvm::lsp::Location> locations;
   server.findReferencesOf(params.textDocument.uri, params.position, locations);
   reply(std::move(locations));
 }



More information about the Mlir-commits mailing list