Skip to content

Commit 9bca963

Browse files
Revert "[MLIR] Extend MlirOptMain API to register HW-specific options inside"
This reverts commit d0dd595.
1 parent b41406a commit 9bca963

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,6 @@ class MlirOptMainConfig {
294294
std::string generateReproducerFileFlag = "";
295295
};
296296

297-
/// VPUX-specific method to get value for arch kind from command line
298-
/// and register HW-specific passes and pipelines
299-
using AdditionalRegistrationFn =
300-
std::function<void(llvm::StringRef helpHeader)>;
301-
302297
/// This defines the function type used to setup the pass manager. This can be
303298
/// used to pass in a callback to setup a default pass pipeline to be applied on
304299
/// the loaded IR.
@@ -326,12 +321,18 @@ LogicalResult MlirOptMain(llvm::raw_ostream &outputStream,
326321
/// Implementation for tools like `mlir-opt`.
327322
/// - toolName is used for the header displayed by `--help`.
328323
/// - registry should contain all the dialects that can be parsed in the source.
329-
/// - additionalRegistration will be called before the main command line parsing
330-
/// to perform additional registrations.
331324
LogicalResult MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
332-
DialectRegistry &registry,
333-
const AdditionalRegistrationFn &additionalRegistration
334-
= [](llvm::StringRef){});
325+
DialectRegistry &registry);
326+
327+
/// Implementation for tools like `mlir-opt`.
328+
/// This function can be used with registerAndParseCLIOptions so that
329+
/// CLI options can be accessed before running MlirOptMain.
330+
/// - inputFilename is the name of the input mlir file.
331+
/// - outputFilename is the name of the output file.
332+
/// - registry should contain all the dialects that can be parsed in the source.
333+
LogicalResult MlirOptMain(int argc, char **argv, llvm::StringRef inputFilename,
334+
llvm::StringRef outputFilename,
335+
DialectRegistry &registry);
335336

336337
/// Helper wrapper to return the result of MlirOptMain directly from main.
337338
///

mlir/lib/Tools/mlir-opt/MlirOptMain.cpp

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -630,41 +630,13 @@ LogicalResult mlir::MlirOptMain(llvm::raw_ostream &outputStream,
630630
config.outputSplitMarker());
631631
}
632632

633-
LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
634-
DialectRegistry &registry,
635-
const AdditionalRegistrationFn &additionalRegistration) {
636-
static cl::opt<std::string> inputFilename(
637-
cl::Positional, cl::desc("<input file>"), cl::init("-"));
638-
639-
static cl::opt<std::string> outputFilename("o", cl::desc("Output filename"),
640-
cl::value_desc("filename"),
641-
cl::init("-"));
633+
LogicalResult mlir::MlirOptMain(int argc, char **argv,
634+
llvm::StringRef inputFilename,
635+
llvm::StringRef outputFilename,
636+
DialectRegistry &registry) {
642637

643638
InitLLVM y(argc, argv);
644639

645-
// Register any command line options.
646-
registerAsmPrinterCLOptions();
647-
registerMLIRContextCLOptions();
648-
registerPassManagerCLOptions();
649-
registerDefaultTimingManagerCLOptions();
650-
tracing::DebugCounter::registerCLOptions();
651-
652-
// Build the list of dialects as a header for the --help message.
653-
std::string helpHeader = (toolName + "\nAvailable Dialects: ").str();
654-
{
655-
llvm::raw_string_ostream os(helpHeader);
656-
interleaveComma(registry.getDialectNames(), os,
657-
[&](auto name) { os << name; });
658-
}
659-
660-
// It is not possible to place a call after command line parser
661-
// since not all options are registered at the moment
662-
additionalRegistration(helpHeader);
663-
664-
MlirOptMainConfig::registerCLOptions(registry);
665-
666-
// Parse pass names in main to ensure static initialization completed.
667-
cl::ParseCommandLineOptions(argc, argv, helpHeader);
668640
MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions();
669641

670642
if (config.shouldShowDialects())
@@ -701,3 +673,14 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
701673
output->keep();
702674
return success();
703675
}
676+
677+
LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
678+
DialectRegistry &registry) {
679+
680+
// Register and parse command line options.
681+
std::string inputFilename, outputFilename;
682+
std::tie(inputFilename, outputFilename) =
683+
registerAndParseCLIOptions(argc, argv, toolName, registry);
684+
685+
return MlirOptMain(argc, argv, inputFilename, outputFilename, registry);
686+
}

0 commit comments

Comments
 (0)