This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by mehdi_amini on Feb 15 2021, 12:36 PM.

Details

Summary

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.

Diff Detail

Event Timeline

mehdi_amini created this revision.Feb 15 2021, 12:36 PM
mehdi_amini requested review of this revision.Feb 15 2021, 12:36 PM
ftynse accepted this revision.Feb 15 2021, 1:34 PM

Thanks!

I haven't gotten to some of the cleanups yet. Do you mind adding a test for these case?

This revision is now accepted and ready to land.Feb 15 2021, 1:34 PM

Thanks!

I haven't gotten to some of the cleanups yet. Do you mind adding a test for these case?

Any suggestion how? mlir-translate --mlir-to-llvmir does not register any other dialect than the one that can be exported, so it can't parse the standard dialect for example. Locally I tested it by adding the standard dialect to the mlir-to-llvmir translation, but I don't think this is what we want here.

Test dialect doesn't have LLVM translation interface, and we can register it under #ifdef MLIR_INCLUDE_TESTS in mlir-translate.cpp similarly to what we do in mlir-opt.cpp. Failing to convert an operation sounds more intrusive. We could consider conditionally registering a translation for the test dialect based on some command-line flag (forwarded to a proper function), but I'm not sure it is worth it.

Actually we can't do that in mlir-translate.cpp like we did in mlir-opt.cpp because there is no dialect registry passed through this interface. We'd have to do it in ConvertToLLVMIR.cpp but I'm not sure it is desirable there, let me know if you have another idea I'll address this post-commit.