Skip to content

Commit 4acbd44

Browse files
committed
[MLIR][Doc] Also print summarys for passes on a newline
This patch is improves upon https://reviews.llvm.org/D152621. There, I pointed out some issues with D152621, which I'll repeat here. > Passes use a different logic for generating the documentation; which I didn't update to be in-line with this change. Fixed by defining and using `mlir::tblgen::emitSummary`. This is now used in `OpDocGen.cpp` and `PassDocGen.cpp`. Note that the passes documentation currently prints the summary behind the pass argument. For example: ``` #### -arm-neon-2d-to-intr: Convert Arm NEON structured ops to intrinsics ``` at https://mlir.llvm.org/docs/Passes/#-promote-buffers-to-stack-promotes-heap-based-allocations-to-automatically-managed-stack-based-allocations. This currently differs from how the summary is printed for Ops. For example: ``` #### amdgpu.lds_barrier (::mlir::amdgpu::LDSBarrierOp) ¶ **Summary:** _Barrier that includes a wait for LDS memory operations._ ``` at https://mlir.llvm.org/docs/Dialects/AMDGPU/#amdgpulds_barrier-mliramdgpuldsbarrierop. The changes in this patch ensure that: 1. The summary is always printed on a new line. 2. The summary is always printed in italic. 3. The summary always starts with a capital letter. I've dropped the `**Summary:**`, which was introduced in D152621, because only italicization should be already clear enough. > `amx.tdpbssd` shows **Summary:** __ meaning that apparently hasSummary does not guarantee a non-empty summary. This is fixed by double-checking `!summary.empty()`, because the following code ```cpp void mlir::tblgen::emitSummary(StringRef summary, raw_ostream &os) { if (!summary.empty()) { char first = std::toupper(summary.front()); llvm::StringRef rest = summary.drop_front(); os << "\n_" << first << rest << "_\n\n"; } else { os << "\n_" << "foo" << "_\n\n"; } } ``` generates the following Markdown: ``` ### `amx.tdpbssd` (::mlir::amx::x86_amx_tdpbssd) _foo_ ``` in `tools/mlir/docs/Dialects/AMX.md`. > Summary fields containing * cancel the italicization, so the * should probably be escaped to solve this. EDIT: Nope. This is because mlir-www runs Hugo 0.80 whereas 0.111 correctly parses _Raw Buffer Floating-point Atomic Add (MI-* only)_ as an italicized string. This will be fixed by llvm/mlir-www#152. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D152648
1 parent a89895a commit 4acbd44

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

mlir/docs/DefiningDialects/Operations.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ let description = [{
165165
Placing the documentation at the beginning is recommended since it helps in
166166
understanding the operation.
167167

168-
> * Place documentation at the beginning of the operation definition
169-
> * The summary should be short and concise. It should be a one-liner without
170-
> trailing punctuation. Put expanded explanation in description.
168+
> * Place documentation at the beginning of the operation definition.
169+
> * The summary should be short and concise. It should be a one-liner
170+
> starting with a capital letter and without trailing punctuation.
171+
> Put expanded explanation in the description.
171172
172173
### Operation arguments
173174

mlir/tools/mlir-tblgen/DocGenUtilities.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class raw_ostream;
2323
namespace mlir {
2424
namespace tblgen {
2525

26+
// Emit the summary. To avoid confusion, the summary is styled differently from
27+
// the description.
28+
void emitSummary(llvm::StringRef summary, llvm::raw_ostream &os);
29+
2630
// Emit the description by aligning the text to the left per line (e.g.
2731
// removing the minimum indentation across the block).
2832
//

mlir/tools/mlir-tblgen/OpDocGen.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ using namespace mlir;
4747
using namespace mlir::tblgen;
4848
using mlir::tblgen::Operator;
4949

50+
void mlir::tblgen::emitSummary(StringRef summary, raw_ostream &os) {
51+
if (!summary.empty()) {
52+
char first = std::toupper(summary.front());
53+
llvm::StringRef rest = summary.drop_front();
54+
os << "\n_" << first << rest << "_\n\n";
55+
}
56+
}
57+
5058
// Emit the description by aligning the text to the left per line (e.g.,
5159
// removing the minimum indentation across the block).
5260
//
@@ -172,7 +180,7 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
172180

173181
// Emit the summary, syntax, and description if present.
174182
if (op.hasSummary())
175-
os << "\n**Summary:** _" << op.getSummary() << "_\n\n";
183+
emitSummary(op.getSummary(), os);
176184
if (op.hasAssemblyFormat())
177185
emitAssemblyFormat(op.getOperationName(), op.getAssemblyFormat().trim(),
178186
os);

mlir/tools/mlir-tblgen/PassDocGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ using namespace mlir::tblgen;
2121

2222
/// Emit the documentation for the given pass.
2323
static void emitDoc(const Pass &pass, raw_ostream &os) {
24-
os << llvm::formatv("### `-{0}`: {1}\n", pass.getArgument(),
25-
pass.getSummary());
24+
os << llvm::formatv("### `-{0}`\n", pass.getArgument());
25+
emitSummary(pass.getSummary(), os);
2626
emitDescription(pass.getDescription(), os);
2727

2828
// Handle the options of the pass.

0 commit comments

Comments
 (0)