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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Feb 17 05:24:15 PST 2026


Author: AidinT
Date: 2026-02-17T05:24:11-08:00
New Revision: 0106783f0306604d5c4bd35e2d32273f03f77fbb

URL: https://github.com/llvm/llvm-project/commit/0106783f0306604d5c4bd35e2d32273f03f77fbb
DIFF: https://github.com/llvm/llvm-project/commit/0106783f0306604d5c4bd35e2d32273f03f77fbb.diff

LOG: [MLIR] convert LLVMTranslationDialectInterface using ODS (#181391)

This PR converts LLVMTranslationDialectInterface using ODS

Added: 
    mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td

Modified: 
    mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
    mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h
    mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Removed: 
    


################################################################################
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..6d8c7174bd2e3
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationDialectInterface.td
@@ -0,0 +1,63 @@
+#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
+        
diff erent 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
-  /// 
diff erent 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..21b60ae747a71 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -15,10 +15,11 @@ add_mlir_dialect_library(MLIRLLVMDialect
 
   DEPENDS
   MLIRLLVMDialectBytecodeIncGen
+  MLIRLLVMInterfacesIncGen
+  MLIRLLVMIntrinsicOpsIncGen
   MLIRLLVMOpsIncGen
+  MLIRLLVMTranslationDialectInterfaceIncGen
   MLIRLLVMTypesIncGen
-  MLIRLLVMIntrinsicOpsIncGen
-  MLIRLLVMInterfacesIncGen
   MLIROpenMPOpsIncGen
   intrinsics_gen
 


        


More information about the Mlir-commits mailing list