[PATCH] D77907: [mlir][Pass] Add a new `Pass::getArgument` hook

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 13:59:05 PDT 2020


rriddle created this revision.
rriddle added a reviewer: mehdi_amini.
Herald added subscribers: llvm-commits, frgossen, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar.
Herald added a project: LLVM.

This hook allows for passes to specify the command line argument without the need for registration. More concretely this will allow for generating pass crash reproducers without needing to have the passes registered. This should remove the need for production tools to register passes, leaving that solely to development tools like mlir-opt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77907

Files:
  mlir/include/mlir/Pass/Pass.h
  mlir/lib/Pass/Pass.cpp
  mlir/tools/mlir-tblgen/PassGen.cpp


Index: mlir/tools/mlir-tblgen/PassGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/PassGen.cpp
+++ mlir/tools/mlir-tblgen/PassGen.cpp
@@ -42,10 +42,10 @@
   {0}Base(const {0}Base &) : {1}(PassID::getID<DerivedT>()) {{}
 
   /// Returns the command-line argument attached to this pass.
-  static llvm::StringRef getPassArgument() { return "{2}"; }
+  llvm::StringRef getArgument() const override { return "{2}"; }
 
   /// Returns the derived pass name.
-  llvm::StringRef getName() override { return "{0}"; }
+  llvm::StringRef getName() const override { return "{0}"; }
 
   /// Support isa/dyn_cast functionality for the derived pass class.
   static bool classof(const ::mlir::Pass *pass) {{
Index: mlir/lib/Pass/Pass.cpp
===================================================================
--- mlir/lib/Pass/Pass.cpp
+++ mlir/lib/Pass/Pass.cpp
@@ -59,11 +59,14 @@
     });
     return;
   }
-  // Otherwise, print the pass argument followed by its options.
-  if (const PassInfo *info = lookupPassInfo())
-    os << info->getPassArgument();
+  // Otherwise, print the pass argument followed by its options. If the pass
+  // doesn't have an argument, print the name of the pass to give some indicator
+  // of what pass was run.
+  StringRef argument = getArgument();
+  if (!argument.empty())
+    os << argument;
   else
-    os << getName();
+    os << "unknown<" << getName() << ">";
   passOptions.print(os);
 }
 
Index: mlir/include/mlir/Pass/Pass.h
===================================================================
--- mlir/include/mlir/Pass/Pass.h
+++ mlir/include/mlir/Pass/Pass.h
@@ -55,7 +55,15 @@
   const PassInfo *lookupPassInfo() const { return lookupPassInfo(getPassID()); }
 
   /// Returns the derived pass name.
-  virtual StringRef getName() = 0;
+  virtual StringRef getName() const = 0;
+
+  /// Returns the command line argument used when registering this pass. Return
+  /// an empty string if one does not exist.
+  virtual StringRef getArgument() const {
+    if (const PassInfo *passInfo = lookupPassInfo())
+      return passInfo->getPassArgument();
+    return "";
+  }
 
   /// Returns the name of the operation that this pass operates on, or None if
   /// this is a generic OperationPass.
@@ -332,12 +340,7 @@
   PassWrapper() : BaseT(PassID::getID<PassT>()) {}
 
   /// Returns the derived pass name.
-  StringRef getName() override {
-    StringRef name = llvm::getTypeName<PassT>();
-    if (!name.consume_front("mlir::"))
-      name.consume_front("(anonymous namespace)::");
-    return name;
-  }
+  StringRef getName() const override { return llvm::getTypeName<PassT>(); }
 
   /// A clone method to create a copy of this pass.
   std::unique_ptr<Pass> clonePass() const override {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77907.256658.patch
Type: text/x-patch
Size: 2780 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200410/f481e31d/attachment-0001.bin>


More information about the llvm-commits mailing list