[Mlir-commits] [mlir] [mlir][doc] Escape effects, interfaces, and traits (PR #76297)

Rik Huijzer llvmlistbot at llvm.org
Sat Dec 23 10:30:43 PST 2023


https://github.com/rikhuijzer updated https://github.com/llvm/llvm-project/pull/76297

>From 1541f23f2e2b81cd384b687c0c3937bf6972a0e4 Mon Sep 17 00:00:00 2001
From: Rik Huijzer <github at huijzer.xyz>
Date: Sat, 23 Dec 2023 19:25:01 +0100
Subject: [PATCH 1/2] [mlir][doc] Escape effects, interfaces, and traits

Co-authored-by: scott at modular.com
---
 mlir/test/mlir-tblgen/gen-dialect-doc.td |  6 +++---
 mlir/tools/mlir-tblgen/OpDocGen.cpp      | 12 +++++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/mlir/test/mlir-tblgen/gen-dialect-doc.td b/mlir/test/mlir-tblgen/gen-dialect-doc.td
index ca0b6e38edf82c..c9492eb9ac3cef 100644
--- a/mlir/test/mlir-tblgen/gen-dialect-doc.td
+++ b/mlir/test/mlir-tblgen/gen-dialect-doc.td
@@ -81,9 +81,9 @@ def TestTypeDefParams : TypeDef<Test_Dialect, "TestTypeDefParams"> {
 // CHECK: Other group
 // CHECK: test.b
 // CHECK: test.c
-// CHECK: Traits: SingleBlock, SingleBlockImplicitTerminator<YieldOp>
-// CHECK: Interfaces: NoMemoryEffect (MemoryEffectOpInterface)
-// CHECK: Effects: MemoryEffects::Effect{}
+// CHECK: Traits: `SingleBlockImplicitTerminator<YieldOp>`, `SingleBlock`
+// CHECK: Interfaces: `NoMemoryEffect (MemoryEffectOpInterface)`
+// CHECK: Effects: `MemoryEffects::Effect{}`
 
 // CHECK: ## Attribute constraints
 // CHECK: ### attribute summary
diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 877ef1089dcec0..9e7ec5b13a5cfe 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -123,6 +123,12 @@ static void emitAssemblyFormat(StringRef opName, StringRef format,
   os << "```\n\n";
 }
 
+/// Place `text` between backticks so that the Markdown processor renders it as
+/// inline code.
+static std::string backticks(const std::string &text) {
+    return '`' + text + '`';
+}
+
 static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) {
   // TODO: We should link to the trait/documentation of it. That also means we
   // should add descriptions to traits that can be queried.
@@ -155,14 +161,14 @@ static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) {
           os << effect << " on " << rec->getValueAsString("resource");
         });
         os << "}";
-        effects.insert(os.str());
+        effects.insert(backticks(os.str()));
         name.append(llvm::formatv(" ({0})", traitName).str());
       }
-      interfaces.insert(name);
+      interfaces.insert(backticks(name));
       continue;
     }
 
-    traits.insert(name);
+    traits.insert(backticks(name));
   }
   if (!traits.empty()) {
     llvm::interleaveComma(traits, os << "\nTraits: ");

>From bf6e8e321413fd3621b5807b36a79ed4f6951deb Mon Sep 17 00:00:00 2001
From: Rik Huijzer <github at huijzer.xyz>
Date: Sat, 23 Dec 2023 19:30:32 +0100
Subject: [PATCH 2/2] Apply `clang-format`

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

diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 9e7ec5b13a5cfe..7cd2690ea81557 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -126,7 +126,7 @@ static void emitAssemblyFormat(StringRef opName, StringRef format,
 /// Place `text` between backticks so that the Markdown processor renders it as
 /// inline code.
 static std::string backticks(const std::string &text) {
-    return '`' + text + '`';
+  return '`' + text + '`';
 }
 
 static void emitOpTraitsDoc(const Operator &op, raw_ostream &os) {



More information about the Mlir-commits mailing list