[Mlir-commits] [mlir] 7824768 - [mlir][Pass] Add a new `Pass::getArgument` hook

River Riddle llvmlistbot at llvm.org
Fri Apr 10 22:53:31 PDT 2020


Author: River Riddle
Date: 2020-04-10T22:50:14-07:00
New Revision: 7824768b2e784b81ea988b86ae944edf6aeb0828

URL: https://github.com/llvm/llvm-project/commit/7824768b2e784b81ea988b86ae944edf6aeb0828
DIFF: https://github.com/llvm/llvm-project/commit/7824768b2e784b81ea988b86ae944edf6aeb0828.diff

LOG: [mlir][Pass] Add a new `Pass::getArgument` hook

Summary: 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.

Differential Revision: https://reviews.llvm.org/D77907

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h
index 6d6226f83335..9b9dd7533a1e 100644
--- a/mlir/include/mlir/Pass/Pass.h
+++ b/mlir/include/mlir/Pass/Pass.h
@@ -55,7 +55,15 @@ class Pass {
   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 @@ template <typename PassT, typename BaseT> class PassWrapper : public BaseT {
   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 {

diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 68be02e7eb1c..0c11973b9433 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -59,11 +59,14 @@ void Pass::printAsTextualPipeline(raw_ostream &os) {
     });
     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);
 }
 

diff  --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp
index 487bea6afa7b..7cd9590110ad 100644
--- a/mlir/tools/mlir-tblgen/PassGen.cpp
+++ b/mlir/tools/mlir-tblgen/PassGen.cpp
@@ -42,10 +42,10 @@ class {0}Base : public {1} {
   {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) {{


        


More information about the Mlir-commits mailing list