[PATCH] D74865: [MLIR] add show-dialects option for mlir-opt

Stephen Neuendorffer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 27 10:39:37 PST 2020


stephenneuendorffer updated this revision to Diff 247027.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74865/new/

https://reviews.llvm.org/D74865

Files:
  mlir/test/mlir-opt/commandline.mlir
  mlir/tools/mlir-opt/mlir-opt.cpp


Index: mlir/tools/mlir-opt/mlir-opt.cpp
===================================================================
--- mlir/tools/mlir-opt/mlir-opt.cpp
+++ 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<bool>
+    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);
Index: mlir/test/mlir-opt/commandline.mlir
===================================================================
--- /dev/null
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74865.247027.patch
Type: text/x-patch
Size: 1835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200227/23250c20/attachment.bin>


More information about the llvm-commits mailing list