[clang] 362194c - [CIR] Register only the LLVM IR translations CIR lowers to (#221797)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 13:10:07 PDT 2026
Author: Fangrui Song
Date: 2026-09-07T13:10:02-07:00
New Revision: 362194cb4c7e61949d54dfd89b05442a11da25b8
URL: https://github.com/llvm/llvm-project/commit/362194cb4c7e61949d54dfd89b05442a11da25b8
DIFF: https://github.com/llvm/llvm-project/commit/362194cb4c7e61949d54dfd89b05442a11da25b8.diff
LOG: [CIR] Register only the LLVM IR translations CIR lowers to (#221797)
The ClangIR tests reach LLVM IR through mlir-translate, which links
every MLIR dialect and translation, so building check-clang builds most
of MLIR. Register mlir-to-llvmir in cir-translate over the same three
dialects and use it instead. Remove the dependency on `mlir-translate`
to run CIR tests.
ninja check-clang drops from 6499 to 5853 build edges.
LLM-aided
Added:
Modified:
clang/test/CIR/Lowering/lifetime.cir
clang/test/CIR/Lowering/stack-save-restore.cir
clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
clang/test/CIR/Transforms/abi-lowering/extend-signed-arg.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-bitint.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-complex.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-scalars.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-struct-direct.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-union-coerce-shapes.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-union.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-variadic-call.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-vector.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-vptr.cir
clang/test/CIR/Transforms/abi-lowering/x86_64-wide-floats.cir
clang/test/CMakeLists.txt
clang/tools/cir-translate/CMakeLists.txt
clang/tools/cir-translate/cir-translate.cpp
Removed:
################################################################################
diff --git a/clang/test/CIR/Lowering/lifetime.cir b/clang/test/CIR/Lowering/lifetime.cir
index 09a0f4b390cc8..4079fa609dcb5 100644
--- a/clang/test/CIR/Lowering/lifetime.cir
+++ b/clang/test/CIR/Lowering/lifetime.cir
@@ -1,4 +1,4 @@
-// RUN: cir-opt %s -cir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s
+// RUN: cir-opt %s -cir-to-llvm -o - | cir-translate -mlir-to-llvmir | FileCheck %s
!s32i = !cir.int<s, 32>
diff --git a/clang/test/CIR/Lowering/stack-save-restore.cir b/clang/test/CIR/Lowering/stack-save-restore.cir
index 9e30081e3f477..1f735abafc8af 100644
--- a/clang/test/CIR/Lowering/stack-save-restore.cir
+++ b/clang/test/CIR/Lowering/stack-save-restore.cir
@@ -1,5 +1,5 @@
// RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR
-// RUN: cir-opt %s -cir-to-llvm -o - | mlir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
+// RUN: cir-opt %s -cir-to-llvm -o - | cir-translate -mlir-to-llvmir | FileCheck %s -check-prefix=LLVM
!u8i = !cir.int<u, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir b/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
index 7f6a3ffb9d857..c280a85119998 100644
--- a/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
@@ -2,7 +2,7 @@
// RUN: | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering="classification-attr=test_classify" \
// RUN: -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s64i = !cir.int<s, 64>
diff --git a/clang/test/CIR/Transforms/abi-lowering/extend-signed-arg.cir b/clang/test/CIR/Transforms/abi-lowering/extend-signed-arg.cir
index 499db952ccf42..6798dcf88657d 100644
--- a/clang/test/CIR/Transforms/abi-lowering/extend-signed-arg.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/extend-signed-arg.cir
@@ -2,7 +2,7 @@
// RUN: | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering="classification-attr=test_classify" \
// RUN: -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s8i = !cir.int<s, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-bitint.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitint.cir
index 1a8f491fc9e7d..883e52f408b9e 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-bitint.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-bitint.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!b17i = !cir.int<s, 17, bitint>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-complex.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-complex.cir
index 5a148609a6bb8..6e36411c295eb 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-complex.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-complex.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s16i = !cir.int<s, 16>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
index 3de607561242f..d7f7d2566adb3 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-empty-class.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s32i = !cir.int<s, 32>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-scalars.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-scalars.cir
index e0d60fff66e32..04f11abc7b5d5 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-scalars.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-scalars.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s8i = !cir.int<s, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-direct.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-direct.cir
index f857529ee5d07..5a8ba5308192a 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-direct.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-struct-direct.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s8i = !cir.int<s, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-union-coerce-shapes.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-union-coerce-shapes.cir
index 32ff2eec40dc5..fab8a00323fd7 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-union-coerce-shapes.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-union-coerce-shapes.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s8i = !cir.int<s, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-union.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-union.cir
index b32680bbd98ea..dd3066848c460 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-union.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-union.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s8i = !cir.int<s, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-variadic-call.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-variadic-call.cir
index 80303dbdee129..dc3130d5e5d66 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-variadic-call.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-variadic-call.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s8i = !cir.int<s, 8>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-vector.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-vector.cir
index 0c1d41808c9de..d5d47a8491b44 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-vector.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-vector.cir
@@ -4,7 +4,7 @@
// RUN: cir-opt %s -cir-call-conv-lowering='target=x86_64 x86-avx-abi-level=avx512' \
// RUN: | FileCheck %s --check-prefix=AVX512
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s32i = !cir.int<s, 32>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-vptr.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-vptr.cir
index 37d16e3f1013e..de10afb52eed8 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-vptr.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-vptr.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s32i = !cir.int<s, 32>
diff --git a/clang/test/CIR/Transforms/abi-lowering/x86_64-wide-floats.cir b/clang/test/CIR/Transforms/abi-lowering/x86_64-wide-floats.cir
index 61ef20c3ebbff..99b0347c220f3 100644
--- a/clang/test/CIR/Transforms/abi-lowering/x86_64-wide-floats.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/x86_64-wide-floats.cir
@@ -1,6 +1,6 @@
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 | FileCheck %s
// RUN: cir-opt %s -cir-call-conv-lowering=target=x86_64 -cir-to-llvm -o - 2>/dev/null \
-// RUN: | mlir-translate -mlir-to-llvmir --allow-unregistered-dialect \
+// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
!s32i = !cir.int<s, 32>
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 304497490a3dc..b8adfa799bcae 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -117,7 +117,6 @@ if(CLANG_ENABLE_CIR)
list(APPEND CLANG_TEST_DEPS
cir-opt
cir-translate
- mlir-translate
)
add_subdirectory(CIR/lib)
endif()
diff --git a/clang/tools/cir-translate/CMakeLists.txt b/clang/tools/cir-translate/CMakeLists.txt
index 1e85c541457d9..bdbfa3133cdcf 100644
--- a/clang/tools/cir-translate/CMakeLists.txt
+++ b/clang/tools/cir-translate/CMakeLists.txt
@@ -1,7 +1,3 @@
-get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
-get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
-get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
-
include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
@@ -20,12 +16,16 @@ clang_target_link_libraries(cir-translate
target_link_libraries(cir-translate
PRIVATE
- ${dialect_libs}
- ${conversion_libs}
- ${translation_libs}
MLIRAnalysis
+ MLIRBuiltinToLLVMIRTranslation
MLIRDialect
+ MLIRDLTIDialect
+ MLIRFuncDialect
MLIRIR
+ MLIRLLVMDialect
+ MLIRLLVMToLLVMIRTranslation
+ MLIROpenMPToLLVMIRTranslation
+ MLIRTargetLLVMIRExport
MLIROptLib
MLIRParser
MLIRPass
diff --git a/clang/tools/cir-translate/cir-translate.cpp b/clang/tools/cir-translate/cir-translate.cpp
index a58512e3fca22..cefa7d2996f30 100644
--- a/clang/tools/cir-translate/cir-translate.cpp
+++ b/clang/tools/cir-translate/cir-translate.cpp
@@ -17,9 +17,11 @@
#include "mlir/Dialect/OpenMP/Utils/Utils.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/MLIRContext.h"
-#include "mlir/InitAllTranslations.h"
#include "mlir/Support/LogicalResult.h"
-#include "mlir/Target/LLVMIR/Dialect/All.h"
+#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
#include "mlir/Tools/mlir-translate/MlirTranslateMain.h"
#include "mlir/Tools/mlir-translate/Translation.h"
@@ -144,6 +146,12 @@ llvm::LogicalResult prepareCIRModuleForTranslation(mlir::ModuleOp mod) {
} // namespace
} // namespace cir
+static void registerLLVMIRTranslations(mlir::DialectRegistry ®istry) {
+ mlir::registerBuiltinDialectTranslation(registry);
+ mlir::registerLLVMDialectTranslation(registry);
+ mlir::registerOpenMPDialectTranslation(registry);
+}
+
void registerToLLVMTranslation() {
static llvm::cl::opt<bool> disableCCLowering(
"disable-cc-lowering",
@@ -172,12 +180,35 @@ void registerToLLVMTranslation() {
[](mlir::DialectRegistry ®istry) {
cir::registerAllDialects(registry);
registry.insert<mlir::func::FuncDialect>();
- mlir::registerAllToLLVMIRTranslations(registry);
+ registerLLVMIRTranslations(registry);
cir::direct::registerCIRDialectTranslation(registry);
});
}
+// Mirrors mlir::registerToLLVMIRTranslation, restricted to the dialects CIR
+// lowers to so that the ClangIR tests need not depend on mlir-translate, which
+// links every MLIR dialect.
+static void registerMLIRToLLVMIRTranslation() {
+ mlir::TranslateFromMLIRRegistration registration(
+ "mlir-to-llvmir", "Translate MLIR to LLVMIR",
+ [](mlir::Operation *op, mlir::raw_ostream &output) {
+ llvm::LLVMContext llvmContext;
+ std::unique_ptr<llvm::Module> llvmModule =
+ mlir::translateModuleToLLVMIR(op, llvmContext);
+ if (!llvmModule)
+ return mlir::failure();
+ llvmModule->renumberMetadataForAssembly();
+ llvmModule->print(output, nullptr);
+ return mlir::success();
+ },
+ [](mlir::DialectRegistry ®istry) {
+ registry.insert<mlir::DLTIDialect, mlir::func::FuncDialect>();
+ registerLLVMIRTranslations(registry);
+ });
+}
+
int main(int argc, char **argv) {
registerToLLVMTranslation();
+ registerMLIRToLLVMIRTranslation();
return failed(mlir::mlirTranslateMain(argc, argv, "CIR Translation Tool"));
}
More information about the cfe-commits
mailing list