[Mlir-commits] [mlir] [mlir][doc] Trim summary text during DocGen (PR #68477)

Rik Huijzer llvmlistbot at llvm.org
Sat Oct 7 03:48:37 PDT 2023


https://github.com/rikhuijzer created https://github.com/llvm/llvm-project/pull/68477

When defining a multi-line string in tblgen, the output in the Markdown file currently contains too much whitespace and newlines for Hugo's Markdown parser. For example, for `arith.addui_extended` the tblgen
```tblgen
let summary = [{
  extended unsigned integer addition operation returning sum and overflow bit
}];
```
is currently converted to
```markdown
_
    extended unsigned integer addition operation returning sum and overflow bit
  _
```
which causes the text to not be italicized (as can be seen at https://mlir.llvm.org/docs/Dialects/ArithOps/#arithaddui_extended-arithadduiextendedop). After this PR, the output becomes
```
_Extended unsigned integer addition operation returning sum and overflow bit_
```

>From bb573b616033e78e57cb78102b5e7cd4f2bcea7e Mon Sep 17 00:00:00 2001
From: Rik Huijzer <github at huijzer.xyz>
Date: Sat, 7 Oct 2023 12:26:29 +0200
Subject: [PATCH 1/2] [mlir][doc] Trim summary text during DocGen

---
 mlir/tools/mlir-tblgen/OpDocGen.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 088d34597f315fc..b267b4ae06770be 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -50,6 +50,7 @@ using mlir::tblgen::Operator;
 
 void mlir::tblgen::emitSummary(StringRef summary, raw_ostream &os) {
   if (!summary.empty()) {
+    summary = summary.trim();
     char first = std::toupper(summary.front());
     llvm::StringRef rest = summary.drop_front();
     os << "\n_" << first << rest << "_\n\n";

>From 9a508aa1f8961c6cd015460dbc4b54a06292c54b Mon Sep 17 00:00:00 2001
From: Rik Huijzer <github at huijzer.xyz>
Date: Sat, 7 Oct 2023 12:41:23 +0200
Subject: [PATCH 2/2] Pass trimmed text to rest of function

---
 mlir/tools/mlir-tblgen/OpDocGen.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index b267b4ae06770be..498aa40435fb115 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -50,9 +50,9 @@ using mlir::tblgen::Operator;
 
 void mlir::tblgen::emitSummary(StringRef summary, raw_ostream &os) {
   if (!summary.empty()) {
-    summary = summary.trim();
-    char first = std::toupper(summary.front());
-    llvm::StringRef rest = summary.drop_front();
+    llvm::StringRef trimmed = summary.trim();
+    char first = std::toupper(trimmed.front());
+    llvm::StringRef rest = trimmed.drop_front();
     os << "\n_" << first << rest << "_\n\n";
   }
 }



More information about the Mlir-commits mailing list