diff --git a/mlir/include/mlir/Tools/mlir-translate/Translation.h b/mlir/include/mlir/Tools/mlir-translate/Translation.h --- a/mlir/include/mlir/Tools/mlir-translate/Translation.h +++ b/mlir/include/mlir/Tools/mlir-translate/Translation.h @@ -106,6 +106,9 @@ size_t globalWidth) const override; }; +/// Register command-line options used by the translation registry. +void registerTranslationCLOptions(); + } // namespace mlir #endif // MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp --- a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp +++ b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp @@ -61,6 +61,7 @@ llvm::cl::Required); registerAsmPrinterCLOptions(); registerMLIRContextCLOptions(); + registerTranslationCLOptions(); llvm::cl::ParseCommandLineOptions(argc, argv, toolName); std::string errorMessage; diff --git a/mlir/lib/Tools/mlir-translate/Translation.cpp b/mlir/lib/Tools/mlir-translate/Translation.cpp --- a/mlir/lib/Tools/mlir-translate/Translation.cpp +++ b/mlir/lib/Tools/mlir-translate/Translation.cpp @@ -21,6 +21,21 @@ using namespace mlir; +//===----------------------------------------------------------------------===// +// Translation CommandLine Options +//===----------------------------------------------------------------------===// + +struct TranslationOptions { + llvm::cl::opt noImplicitModule{ + "no-implicit-module", + llvm::cl::desc("Disable the parsing of an implicit top-level module op"), + llvm::cl::init(false)}; +}; + +static llvm::ManagedStatic clOptions; + +void mlir::registerTranslationCLOptions() { *clOptions; } + //===----------------------------------------------------------------------===// // Translation Registry //===----------------------------------------------------------------------===// @@ -103,11 +118,6 @@ const TranslateFromMLIRFunction &function, const std::function &dialectRegistration) { - static llvm::cl::opt noImplicitModule{ - "no-implicit-module", - llvm::cl::desc("Disable the parsing of an implicit top-level module op"), - llvm::cl::init(false)}; - registerTranslation(name, description, [function, dialectRegistration]( llvm::SourceMgr &sourceMgr, raw_ostream &output, @@ -116,7 +126,7 @@ dialectRegistration(registry); context->appendDialectRegistry(registry); OwningOpRef op = parseSourceFileForTool( - sourceMgr, context, !noImplicitModule); + sourceMgr, context, !clOptions->noImplicitModule); if (!op || failed(verify(*op))) return failure(); return function(op.get(), output);