This is an archive of the discontinued LLVM Phabricator instance.

[mlir][mlir-translation] patch for standalone-translation command line description missing.
ClosedPublic

Authored by changkaiyan on Sep 26 2022, 9:12 PM.

Details

Summary

When I run standalone-translate executable file, I expect the following command option can be different from its description. However, I can not separately set the description, which means there must be some unexpected relationship of command option and command description in mlir repository. I have found the error in mlir/lib/Tools/mlir-translate/Translation.cpp as shown in Code Snippet 1. To make application programmer make use of the description, there should be some override functions to provide this customized description.

# things now (unexpected)
OVERVIEW: MLIR Translation Tool
USAGE: standalone-translate [options] <input file>

OPTIONS:

Color Options:

  --color                                              - Use colors in output (default=autodetect)

General options:

  Translation to perform
      --myoption                                 - myoption
# expected
OVERVIEW: MLIR Translation Tool
USAGE: standalone-translate [options] <input file>

OPTIONS:

Color Options:

  --color                                              - Use colors in output (default=autodetect)

General options:

  Translation to perform
      --myoption                                 - something different
// Code Snippet 1

TranslationParser::TranslationParser(llvm::cl::Option &opt)
    : llvm::cl::parser<const TranslateFunction *>(opt) {
  for (const auto &kv : getTranslationRegistry())
    addLiteralOption(kv.first(), &kv.second, kv.first()); // argument 0 is option, argument 2 is description. It should be different.
}

Test Plan:
The additional description can be tested by the standalone project.

Diff Detail

Event Timeline

changkaiyan created this revision.Sep 26 2022, 9:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 26 2022, 9:12 PM
changkaiyan requested review of this revision.Sep 26 2022, 9:12 PM

Line ending change only?
Cannot see a real difference in the patch :(

Line ending change only?
Cannot see a real difference in the patch :(

Sorry, I may upload the wrong diff file, I will check the right version and reupload it.

The update diff. Fixed the previous version.

The update diff. Fixed the previous version.

This is not a full diff. To make reviews easier, please always include as much context as possible with your diff!

To get a full diff, use one of the following commands (or just use Arcanist to upload your patch):

git show HEAD -U999999 > mypatch.patch
git diff -U999999 u > mypatch.patch
git diff HEAD~1 -U999999 > mypatch.patch

You can find information about Arcanist at https://llvm.org/docs/Phabricator.html and https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/

Update the diff file. The format is correct in this version.

The update diff. Fixed the previous version.

This is not a full diff. To make reviews easier, please always include as much context as possible with your diff!

To get a full diff, use one of the following commands (or just use Arcanist to upload your patch):

git show HEAD -U999999 > mypatch.patch
git diff -U999999 u > mypatch.patch
git diff HEAD~1 -U999999 > mypatch.patch

You can find information about Arcanist at https://llvm.org/docs/Phabricator.html and https://secure.phabricator.com/book/phabricator/article/arcanist_quick_start/

Thanks for your comment. I have updated the diff file.

Thanks for fixing the diff, it's much clearer what this is about now.

mlir/include/mlir/Tools/mlir-translate/Translation.h
74–78

I would just always require a description.

mlir/lib/Tools/mlir-translate/Translation.cpp
39–44

I think it would be cleaner to restructure getTranslationRegistry instead of adding a secondary map. What about introducing a proper Translation (or better name) struct that contains the TranslateFunction+arg+description?

changkaiyan marked an inline comment as done.Sep 29 2022, 7:14 PM
changkaiyan added inline comments.
mlir/include/mlir/Tools/mlir-translate/Translation.h
74–78

Some legacy code can not use the new signature. One solution is for compatibility, these functions only with parameter name are retained. The second solution is to modify all the related code in mlir repository, add a description to them. I prefer the second one, because this could enhance users' experience.

Example:

/home/changkaiyan/LLVM/mlir/lib/Target/SPIRV/TranslateRegistration.cpp: In function ‘void mlir::registerTestRoundtripDebugSPIRV()’:
/home/changkaiyan/LLVM/mlir/lib/Target/SPIRV/TranslateRegistration.cpp:182:8: error: no matching function for call to ‘mlir::TranslateFromMLIRRegistration::TranslateFromMLIRRegistration(const char [27], mlir::registerTestRoundtripDebugSPIRV()::<lambda(mlir::ModuleOp, llvm::raw_ostream&)>, mlir::registerTestRoundtripDebugSPIRV()::<lambda(mlir::DialectRegistry&)>)’
       });
        ^

Related Target: LLVMIR, SPIRV, Cpp.

changkaiyan marked an inline comment as done.

Solve the related problem with this patch.

changkaiyan marked an inline comment as done.Sep 29 2022, 8:14 PM

Any problem to this version? I think this is a better patch and I am waiting for the comment before commit this.

rriddle accepted this revision.Oct 3 2022, 12:08 AM

LG, thanks!

mlir/lib/Tools/mlir-translate/Translation.cpp
27–30

Can you wrap this in an anonymous namespace?

48–50

Can we support something like:

This revision is now accepted and ready to land.Oct 3 2022, 12:08 AM