diff --git a/mlir/test/mlir-opt/commandline.mlir b/mlir/test/mlir-opt/commandline.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/mlir-opt/commandline.mlir @@ -0,0 +1,17 @@ +// RUN: mlir-opt --show-dialects | FileCheck %s +// CHECK: Registered Dialects: +// CHECK: affine +// CHECK: fxpmath +// CHECK: gpu +// CHECK: linalg +// CHECK: llvm +// CHECK: loop +// CHECK: nvvm +// CHECK: omp +// CHECK: quant +// CHECK: rocdl +// CHECK: sdbm +// CHECK: spv +// CHECK: std +// CHECK: test +// CHECK: vector 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 @@ -13,6 +13,8 @@ #include "mlir/Analysis/Passes.h" #include "mlir/InitAllDialects.h" #include "mlir/InitAllPasses.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" @@ -118,6 +120,11 @@ createTestMemRefDependenceCheckPass(); } +static cl::opt + showDialects("show-dialects", + cl::desc("Print the list of registered dialects"), + cl::init(false)); + int main(int argc, char **argv) { registerAllDialects(); registerAllPasses(); @@ -131,6 +138,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);