[Mlir-commits] [mlir] 0118a3f - [mlir][docgen] Enable custom prefix strip for op name.

Jacques Pienaar llvmlistbot at llvm.org
Mon Jun 12 20:59:23 PDT 2023


Author: Jacques Pienaar
Date: 2023-06-12T20:58:21-07:00
New Revision: 0118a3f6c3c9bde9042f21b20a7a7131b942761c

URL: https://github.com/llvm/llvm-project/commit/0118a3f6c3c9bde9042f21b20a7a7131b942761c
DIFF: https://github.com/llvm/llvm-project/commit/0118a3f6c3c9bde9042f21b20a7a7131b942761c.diff

LOG: [mlir][docgen] Enable custom prefix strip for op name.

The fully qualified name gets long in the TOC (especially on mobile),
enable specifying a prefix to be stripped.

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

Added: 
    

Modified: 
    mlir/tools/mlir-tblgen/OpDocGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 61def4435e00e..8264b0afe684d 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -21,6 +21,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Regex.h"
@@ -30,11 +31,20 @@
 #include "llvm/TableGen/TableGenBackend.h"
 
 #include <set>
+#include <string>
+
+//===----------------------------------------------------------------------===//
+// Commandline Options
+//===----------------------------------------------------------------------===//
+static llvm::cl::OptionCategory docCat("Options for -gen-(attrdef|typedef|op|dialect)-doc");
+llvm::cl::opt<std::string> stripPrefix(
+    "strip-prefix",
+    llvm::cl::desc("Strip prefix of the fully qualified names"),
+    llvm::cl::init("::mlir::"), llvm::cl::cat(docCat));
 
 using namespace llvm;
 using namespace mlir;
 using namespace mlir::tblgen;
-
 using mlir::tblgen::Operator;
 
 // Emit the description by aligning the text to the left per line (e.g.,
@@ -155,8 +165,10 @@ static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) {
 }
 
 static void emitOpDoc(const Operator &op, raw_ostream &os) {
-  os << llvm::formatv("### `{0}` ({1})\n", op.getOperationName(),
-                      op.getQualCppClassName());
+  std::string classNameStr = op.getQualCppClassName();
+  StringRef className = classNameStr;
+  (void)className.consume_front(stripPrefix);
+  os << llvm::formatv("### `{0}` ({1})\n", op.getOperationName(), className);
 
   // Emit the summary, syntax, and description if present.
   if (op.hasSummary())


        


More information about the Mlir-commits mailing list