[Mlir-commits] [mlir] [MLIR] Convert LLVMImportDialectInterface using ODS (PR #181923)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 17 14:11:14 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
Author: AidinT (aidint)
<details>
<summary>Changes</summary>
This PR generates LLVMImportDialectInterface using ODS.
---
Full diff: https://github.com/llvm/llvm-project/pull/181923.diff
4 Files Affected:
- (modified) mlir/include/mlir/Target/LLVMIR/CMakeLists.txt (+4)
- (added) mlir/include/mlir/Target/LLVMIR/LLVMImportDialectInterface.td (+96)
- (modified) mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h (+3-63)
- (modified) mlir/lib/Target/LLVMIR/CMakeLists.txt (+3)
``````````diff
diff --git a/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt b/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
index 39b3674156dad..8cf9a9cd864da 100644
--- a/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
+++ b/mlir/include/mlir/Target/LLVMIR/CMakeLists.txt
@@ -3,3 +3,7 @@ add_subdirectory(Transforms)
set(LLVM_TARGET_DEFINITIONS LLVMTranslationDialectInterface.td)
mlir_tablegen(LLVMTranslationDialectInterface.h.inc -gen-dialect-interface-decls)
add_mlir_generic_tablegen_target(MLIRLLVMTranslationDialectInterfaceIncGen)
+
+set(LLVM_TARGET_DEFINITIONS LLVMImportDialectInterface.td)
+mlir_tablegen(LLVMImportDialectInterface.h.inc -gen-dialect-interface-decls)
+add_mlir_generic_tablegen_target(MLIRLLVMImportDialectInterfaceIncGen)
diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMImportDialectInterface.td b/mlir/include/mlir/Target/LLVMIR/LLVMImportDialectInterface.td
new file mode 100644
index 0000000000000..93e6fcf327086
--- /dev/null
+++ b/mlir/include/mlir/Target/LLVMIR/LLVMImportDialectInterface.td
@@ -0,0 +1,96 @@
+#ifndef MLIR_INTERFACES_LLVMIMPORTDIALECTINTERFACE
+#define MLIR_INTERFACES_LLVMIMPORTDIALECTINTERFACE
+
+include "mlir/IR/Interfaces.td"
+
+def LLVMImportDialectInterface : DialectInterface<"LLVMImportDialectInterface"> {
+ let description = [{
+ Base class for dialect interfaces used to import LLVM IR. Dialects that can
+ be imported should provide an implementation of this interface for the
+ supported intrinsics. 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 interfaces to implement the import of
+ intrinsics into MLIR.
+ }],
+ "::llvm::LogicalResult", "convertIntrinsic",
+ (ins "::mlir::OpBuilder &":$builder, "::llvm::CallInst *":$inst,
+ "::mlir::LLVM::ModuleImport &":$moduleImport),
+ [{
+ return ::llvm::failure();
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interfaces to implement the import of
+ instructions into MLIR.
+ }],
+ "::llvm::LogicalResult", "convertInstruction",
+ (ins "::mlir::OpBuilder &":$builder, "::llvm::Instruction *":$inst,
+ "::mlir::ArrayRef<llvm::Value *>":$llvmOperands,
+ "::mlir::LLVM::ModuleImport &":$moduleImport),
+ [{
+ return ::llvm::failure();
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interfaces to implement the import of metadata
+ into MLIR. Attaches the converted metadata kind and node to the provided
+ operation.
+ }],
+ "::mlir::LogicalResult", "setMetadataAttrs",
+ (ins "::mlir::OpBuilder &":$builder, "unsigned":$kind,
+ "::llvm::MDNode *":$node, "::mlir::Operation *":$op,
+ "::mlir::LLVM::ModuleImport &":$moduleImport),
+ [{
+ return ::llvm::failure();
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interfaces to publish the supported intrinsics.
+ As every LLVM IR intrinsic has a unique integer identifier, the function
+ returns the list of supported intrinsic identifiers.
+ }],
+ "::mlir::ArrayRef<unsigned>", "getSupportedIntrinsics", (ins),
+ [{
+ return {};
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interfaces to publish the supported instructions.
+ As every LLVM IR instruction has a unique integer identifier, the function
+ returns the list of supported instruction identifiers. These identifiers
+ will then be used to match LLVM instructions to the appropriate import
+ interface and `convertInstruction` method. It is an error to have multiple
+ interfaces overriding the same instruction.
+ }],
+ "::mlir::ArrayRef<unsigned>", "getSupportedInstructions", (ins),
+ [{
+ return {};
+ }]
+ >,
+ InterfaceMethod<[{
+ Hook for derived dialect interfaces to publish the supported metadata
+ kinds. As every metadata kind has a unique integer identifier, the
+ function returns the list of supported metadata identifiers. The
+ `llvmContext` parameter is used to obtain identifiers for metadata kinds
+ that do not have a fixed static identifier. Since different LLVM contexts
+ can assign different identifiers to these non-static metadata kinds, the
+ function must recompute the list of supported metadata identifiers on each
+ call.
+ }],
+ "::mlir::SmallVector<unsigned>", "getSupportedMetadata",
+ (ins "::llvm::LLVMContext &":$llvmContext),
+ [{
+ return {};
+ }]
+ >
+ ];
+}
+
+#endif
diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h b/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h
index 0e50fac7e85dd..1c1d56b720a22 100644
--- a/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h
+++ b/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h
@@ -31,71 +31,11 @@ namespace mlir {
namespace LLVM {
class ModuleImport;
} // namespace LLVM
+} // namespace mlir
-/// Base class for dialect interfaces used to import LLVM IR. Dialects that can
-/// be imported should provide an implementation of this interface for the
-/// supported intrinsics. 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 LLVMImportDialectInterface
- : public DialectInterface::Base<LLVMImportDialectInterface> {
-public:
- LLVMImportDialectInterface(Dialect *dialect) : Base(dialect) {}
-
- /// Hook for derived dialect interfaces to implement the import of
- /// intrinsics into MLIR.
- virtual LogicalResult
- convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
- LLVM::ModuleImport &moduleImport) const {
- return failure();
- }
-
- /// Hook for derived dialect interfaces to implement the import of
- /// instructions into MLIR.
- virtual LogicalResult
- convertInstruction(OpBuilder &builder, llvm::Instruction *inst,
- ArrayRef<llvm::Value *> llvmOperands,
- LLVM::ModuleImport &moduleImport) const {
- return failure();
- }
-
- /// Hook for derived dialect interfaces to implement the import of metadata
- /// into MLIR. Attaches the converted metadata kind and node to the provided
- /// operation.
- virtual LogicalResult
- setMetadataAttrs(OpBuilder &builder, unsigned kind, llvm::MDNode *node,
- Operation *op, LLVM::ModuleImport &moduleImport) const {
- return failure();
- }
-
- /// Hook for derived dialect interfaces to publish the supported intrinsics.
- /// As every LLVM IR intrinsic has a unique integer identifier, the function
- /// returns the list of supported intrinsic identifiers.
- virtual ArrayRef<unsigned> getSupportedIntrinsics() const { return {}; }
-
- /// Hook for derived dialect interfaces to publish the supported instructions.
- /// As every LLVM IR instruction has a unique integer identifier, the function
- /// returns the list of supported instruction identifiers. These identifiers
- /// will then be used to match LLVM instructions to the appropriate import
- /// interface and `convertInstruction` method. It is an error to have multiple
- /// interfaces overriding the same instruction.
- virtual ArrayRef<unsigned> getSupportedInstructions() const { return {}; }
-
- /// Hook for derived dialect interfaces to publish the supported metadata
- /// kinds. As every metadata kind has a unique integer identifier, the
- /// function returns the list of supported metadata identifiers. The
- /// `llvmContext` parameter is used to obtain identifiers for metadata kinds
- /// that do not have a fixed static identifier. Since different LLVM contexts
- /// can assign different identifiers to these non-static metadata kinds, the
- /// function must recompute the list of supported metadata identifiers on each
- /// call.
- virtual SmallVector<unsigned>
- getSupportedMetadata(llvm::LLVMContext &llvmContext) const {
- return {};
- }
-};
+#include "mlir/Target/LLVMIR/LLVMImportDialectInterface.h.inc"
+namespace mlir {
/// Interface collection for the import of LLVM IR that dispatches to a concrete
/// dialect interface implementation. Queries the dialect interfaces to obtain a
/// list of the supported LLVM IR constructs and then builds a mapping for the
diff --git a/mlir/lib/Target/LLVMIR/CMakeLists.txt b/mlir/lib/Target/LLVMIR/CMakeLists.txt
index a73a78d17c134..db221697edd05 100644
--- a/mlir/lib/Target/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Target/LLVMIR/CMakeLists.txt
@@ -76,6 +76,9 @@ add_mlir_translation_library(MLIRTargetLLVMIRImport
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
+ DEPENDS
+ MLIRLLVMImportDialectInterfaceIncGen
+
LINK_COMPONENTS
Core
IRReader
``````````
</details>
https://github.com/llvm/llvm-project/pull/181923
More information about the Mlir-commits
mailing list