[Mlir-commits] [mlir] 40e7741 - [mlir-opt] Add '-p' as an alias for '-pass-pipeline'

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 8 12:19:24 PST 2022


Author: rkayaith
Date: 2022-11-08T15:17:27-05:00
New Revision: 40e7741d2db089b9e43b3537163a8675ff74de70

URL: https://github.com/llvm/llvm-project/commit/40e7741d2db089b9e43b3537163a8675ff74de70
DIFF: https://github.com/llvm/llvm-project/commit/40e7741d2db089b9e43b3537163a8675ff74de70.diff

LOG: [mlir-opt] Add '-p' as an alias for '-pass-pipeline'

The pipeline strings have been getting more verbose over time, adding an
alias for the option should help improve the ergonomics a bit.

Reviewed By: rriddle

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

Added: 
    

Modified: 
    mlir/include/mlir/Pass/PassRegistry.h
    mlir/lib/Pass/PassRegistry.cpp
    mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
    mlir/test/mlir-opt/commandline.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h
index 97692262acc8e..b0731f100c804 100644
--- a/mlir/include/mlir/Pass/PassRegistry.h
+++ b/mlir/include/mlir/Pass/PassRegistry.h
@@ -236,7 +236,9 @@ struct PassPipelineCLParserImpl;
 class PassPipelineCLParser {
 public:
   /// Construct a pass pipeline parser with the given command line description.
+  /// Optionally registers an alias for the `pass-pipeline` option.
   PassPipelineCLParser(StringRef arg, StringRef description);
+  PassPipelineCLParser(StringRef arg, StringRef description, StringRef alias);
   ~PassPipelineCLParser();
 
   /// Returns true if this parser contains any valid options to add.
@@ -257,6 +259,7 @@ class PassPipelineCLParser {
   std::unique_ptr<detail::PassPipelineCLParserImpl> impl;
 
   llvm::cl::opt<std::string> passPipeline;
+  Optional<llvm::cl::alias> passPipelineAlias;
 };
 
 /// This class implements a command-line parser specifically for MLIR pass

diff  --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp
index 0ddb2e99ecfce..cc9eab3005a5f 100644
--- a/mlir/lib/Pass/PassRegistry.cpp
+++ b/mlir/lib/Pass/PassRegistry.cpp
@@ -764,7 +764,7 @@ namespace {
 
 /// The name for the command line option used for parsing the textual pass
 /// pipeline.
-static constexpr StringLiteral passPipelineArg = "pass-pipeline";
+#define PASS_PIPELINE_ARG "pass-pipeline"
 
 /// Adds command line option for each registered pass or pass pipeline, as well
 /// as textual pass pipelines.
@@ -896,8 +896,17 @@ PassPipelineCLParser::PassPipelineCLParser(StringRef arg, StringRef description)
     : impl(std::make_unique<detail::PassPipelineCLParserImpl>(
           arg, description, /*passNamesOnly=*/false)),
       passPipeline(
-          StringRef(passPipelineArg),
+          PASS_PIPELINE_ARG,
           llvm::cl::desc("Textual description of the pass pipeline to run")) {}
+
+PassPipelineCLParser::PassPipelineCLParser(StringRef arg, StringRef description,
+                                           StringRef alias)
+    : PassPipelineCLParser(arg, description) {
+  passPipelineAlias.emplace(alias,
+                            llvm::cl::desc("Alias for --" PASS_PIPELINE_ARG),
+                            llvm::cl::aliasopt(passPipeline));
+}
+
 PassPipelineCLParser::~PassPipelineCLParser() = default;
 
 /// Returns true if this parser contains any valid options to add.
@@ -919,7 +928,7 @@ LogicalResult PassPipelineCLParser::addToPipeline(
   if (passPipeline.getNumOccurrences()) {
     if (impl->passList.getNumOccurrences())
       return errorHandler(
-          "'-" + passPipelineArg +
+          "'-" PASS_PIPELINE_ARG
           "' option can't be used with individual pass options");
     std::string errMsg;
     llvm::raw_string_ostream os(errMsg);

diff  --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 7215e5ffa3980..d75bff3ce33b5 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -269,7 +269,7 @@ LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,
   registerPassManagerCLOptions();
   registerDefaultTimingManagerCLOptions();
   DebugCounter::registerCLOptions();
-  PassPipelineCLParser passPipeline("", "Compiler passes to run");
+  PassPipelineCLParser passPipeline("", "Compiler passes to run", "p");
 
   // Build the list of dialects as a header for the --help message.
   std::string helpHeader = (toolName + "\nAvailable Dialects: ").str();

diff  --git a/mlir/test/mlir-opt/commandline.mlir b/mlir/test/mlir-opt/commandline.mlir
index 1badf905d28de..bdcdf9de29ff8 100644
--- a/mlir/test/mlir-opt/commandline.mlir
+++ b/mlir/test/mlir-opt/commandline.mlir
@@ -40,3 +40,6 @@
 // CHECK-NEXT: transform
 // CHECK-NEXT: vector
 // CHECK-NEXT: x86vector
+
+// RUN: mlir-opt --help-hidden | FileCheck %s -check-prefix=CHECK-HELP
+// CHECK-HELP: -p - Alias for --pass-pipeline


        


More information about the Mlir-commits mailing list