[Mlir-commits] [mlir] [mlir][NVVM][NFC] Predeclare `ModuleTranslation` to improve build times (PR #232727)

Markus Böck llvmlistbot at llvm.org
Fri Oct 16 05:56:50 PDT 2026


https://github.com/zero9178 created https://github.com/llvm/llvm-project/pull/232727

The NVVMDialect's LLVM IR export is currently layered such that it is interwoven with the dialect implementation. For many ops, a `getIntrinsicIDAndArgs` method implements the translation to LLVM IR and requires the declaration of `mlir::LLVM::ModuleTranslation`. The header for the latter is a rather heavy header that includes all of OpenMP Dialect and more.

This PR makes NVVMDialect.h faster to parse by predeclaring `mlir::LLVM::ModuleTranslation` rather than including its definition. In a local build tested on a AMD Ryzen Threadripper PRO 5975WX this saved aorund 2.4s of compile time per-file that includes NVVMDialect.h for a total of 65.4s of CPU time saved.

I believe that ideally the LLVM IR translation should be moved to and contained in NVVMToLLVMIRTranslation but is left as a future change after these "easy" compile time changes have been applied.

>From 012883ebc269e56ed3609fa6ea3c77a862d87491 Mon Sep 17 00:00:00 2001
From: mboeck <mboeck at nvidia.com>
Date: Fri, 16 Oct 2026 12:54:47 +0000
Subject: [PATCH] [mlir][NVVM][NFC] Predeclare `ModuleTranslation` to improve
 build times

The NVVMDialect's LLVM IR export is currently layered such that it is interwoven with the dialect implementation. For many ops, a `getIntrinsicIDAndArgs` method implements the translation to LLVM IR and requires the definition of `mlir::LLVM::ModuleTranslation`. The header for the latter is a rather heavy header that includes all of OpenMP Dialect and more.

This PR makes NVVMDialect.h faster to parse by predeclaring `mlir::LLVM::ModuleTranslation` rather than including its definition.
In a local build tested on a AMD Ryzen Threadripper PRO 5975WX this saved aorund 2.4s of compile time per-file that includes NVVMDialect.h for a total of 65.4s of CPU time saved.

I believe that ideally the LLVM IR translation should be properly moved to and contained in NVVMToLLVMIRTranslation but is left as a future change after these "easy" compile time changes have been applied.
---
 mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h | 4 +++-
 mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp     | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h
index 0cc509c062c5d4..31df487dac9678 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h
+++ b/mlir/include/mlir/Dialect/LLVMIR/NVVMDialect.h
@@ -25,7 +25,6 @@
 #include "mlir/IR/OpDefinition.h"
 #include "mlir/Interfaces/InferIntRangeInterface.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
-#include "mlir/Target/LLVMIR/ModuleTranslation.h"
 #include "llvm/IR/IntrinsicsNVPTX.h"
 
 #include "mlir/Dialect/LLVMIR/NVVMOpsEnums.h.inc"
@@ -62,6 +61,9 @@ std::pair<mlir::Type, unsigned> inferMMAType(mlir::NVVM::MMATypes type,
                                              int nCol,
                                              mlir::MLIRContext *context);
 } // namespace NVVM
+namespace LLVM {
+class ModuleTranslation;
+} // namespace LLVM
 } // namespace mlir
 
 ///// Ops /////
diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
index 1a300b1e7f41c7..bb2db355d567f2 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
@@ -30,6 +30,7 @@
 #include "mlir/IR/Operation.h"
 #include "mlir/IR/OperationSupport.h"
 #include "mlir/IR/Types.h"
+#include "mlir/Target/LLVMIR/ModuleTranslation.h"
 #include "mlir/Transforms/InliningUtils.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/TypeSwitch.h"



More information about the Mlir-commits mailing list