Skip to content

[mlir][docgen] Add option to enable Hugo Docs specific features #68725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

MacDue
Copy link
Member

@MacDue MacDue commented Oct 10, 2023

This is set to off by default but enabled for the MLIR project, which uses Hugo Docs. Downstream projects can choose if they want to set this option or not.

Also fix an incorrectly closed <table> tag.

This is set to off by default but enabled for the MLIR project, which
uses Hugo Docs. Downstream projects can choose if they want to set this
option or not.

Also fix an incorrectly closed `<table>` tag.
@MacDue MacDue marked this pull request as ready for review October 10, 2023 16:56
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 10, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Benjamin Maxwell (MacDue)

Changes

This is set to off by default but enabled for the MLIR project, which uses Hugo Docs. Downstream projects can choose if they want to set this option or not.

Also fix an incorrectly closed &lt;table&gt; tag.


Full diff: https://github.com/llvm/llvm-project/pull/68725.diff

2 Files Affected:

  • (modified) mlir/cmake/modules/AddMLIR.cmake (+2-1)
  • (modified) mlir/tools/mlir-tblgen/OpDocGen.cpp (+6-2)
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 4622d4d05fcbdeb..544abe43688820e 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -188,7 +188,8 @@ endfunction()
 # Generate Documentation
 function(add_mlir_doc doc_filename output_file output_directory command)
   set(LLVM_TARGET_DEFINITIONS ${doc_filename}.td)
-  tablegen(MLIR ${output_file}.md ${command} ${ARGN})
+  # The MLIR docs use Hugo, so we allow Hugo specific features here.
+  tablegen(MLIR ${output_file}.md ${command} -allow-hugo-specific-features ${ARGN})
   set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/${output_directory}${output_file}.md)
   add_custom_command(
           OUTPUT ${GEN_DOC_FILE}
diff --git a/mlir/tools/mlir-tblgen/OpDocGen.cpp b/mlir/tools/mlir-tblgen/OpDocGen.cpp
index 088d34597f315fc..855f02d828418dd 100644
--- a/mlir/tools/mlir-tblgen/OpDocGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDocGen.cpp
@@ -42,6 +42,10 @@ 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));
+llvm::cl::opt<bool> allowHugoSpecificFeatures(
+    "allow-hugo-specific-features",
+    llvm::cl::desc("Allows using features specific to Hugo"),
+    llvm::cl::init(false), llvm::cl::cat(docCat));
 
 using namespace llvm;
 using namespace mlir;
@@ -213,7 +217,7 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
       os << "<td><code>" << it.name << "</code></td><td>" << storageType
          << "</td><td>";
       StringRef description = resolveAttrDescription(it.attr);
-      if (!description.empty()) {
+      if (allowHugoSpecificFeatures && !description.empty()) {
         // Expandable description.
         // This appears as just the summary, but when clicked shows the full
         // description.
@@ -227,7 +231,7 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
       }
       os << "</td></tr>\n";
     }
-    os << "<table>\n";
+    os << "</table>\n";
   }
 
   // Emit each of the operands.

Copy link
Member

@ScottTodd ScottTodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just tested downstream in IREE and this fixes the previously broken rendering (context: #67009 (comment)).

ScottTodd referenced this pull request Oct 10, 2023
…ons (#67009)

This updates the table of op attributes so that clicking the summary
expands to show the complete description.

```
   Attribute | MLIR Type | Description
   <name>      <type>      ▶ <summary>  <-- Click to expand
```

Enum attributes have now also been updated to generate a description
that lists all the cases (with both their MLIR and C++ names). This
makes viewing enums on the MLIR docs much nicer.

**Example**

Default view:

![image](https://github.com/llvm/llvm-project/assets/11597044/922669c7-b838-4230-bcfd-a77cde0f335d)

Expanded:

![image](https://github.com/llvm/llvm-project/assets/11597044/41da086e-a5ce-45dd-9f44-9d10a4d5f2e1)

---

This requires: llvm/mlir-www#158 (adds a very
simple markdown shortcode)
@MacDue MacDue merged commit 2754f88 into llvm:main Oct 11, 2023
@MacDue MacDue deleted the docs_option branch October 11, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants