diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h --- a/mlir/include/mlir/Pass/Pass.h +++ b/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()) {} /// Returns the derived pass name. - StringRef getName() override { - StringRef name = llvm::getTypeName(); - if (!name.consume_front("mlir::")) - name.consume_front("(anonymous namespace)::"); - return name; - } + StringRef getName() const override { return llvm::getTypeName(); } /// A clone method to create a copy of this pass. std::unique_ptr clonePass() const override { diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp --- a/mlir/lib/Pass/Pass.cpp +++ b/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); } diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -42,10 +42,10 @@ {0}Base(const {0}Base &) : {1}(PassID::getID()) {{} /// 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) {{