Skip to content

Commit

Permalink
[MLIR] Fix mlir-opt --show-dialects to not require any input (as do…
Browse files Browse the repository at this point in the history
…cumented)
  • Loading branch information
joker-eph committed Mar 15, 2024
1 parent 297af06 commit 2a547f0
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Support/Timing.h"
#include "mlir/Support/ToolUtilities.h"
#include "mlir/Tools/ParseUtilities.h"
Expand Down Expand Up @@ -513,15 +514,19 @@ mlir::registerAndParseCLIOptions(int argc, char **argv,
return std::make_pair(inputFilename.getValue(), outputFilename.getValue());
}

static LogicalResult printRegisteredDialects(DialectRegistry &registry) {
llvm::outs() << "Available Dialects: ";
interleave(registry.getDialectNames(), llvm::outs(), ",");
llvm::outs() << "\n";
return success();
}

LogicalResult mlir::MlirOptMain(llvm::raw_ostream &outputStream,
std::unique_ptr<llvm::MemoryBuffer> buffer,
DialectRegistry &registry,
const MlirOptMainConfig &config) {
if (config.shouldShowDialects()) {
llvm::outs() << "Available Dialects: ";
interleave(registry.getDialectNames(), llvm::outs(), ",");
llvm::outs() << "\n";
}
if (config.shouldShowDialects())
return printRegisteredDialects(registry);

// The split-input-file mode is a very specific mode that slices the file
// up into small pieces and checks each independently.
Expand Down Expand Up @@ -556,6 +561,9 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv,

MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions();

if (config.shouldShowDialects())
return printRegisteredDialects(registry);

// When reading from stdin and the input is a tty, it is often a user mistake
// and the process "appears to be stuck". Print a message to let the user know
// about it!
Expand Down

0 comments on commit 2a547f0

Please sign in to comment.