[Mlir-commits] [mlir] [MLIR] convert LLVMTranslationDialectInterface using ODS (PR #181391)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Feb 16 13:08:18 PST 2026
https://github.com/aidint updated https://github.com/llvm/llvm-project/pull/181391
>From c64189cd2e0ca8aadebcf55cb9f6dd8cf931bd79 Mon Sep 17 00:00:00 2001
From: aidint <at.aidin at gmail.com>
Date: Fri, 13 Feb 2026 18:44:34 +0100
Subject: [PATCH 1/3] convert LLVMTranslationDialectInterface using ODS
---
.../include/mlir/Target/LLVMIR/CMakeLists.txt | 4 ++
.../LLVMIR/LLVMTranslationDialectInterface.td | 64 +++++++++++++++++++
.../Target/LLVMIR/LLVMTranslationInterface.h | 44 +------------
mlir/lib/Dialect/LLVMIR/CMakeLists.txt | 1 +
4 files changed, 72 insertions(+), 41 deletions(-)
create mode 100644 mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
diff --git a/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt b/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
index e31af32661164..39b3674156dad 100644
--- a/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
+++ b/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
@@ -1 +1,5 @@
add_subdirectory(Transforms)
+
+set(LLVM_TARGET_DEFINITIONS LLVMTranslationDialectInterface.td)
+mlir_tablegen(LLVMTranslationDialectInterface.h.inc -gen-dialect-interface-decls)
+add_mlir_generic_tablegen_target(MLIRLLVMTranslationDialectInterfaceIncGen)
diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
new file mode 100644
index 0000000000000..1fb7d20cd123f
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
@@ -0,0 +1,64 @@
+#ifndef MLIR_INTERFACES_LLVMTRANSLATIONDIALECTINTERFACE
+#define MLIR_INTERFACES_LLVMTRANSLATIONDIALECTINTERFACE
+
+
+include "mlir/IR/Interfaces.td"
+
+def LLVMTranslationDialectInterface : DialectInterface<"LLVMTranslationDialectInterface"> {
+ let description = [{
+ Base class for dialect interfaces providing translation to LLVM IR.
+ Dialects that can be translated should provide an implementation of this
+ interface for the supported operations. The interface may be implemented in
+ a separate library to avoid the "main" dialect library depending on LLVM IR.
+ The interface can be attached using the delayed registration mechanism
+ available in DialectRegistry.
+ }];
+ let cppNamespace = "::mlir";
+
+ let methods = [
+ InterfaceMethod<[{
+ Hook for derived dialect interface to provide translation of the
+ operations to LLVM IR.
+ }],
+ "::mlir::LogicalResult", "convertOperation",
+ (ins "::mlir::Operation *":$op, "::llvm::IRBuilderBase &":$builder,
+ "::mlir::LLVM::ModuleTranslation &":$moduleTranslation),
+ [{
+ return ::llvm::failure();
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interface to act on an operation that has dialect
+ attributes from the derived dialect (the operation itself may be from a
+ different dialect). This gets called after the operation has been
+ translated. The hook is expected to use moduleTranslation to look up the
+ translation results and amend the corresponding IR constructs. Does
+ nothing and succeeds by default.
+ }],
+ "::mlir::LogicalResult", "amendOperation",
+ (ins "::mlir::Operation *":$op,
+ "::mlir::ArrayRef<::llvm::Instruction *>":$instructions,
+ "::mlir::NamedAttribute":$attribute,
+ "::mlir::LLVM::ModuleTranslation &":$moduleTranslation),
+ [{
+ return ::llvm::success();
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interface to translate or act on a derived
+ dialect attribute that appears on a function parameter. This gets called
+ after the function operation has been translated.
+ }],
+ "::mlir::LogicalResult", "convertParameterAttr",
+ (ins "::mlir::LLVM::LLVMFuncOp":$function, "int":$argIdx,
+ "::mlir::NamedAttribute":$attr,
+ "::mlir::LLVM::ModuleTranslation &":$moduleTranslation),
+ [{
+ return ::llvm::success();
+ }]
+ >
+ ];
+}
+
+
+#endif
diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h
index 11cb836183920..58d3ee0ed2139 100644
--- a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h
+++ b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h
@@ -27,49 +27,11 @@ namespace LLVM {
class ModuleTranslation;
class LLVMFuncOp;
} // namespace LLVM
+} // namespace mlir
-/// Base class for dialect interfaces providing translation to LLVM IR.
-/// Dialects that can be translated should provide an implementation of this
-/// interface for the supported operations. The interface may be implemented in
-/// a separate library to avoid the "main" dialect library depending on LLVM IR.
-/// The interface can be attached using the delayed registration mechanism
-/// available in DialectRegistry.
-class LLVMTranslationDialectInterface
- : public DialectInterface::Base<LLVMTranslationDialectInterface> {
-public:
- LLVMTranslationDialectInterface(Dialect *dialect) : Base(dialect) {}
-
- /// Hook for derived dialect interface to provide translation of the
- /// operations to LLVM IR.
- virtual LogicalResult
- convertOperation(Operation *op, llvm::IRBuilderBase &builder,
- LLVM::ModuleTranslation &moduleTranslation) const {
- return failure();
- }
-
- /// Hook for derived dialect interface to act on an operation that has dialect
- /// attributes from the derived dialect (the operation itself may be from a
- /// different dialect). This gets called after the operation has been
- /// translated. The hook is expected to use moduleTranslation to look up the
- /// translation results and amend the corresponding IR constructs. Does
- /// nothing and succeeds by default.
- virtual LogicalResult
- amendOperation(Operation *op, ArrayRef<llvm::Instruction *> instructions,
- NamedAttribute attribute,
- LLVM::ModuleTranslation &moduleTranslation) const {
- return success();
- }
+#include "mlir/Target/LLVMIR/LLVMTranslationDialectInterface.h.inc"
- /// Hook for derived dialect interface to translate or act on a derived
- /// dialect attribute that appears on a function parameter. This gets called
- /// after the function operation has been translated.
- virtual LogicalResult
- convertParameterAttr(LLVM::LLVMFuncOp function, int argIdx,
- NamedAttribute attr,
- LLVM::ModuleTranslation &moduleTranslation) const {
- return success();
- }
-};
+namespace mlir {
/// Interface collection for translation to LLVM IR, dispatches to a concrete
/// interface implementation based on the dialect to which the given op belongs.
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index a73f0c1278ec0..db8cb5f65c260 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -20,6 +20,7 @@ add_mlir_dialect_library(MLIRLLVMDialect
MLIRLLVMIntrinsicOpsIncGen
MLIRLLVMInterfacesIncGen
MLIROpenMPOpsIncGen
+ MLIRLLVMTranslationDialectInterfaceIncGen
intrinsics_gen
LINK_COMPONENTS
>From 14840d98c627a0d4102c449aa7977453f33c5754 Mon Sep 17 00:00:00 2001
From: aidint <at.aidin at gmail.com>
Date: Sun, 15 Feb 2026 18:57:07 +0100
Subject: [PATCH 2/3] apply requested changes
---
.../mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td | 1 -
mlir/lib/Dialect/LLVMIR/CMakeLists.txt | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
index 1fb7d20cd123f..6d8c7174bd2e3 100644
--- a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
+++ b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
@@ -1,7 +1,6 @@
#ifndef MLIR_INTERFACES_LLVMTRANSLATIONDIALECTINTERFACE
#define MLIR_INTERFACES_LLVMTRANSLATIONDIALECTINTERFACE
-
include "mlir/IR/Interfaces.td"
def LLVMTranslationDialectInterface : DialectInterface<"LLVMTranslationDialectInterface"> {
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index db8cb5f65c260..9f8fac7891d2e 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -20,8 +20,8 @@ add_mlir_dialect_library(MLIRLLVMDialect
MLIRLLVMIntrinsicOpsIncGen
MLIRLLVMInterfacesIncGen
MLIROpenMPOpsIncGen
- MLIRLLVMTranslationDialectInterfaceIncGen
intrinsics_gen
+ MLIRLLVMTranslationDialectInterfaceIncGen
LINK_COMPONENTS
BinaryFormat
>From 26270aaa41df44d3cf0eb339a3e6f321ad203498 Mon Sep 17 00:00:00 2001
From: aidint <at.aidin at gmail.com>
Date: Mon, 16 Feb 2026 22:08:01 +0100
Subject: [PATCH 3/3] sort dependencies
---
mlir/lib/Dialect/LLVMIR/CMakeLists.txt | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index 9f8fac7891d2e..21b60ae747a71 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -15,13 +15,13 @@ add_mlir_dialect_library(MLIRLLVMDialect
DEPENDS
MLIRLLVMDialectBytecodeIncGen
+ MLIRLLVMInterfacesIncGen
+ MLIRLLVMIntrinsicOpsIncGen
MLIRLLVMOpsIncGen
+ MLIRLLVMTranslationDialectInterfaceIncGen
MLIRLLVMTypesIncGen
- MLIRLLVMIntrinsicOpsIncGen
- MLIRLLVMInterfacesIncGen
MLIROpenMPOpsIncGen
intrinsics_gen
- MLIRLLVMTranslationDialectInterfaceIncGen
LINK_COMPONENTS
BinaryFormat
More information about the Mlir-commits
mailing list