diff --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp --- a/mlir/tools/mlir-opt/mlir-opt.cpp +++ b/mlir/tools/mlir-opt/mlir-opt.cpp @@ -11,6 +11,8 @@ //===----------------------------------------------------------------------===// #include "mlir/Analysis/Passes.h" +#include "mlir/IR/Dialect.h" +#include "mlir/IR/MLIRContext.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" #include "mlir/Support/FileUtilities.h" @@ -47,6 +49,11 @@ cl::desc("Run the verifier after each transformation pass"), cl::init(true)); +static cl::opt + showDialects("show-dialects", + cl::desc("Print the list of registered dialects"), + cl::init(false)); + int main(int argc, char **argv) { InitLLVM y(argc, argv); @@ -57,6 +64,15 @@ // Parse pass names in main to ensure static initialization completed. cl::ParseCommandLineOptions(argc, argv, "MLIR modular optimizer driver\n"); + MLIRContext context; + if(showDialects) { + llvm::outs() << "Registered Dialects:\n"; + for(Dialect *dialect : context.getRegisteredDialects()) { + llvm::outs() << dialect->getNamespace() << "\n"; + } + return 0; + } + // Set up the input file. std::string errorMessage; auto file = openInputFile(inputFilename, &errorMessage);