[Mlir-commits] [mlir] 287ade4 - [mlir][doc] Avoid duplication with constraints and defs

Jacques Pienaar llvmlistbot at llvm.org
Thu Jun 16 19:43:03 PDT 2022


Author: Jacques Pienaar
Date: 2022-06-16T19:42:56-07:00
New Revision: 287ade415eaf88bd13345e6106004bd7b57986fb

URL: https://github.com/llvm/llvm-project/commit/287ade415eaf88bd13345e6106004bd7b57986fb
DIFF: https://github.com/llvm/llvm-project/commit/287ade415eaf88bd13345e6106004bd7b57986fb.diff

LOG: [mlir][doc] Avoid duplication with constraints and defs

Where a constraint also has a def, emit the def only to avoid duplicate
output (and def has more complete info). Also move attributes and types
to the end rather than some on top and some at end.

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

Added: 
    

Modified: 
    mlir/test/mlir-tblgen/gen-dialect-doc.td
    mlir/tools/mlir-tblgen/OpDocGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-tblgen/gen-dialect-doc.td b/mlir/test/mlir-tblgen/gen-dialect-doc.td
index 02640f531d4e0..1ca80960fea39 100644
--- a/mlir/test/mlir-tblgen/gen-dialect-doc.td
+++ b/mlir/test/mlir-tblgen/gen-dialect-doc.td
@@ -29,6 +29,11 @@ def TestType : DialectType<Test_Dialect, CPred<"true">> {
 // CHECK: TOC added by tool.
 // CHECK: [TOC]
 
+// CHECK-NOT: [TOC]
+// CHECK: Traits: SingleBlockImplicitTerminator<YieldOp>
+// CHECK: Interfaces: NoSideEffect (MemoryEffectOpInterface)
+// CHECK: Effects: MemoryEffects::Effect{}
+
 // CHECK: ## Attribute constraint definition
 // CHECK: ### attribute summary
 // CHECK: attribute description
@@ -37,10 +42,6 @@ def TestType : DialectType<Test_Dialect, CPred<"true">> {
 // CHECK: ### type summary
 // CHECK: type description
 
-// CHECK-NOT: [TOC]
-// CHECK: Traits: SingleBlockImplicitTerminator<YieldOp>
-// CHECK: Interfaces: NoSideEffect (MemoryEffectOpInterface)
-// CHECK: Effects: MemoryEffects::Effect{}
 
 def Toc_Dialect : Dialect {
   let name = "test_toc";

diff  --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 8d66448da0e9b..13bd4a8bad2f1 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -316,6 +316,12 @@ static void emitDialectDoc(const Dialect &dialect,
   if (!r.match(dialect.getDescription()))
     os << "[TOC]\n\n";
 
+  if (!ops.empty()) {
+    os << "## Operation definition\n\n";
+    for (const Operator &op : ops)
+      emitOpDoc(op, os);
+  }
+
   if (!attributes.empty()) {
     os << "## Attribute constraint definition\n\n";
     for (const Attribute &attr : attributes)
@@ -335,12 +341,6 @@ static void emitDialectDoc(const Dialect &dialect,
       emitTypeDoc(type, os);
   }
 
-  if (!ops.empty()) {
-    os << "## Operation definition\n\n";
-    for (const Operator &op : ops)
-      emitOpDoc(op, os);
-  }
-
   if (!typeDefs.empty()) {
     os << "## Type definition\n\n";
     for (const TypeDef &def : typeDefs)
@@ -367,35 +367,42 @@ static bool emitDialectDoc(const RecordKeeper &recordKeeper, raw_ostream &os) {
   llvm::StringMap<std::vector<Operator>> dialectOps;
   llvm::StringMap<std::vector<Type>> dialectTypes;
   llvm::StringMap<std::vector<TypeDef>> dialectTypeDefs;
+  llvm::SmallDenseSet<Record *> seen;
+  for (Record *attrDef : attrDefDefs) {
+    AttrDef attr(attrDef);
+    dialectAttrDefs[attr.getDialect().getName()].push_back(attr);
+    dialectsWithDocs.insert(attr.getDialect());
+    seen.insert(attrDef);
+  }
   for (Record *attrDef : attrDefs) {
+    if (seen.count(attrDef))
+      continue;
     Attribute attr(attrDef);
     if (const Dialect &dialect = attr.getDialect()) {
       dialectAttrs[dialect.getName()].push_back(attr);
       dialectsWithDocs.insert(dialect);
     }
   }
-  for (Record *attrDef : attrDefDefs) {
-    AttrDef attr(attrDef);
-    dialectAttrDefs[attr.getDialect().getName()].push_back(attr);
-    dialectsWithDocs.insert(attr.getDialect());
-  }
   for (Record *opDef : opDefs) {
     Operator op(opDef);
     dialectOps[op.getDialect().getName()].push_back(op);
     dialectsWithDocs.insert(op.getDialect());
   }
+  for (Record *typeDef : typeDefDefs) {
+    TypeDef type(typeDef);
+    dialectTypeDefs[type.getDialect().getName()].push_back(type);
+    dialectsWithDocs.insert(type.getDialect());
+    seen.insert(typeDef);
+  }
   for (Record *typeDef : typeDefs) {
+    if (seen.count(typeDef))
+      continue;
     Type type(typeDef);
     if (const Dialect &dialect = type.getDialect()) {
       dialectTypes[dialect.getName()].push_back(type);
       dialectsWithDocs.insert(dialect);
     }
   }
-  for (Record *typeDef : typeDefDefs) {
-    TypeDef type(typeDef);
-    dialectTypeDefs[type.getDialect().getName()].push_back(type);
-    dialectsWithDocs.insert(type.getDialect());
-  }
 
   Optional<Dialect> dialect =
       findDialectToGenerate(dialectsWithDocs.getArrayRef());


        


More information about the Mlir-commits mailing list