Skip to content

Commit 2a547f0

Browse files
committed
[MLIR] Fix mlir-opt --show-dialects to not require any input (as documented)
1 parent 297af06 commit 2a547f0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "mlir/Pass/Pass.h"
3232
#include "mlir/Pass/PassManager.h"
3333
#include "mlir/Support/FileUtilities.h"
34+
#include "mlir/Support/LogicalResult.h"
3435
#include "mlir/Support/Timing.h"
3536
#include "mlir/Support/ToolUtilities.h"
3637
#include "mlir/Tools/ParseUtilities.h"
@@ -513,15 +514,19 @@ mlir::registerAndParseCLIOptions(int argc, char **argv,
513514
return std::make_pair(inputFilename.getValue(), outputFilename.getValue());
514515
}
515516

517+
static LogicalResult printRegisteredDialects(DialectRegistry &registry) {
518+
llvm::outs() << "Available Dialects: ";
519+
interleave(registry.getDialectNames(), llvm::outs(), ",");
520+
llvm::outs() << "\n";
521+
return success();
522+
}
523+
516524
LogicalResult mlir::MlirOptMain(llvm::raw_ostream &outputStream,
517525
std::unique_ptr<llvm::MemoryBuffer> buffer,
518526
DialectRegistry &registry,
519527
const MlirOptMainConfig &config) {
520-
if (config.shouldShowDialects()) {
521-
llvm::outs() << "Available Dialects: ";
522-
interleave(registry.getDialectNames(), llvm::outs(), ",");
523-
llvm::outs() << "\n";
524-
}
528+
if (config.shouldShowDialects())
529+
return printRegisteredDialects(registry);
525530

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

557562
MlirOptMainConfig config = MlirOptMainConfig::createFromCLOptions();
558563

564+
if (config.shouldShowDialects())
565+
return printRegisteredDialects(registry);
566+
559567
// When reading from stdin and the input is a tty, it is often a user mistake
560568
// and the process "appears to be stuck". Print a message to let the user know
561569
// about it!

0 commit comments

Comments
 (0)