Add an option to iree-opt to show all registered dialect
This can be quite useful to debug dialect registration issues.
We already have this option in upstream mlir-opt.
Closes https://github.com/google/iree/pull/1925
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/1925 from antiagainst:show-dialect 84be728c9c032512f31ed0c4749e98ea15af9f04
PiperOrigin-RevId: 311543176
diff --git a/iree/tools/opt_main.cc b/iree/tools/opt_main.cc
index c90f04c..959e54a 100644
--- a/iree/tools/opt_main.cc
+++ b/iree/tools/opt_main.cc
@@ -65,6 +65,10 @@
llvm::cl::desc("Allow operation with no registered dialects"),
llvm::cl::init(true));
+static llvm::cl::opt<bool> showDialects(
+ "show-dialects", llvm::cl::desc("Print the list of registered dialects"),
+ llvm::cl::init(false));
+
int main(int argc, char **argv) {
mlir::registerMlirDialects();
mlir::registerMlirPasses();
@@ -93,6 +97,15 @@
llvm::cl::ParseCommandLineOptions(argc, argv,
"IREE modular optimizer driver\n");
+ if (showDialects) {
+ llvm::outs() << "Registered Dialects:\n";
+ mlir::MLIRContext context;
+ for (mlir::Dialect *dialect : context.getRegisteredDialects()) {
+ llvm::outs() << dialect->getNamespace() << "\n";
+ }
+ return 0;
+ }
+
// Set up the input file.
std::string errorMessage;
auto file = mlir::openInputFile(inputFilename, &errorMessage);