[Mlir-commits] [mlir] 38b106f - Improve error message when tring to export to LLVM IR with a dialect missing the interface

Mehdi Amini llvmlistbot at llvm.org
Thu Apr 8 16:21:37 PDT 2021


Author: Mehdi Amini
Date: 2021-04-08T23:21:27Z
New Revision: 38b106f6815716db4757a813d28ba4649d083c14

URL: https://github.com/llvm/llvm-project/commit/38b106f6815716db4757a813d28ba4649d083c14
DIFF: https://github.com/llvm/llvm-project/commit/38b106f6815716db4757a813d28ba4649d083c14.diff

LOG: Improve error message when tring to export to LLVM IR with a dialect missing the interface

Dialects can be translated to LLVM IR when they have the
LLVMTranslationDialectInterface interface registered. In case the
interface isn't explicitly registered, even the LLVM dialect can't be
exported to LLVM IR. This make the error message more explicit on this.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D96729

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index a8d9f44d702d..3705a6a72a38 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -303,13 +303,20 @@ llvm::Value *mlir::LLVM::detail::createIntrinsicCall(
 /// Given a single MLIR operation, create the corresponding LLVM IR operation
 /// using the `builder`.
 LogicalResult
-ModuleTranslation::convertOperation(Operation &opInst,
+ModuleTranslation::convertOperation(Operation &op,
                                     llvm::IRBuilderBase &builder) {
-  if (failed(iface.convertOperation(&opInst, builder, *this)))
-    return opInst.emitError("unsupported or non-LLVM operation: ")
-           << opInst.getName();
-
-  return convertDialectAttributes(&opInst);
+  const LLVMTranslationDialectInterface *opIface = iface.getInterfaceFor(&op);
+  if (!opIface)
+    return op.emitError("cannot be converted to LLVM IR: missing "
+                        "`LLVMTranslationDialectInterface` registration for "
+                        "dialect for op: ")
+           << op.getName();
+
+  if (failed(opIface->convertOperation(&op, builder, *this)))
+    return op.emitError("LLVM Translation failed for operation: ")
+           << op.getName();
+
+  return convertDialectAttributes(&op);
 }
 
 /// Convert block to LLVM IR.  Unless `ignoreArguments` is set, emit PHI nodes


        


More information about the Mlir-commits mailing list