[Mlir-commits] [mlir] [MLIR] convert LLVMTranslationDialectInterface using ODS (PR #181391)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 13 09:46:41 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm

@llvm/pr-subscribers-mlir

Author: AidinT (aidint)

<details>
<summary>Changes</summary>

This PR converts LLVMTranslationDialectInterface using ODS

---
Full diff: https://github.com/llvm/llvm-project/pull/181391.diff


4 Files Affected:

- (modified) mlir/include/mlir/Target/LLVMIR/CMakeLists.txt (+4) 
- (added) mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td (+64) 
- (modified) mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h (+3-41) 
- (modified) mlir/lib/Dialect/LLVMIR/CMakeLists.txt (+1) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/181391


More information about the Mlir-commits mailing list