Add support for building docs

This commit add targets to build op documentation to both BUILD
and CMake configurations. On the CMake side, we additionall
add an iree-doc master target to drive the generation of all
documentation. The generated documentation will all be placed
under <build-dir>/doc/Dialects/ for now.

Closes https://github.com/google/iree/pull/1283

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/1283 from antiagainst:build-doc 2934d4b2dd0d9117e66ac905d64cea43ea71bc7d
PiperOrigin-RevId: 303793736
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db4d78f..b71703b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,6 +37,7 @@
 
 option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON)
 option(IREE_BUILD_TESTS "Builds IREE unit tests." ON)
+option(IREE_BUILD_DOCS "Builds IREE docs." OFF)
 option(IREE_BUILD_SAMPLES "Builds IREE sample projects." ON)
 option(IREE_BUILD_DEBUGGER "Builds the IREE debugger app." OFF)
 option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF)
@@ -66,6 +67,7 @@
 include(iree_cc_library)
 include(iree_cc_test)
 include(iree_tablegen_library)
+include(iree_tablegen_doc)
 include(iree_cc_embed_data)
 include(iree_bytecode_module)
 include(iree_glslang)
@@ -169,6 +171,17 @@
 endif()
 
 #-------------------------------------------------------------------------------
+# IREE top-level targets
+#-------------------------------------------------------------------------------
+
+if(${IREE_BUILD_DOCS})
+  # Add a top-level custom target to drive generating all documentation.
+  # Register it to the default target given that IREE_BUILD_DOCS is explicitly
+  # requested.
+  add_custom_target(iree-doc ALL)
+endif()
+
+#-------------------------------------------------------------------------------
 # IREE top-level libraries
 #-------------------------------------------------------------------------------
 
diff --git a/build_tools/bazel/iree_tablegen_doc.bzl b/build_tools/bazel/iree_tablegen_doc.bzl
new file mode 100644
index 0000000..89591e9
--- /dev/null
+++ b/build_tools/bazel/iree_tablegen_doc.bzl
@@ -0,0 +1,23 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//build_tools/bazel:tblgen.bzl", "gentbl")
+
+def iree_tablegen_doc(*args, **kwargs):
+    """iree_tablegen_doc() generates documentation from a table definition file.
+
+    This is a simple wrapper over gentbl() so we can differentiate between
+    documentation and others. See gentbl() for details regarding arguments.
+    """
+    gentbl(*args, **kwargs)
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake.py b/build_tools/bazel_to_cmake/bazel_to_cmake.py
index 33deda8..9a0f936 100755
--- a/build_tools/bazel_to_cmake/bazel_to_cmake.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake.py
@@ -543,6 +543,27 @@
     "tblgen_block": tblgen_block,
     }
 
+  def iree_tablegen_doc(self,
+                        name,
+                        tblgen,
+                        td_file,
+                        tbl_outs,
+                        td_srcs=None,
+                        td_includes=None,
+                        strip_include_prefix=None):
+    name_block = self._convert_name_block(name)
+    tblgen_block = self._convert_tblgen_block(tblgen)
+    td_file_block = self._convert_td_file_block(td_file)
+    outs_block = self._convert_tbl_outs_block(tbl_outs)
+
+    self.converter.body += """iree_tablegen_doc(
+%(name_block)s%(td_file_block)s%(outs_block)s%(tblgen_block)s)\n\n""" % {
+    "name_block": name_block,
+    "td_file_block": td_file_block,
+    "outs_block": outs_block,
+    "tblgen_block": tblgen_block,
+    }
+
   def iree_lit_test_suite(self, name, srcs, data, **kwargs):
     name_block = self._convert_name_block(name)
     srcs_block = self._convert_srcs_block(srcs)
diff --git a/build_tools/cmake/iree_tablegen_doc.cmake b/build_tools/cmake/iree_tablegen_doc.cmake
new file mode 100644
index 0000000..0f567de
--- /dev/null
+++ b/build_tools/cmake/iree_tablegen_doc.cmake
@@ -0,0 +1,84 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+include(CMakeParseArguments)
+
+# iree_tablegen_doc()
+#
+# Runs iree-tablegen to produce documentation. For TableGen'ing others,
+# please use iree_tablegen_library().
+#
+# One-value parameters:
+# * NAME: base name of the target. The real target name is mangled from this
+#         given name with the package name
+# * TBLGEN: the base project to pass to TableGen
+#
+# Multi-value parameters:
+# * TD_FILE: Input .td files
+# * OUTS: TableGen generator commands and their outputs in the format of
+#         `-gen-<something> <output-file-name>`. Note that the generator
+#         commands should only be for documentation.
+function(iree_tablegen_doc)
+  cmake_parse_arguments(
+    _RULE
+    ""
+    "NAME;TBLGEN"
+    "TD_FILE;OUTS"
+    ${ARGN}
+  )
+
+  if(IREE_BUILD_DOCS)
+    # Prefix the library with the package name, so we get: iree_package_name
+    iree_package_name(_PACKAGE_NAME)
+    set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
+
+    if(${_RULE_TBLGEN} MATCHES "IREE")
+      set(_TBLGEN "IREE")
+    else()
+      set(_TBLGEN "MLIR")
+    endif()
+
+
+    set(_INCLUDE_DIRS ${IREE_COMMON_INCLUDE_DIRS})
+    list(APPEND _INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
+    list(TRANSFORM _INCLUDE_DIRS PREPEND "-I")
+
+    set(_INPUTS ${_RULE_TD_FILE})
+    set(LLVM_TARGET_DEFINITIONS ${_INPUTS})
+
+    set(_OUTPUTS)
+    while(_RULE_OUTS)
+      list(GET _RULE_OUTS 0 _COMMAND)
+      list(REMOVE_AT _RULE_OUTS 0)
+      list(GET _RULE_OUTS 0 _OUTPUT)
+      list(REMOVE_AT _RULE_OUTS 0)
+
+      # TableGen this output with the given command.
+      tablegen(${_TBLGEN} ${_OUTPUT} ${_COMMAND} ${_INCLUDE_DIRS})
+      list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_OUTPUT})
+    endwhile()
+
+    # Put all dialect docs at one place.
+    set(_DOC_DIR ${PROJECT_BINARY_DIR}/doc/Dialects/)
+    # Set a target to drive copy.
+    add_custom_target(${_NAME}_target
+              ${CMAKE_COMMAND} -E make_directory ${_DOC_DIR}
+      COMMAND ${CMAKE_COMMAND} -E copy ${_OUTPUTS} ${_DOC_DIR}
+      DEPENDS ${_OUTPUTS})
+    set_target_properties(${_NAME}_target PROPERTIES FOLDER "Tablegenning")
+
+    # Register this dialect doc to iree-doc.
+    add_dependencies(iree-doc ${_NAME}_target)
+  endif()
+endfunction()
diff --git a/build_tools/cmake/rebuild.sh b/build_tools/cmake/rebuild.sh
index 1dcca8f..dbacc86 100755
--- a/build_tools/cmake/rebuild.sh
+++ b/build_tools/cmake/rebuild.sh
@@ -35,6 +35,12 @@
   mkdir build
 fi
 cd build
-"$CMAKE_BIN" -G Ninja -DCMAKE_BUILD_TYPE=FastBuild -DIREE_BUILD_COMPILER=ON -DIREE_BUILD_TESTS=ON -DIREE_BUILD_SAMPLES=OFF -DIREE_BUILD_DEBUGGER=OFF -DIREE_BUILD_PYTHON_BINDINGS=ON ..
+"$CMAKE_BIN" -G Ninja -DCMAKE_BUILD_TYPE=FastBuild \
+                      -DIREE_BUILD_COMPILER=ON \
+                      -DIREE_BUILD_TESTS=ON \
+                      -DIREE_BUILD_SAMPLES=OFF \
+                      -DIREE_BUILD_DOCS=ON \
+                      -DIREE_BUILD_DEBUGGER=OFF \
+                      -DIREE_BUILD_PYTHON_BINDINGS=ON ..
 "$CMAKE_BIN" --build .
 
diff --git a/iree/compiler/Dialect/Flow/IR/BUILD b/iree/compiler/Dialect/Flow/IR/BUILD
index eace239..b4fd583 100644
--- a/iree/compiler/Dialect/Flow/IR/BUILD
+++ b/iree/compiler/Dialect/Flow/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -103,3 +104,18 @@
         "@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
     ],
 )
+
+iree_tablegen_doc(
+    name = "FlowDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "FlowDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "FlowOps.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
+    ],
+)
diff --git a/iree/compiler/Dialect/Flow/IR/CMakeLists.txt b/iree/compiler/Dialect/Flow/IR/CMakeLists.txt
index 4ba4fd8..6783a8b 100644
--- a/iree/compiler/Dialect/Flow/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/Flow/IR/CMakeLists.txt
@@ -74,3 +74,12 @@
     -gen-op-decls FlowOps.h.inc
     -gen-op-defs FlowOps.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    FlowDialectDocGen
+  TD_FILE
+    "FlowOps.td"
+  OUTS
+    -gen-dialect-doc FlowDialect.md
+)
diff --git a/iree/compiler/Dialect/HAL/IR/BUILD b/iree/compiler/Dialect/HAL/IR/BUILD
index 4b65f8c..99798db 100644
--- a/iree/compiler/Dialect/HAL/IR/BUILD
+++ b/iree/compiler/Dialect/HAL/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -130,3 +131,17 @@
         "@llvm-project//mlir:StdOpsTdFiles",
     ],
 )
+
+iree_tablegen_doc(
+    name = "HALDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "HALDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "HALOps.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:StdOpsTdFiles",
+    ],
+)
diff --git a/iree/compiler/Dialect/HAL/IR/CMakeLists.txt b/iree/compiler/Dialect/HAL/IR/CMakeLists.txt
index 0f5523e..12e559c 100644
--- a/iree/compiler/Dialect/HAL/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/HAL/IR/CMakeLists.txt
@@ -102,3 +102,12 @@
     -gen-op-interface-decls HALOpInterface.h.inc
     -gen-op-interface-defs HALOpInterface.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    HALDialectDocGen
+  TD_FILE
+    "HALOps.td"
+  OUTS
+    -gen-dialect-doc HALDialect.md
+)
diff --git a/iree/compiler/Dialect/IREE/IR/BUILD b/iree/compiler/Dialect/IREE/IR/BUILD
index d292976..cbb2dd5 100644
--- a/iree/compiler/Dialect/IREE/IR/BUILD
+++ b/iree/compiler/Dialect/IREE/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -68,3 +69,17 @@
         "@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
     ],
 )
+
+iree_tablegen_doc(
+    name = "IREEDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "IREEDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "IREEOps.td",
+    td_srcs = [
+        ":td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
+    ],
+)
diff --git a/iree/compiler/Dialect/IREE/IR/CMakeLists.txt b/iree/compiler/Dialect/IREE/IR/CMakeLists.txt
index 15a8b6e..d94b494 100644
--- a/iree/compiler/Dialect/IREE/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/IREE/IR/CMakeLists.txt
@@ -50,3 +50,12 @@
     -gen-op-decls IREEOps.h.inc
     -gen-op-defs IREEOps.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    IREEDialectDocGen
+  TD_FILE
+    "IREEOps.td"
+  OUTS
+    -gen-dialect-doc IREEDialect.md
+)
diff --git a/iree/compiler/Dialect/Modules/Check/IR/BUILD b/iree/compiler/Dialect/Modules/Check/IR/BUILD
index 7b204b7..d2572b0 100644
--- a/iree/compiler/Dialect/Modules/Check/IR/BUILD
+++ b/iree/compiler/Dialect/Modules/Check/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -78,3 +79,18 @@
         "//iree/compiler/Dialect/IREE/IR:td_files",
     ],
 )
+
+iree_tablegen_doc(
+    name = "CheckDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "CheckDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "CheckOps.td",
+    td_srcs = [
+        ":td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "//iree/compiler/Dialect/HAL/IR:td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+    ],
+)
diff --git a/iree/compiler/Dialect/Modules/Check/IR/CMakeLists.txt b/iree/compiler/Dialect/Modules/Check/IR/CMakeLists.txt
index dd8ee10..14f102a 100644
--- a/iree/compiler/Dialect/Modules/Check/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/Modules/Check/IR/CMakeLists.txt
@@ -59,3 +59,12 @@
     -gen-op-decls CheckOps.h.inc
     -gen-op-defs CheckOps.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    CheckDialectDocGen
+  TD_FILE
+    "CheckOps.td"
+  OUTS
+    -gen-dialect-doc CheckDialect.md
+)
diff --git a/iree/compiler/Dialect/Modules/Strings/IR/BUILD b/iree/compiler/Dialect/Modules/Strings/IR/BUILD
index 6477fa5..5f26574 100644
--- a/iree/compiler/Dialect/Modules/Strings/IR/BUILD
+++ b/iree/compiler/Dialect/Modules/Strings/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -88,3 +89,17 @@
         "@llvm-project//mlir:StdOpsTdFiles",
     ],
 )
+
+iree_tablegen_doc(
+    name = "DialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "StringsDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "Ops.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:StdOpsTdFiles",
+    ],
+)
diff --git a/iree/compiler/Dialect/Modules/Strings/IR/CMakeLists.txt b/iree/compiler/Dialect/Modules/Strings/IR/CMakeLists.txt
index 43370bc..7e55191 100644
--- a/iree/compiler/Dialect/Modules/Strings/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/Modules/Strings/IR/CMakeLists.txt
@@ -70,3 +70,12 @@
     -gen-op-decls Ops.h.inc
     -gen-op-defs Ops.cc.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    DialectDocGen
+  TD_FILE
+    "Ops.td"
+  OUTS
+    -gen-dialect-doc StringsDialect.md
+)
diff --git a/iree/compiler/Dialect/Modules/TensorList/IR/BUILD b/iree/compiler/Dialect/Modules/TensorList/IR/BUILD
index 87b1e62..121a685 100644
--- a/iree/compiler/Dialect/Modules/TensorList/IR/BUILD
+++ b/iree/compiler/Dialect/Modules/TensorList/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -88,3 +89,18 @@
         "@llvm-project//mlir:StdOpsTdFiles",
     ],
 )
+
+iree_tablegen_doc(
+    name = "TensorListDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "TensorListDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "TensorListOps.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "//iree/compiler/Dialect/HAL/IR:td_files",
+        "@llvm-project//mlir:StdOpsTdFiles",
+    ],
+)
diff --git a/iree/compiler/Dialect/Modules/TensorList/IR/CMakeLists.txt b/iree/compiler/Dialect/Modules/TensorList/IR/CMakeLists.txt
index ccf453c..c0aa73b 100644
--- a/iree/compiler/Dialect/Modules/TensorList/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/Modules/TensorList/IR/CMakeLists.txt
@@ -71,3 +71,12 @@
     -gen-op-decls TensorListOps.h.inc
     -gen-op-defs TensorListOps.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    TensorListDialectDocGen
+  TD_FILE
+    "TensorListOps.td"
+  OUTS
+    -gen-dialect-doc TensorListDialect.md
+)
diff --git a/iree/compiler/Dialect/Shape/IR/BUILD b/iree/compiler/Dialect/Shape/IR/BUILD
index 1d2e888..e8a38ad 100644
--- a/iree/compiler/Dialect/Shape/IR/BUILD
+++ b/iree/compiler/Dialect/Shape/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -73,3 +74,19 @@
         "@llvm-project//mlir:include/mlir/IR/OpAsmInterface.td",
     ],
 )
+
+iree_tablegen_doc(
+    name = "ShapeDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "ShapeDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "ShapeOps.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
+        "@llvm-project//mlir:include/mlir/IR/OpAsmInterface.td",
+    ],
+)
diff --git a/iree/compiler/Dialect/Shape/IR/CMakeLists.txt b/iree/compiler/Dialect/Shape/IR/CMakeLists.txt
index 8167a34..30b0818 100644
--- a/iree/compiler/Dialect/Shape/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/Shape/IR/CMakeLists.txt
@@ -53,3 +53,12 @@
     -gen-op-decls ShapeOps.h.inc
     -gen-op-defs ShapeOps.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    ShapeDialectDocGen
+  TD_FILE
+    "ShapeOps.td"
+  OUTS
+    -gen-dialect-doc ShapeDialect.md
+)
diff --git a/iree/compiler/Dialect/VM/IR/BUILD b/iree/compiler/Dialect/VM/IR/BUILD
index 68253d0..24b10f3 100644
--- a/iree/compiler/Dialect/VM/IR/BUILD
+++ b/iree/compiler/Dialect/VM/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -130,3 +131,20 @@
         "@llvm-project//mlir:OpBaseTdFiles",
     ],
 )
+
+iree_tablegen_doc(
+    name = "VMDialectDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "VMDialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "VMOps.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:include/mlir/Interfaces/CallInterfaces.td",
+        "@llvm-project//mlir:include/mlir/Interfaces/ControlFlowInterfaces.td",
+        "@llvm-project//mlir:include/mlir/Interfaces/SideEffects.td",
+    ],
+)
diff --git a/iree/compiler/Dialect/VM/IR/CMakeLists.txt b/iree/compiler/Dialect/VM/IR/CMakeLists.txt
index 769f178..57e42c6 100644
--- a/iree/compiler/Dialect/VM/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/VM/IR/CMakeLists.txt
@@ -90,3 +90,12 @@
     -gen-op-interface-decls VMOpInterface.h.inc
     -gen-op-interface-defs VMOpInterface.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    VMDialectDocGen
+  TD_FILE
+    "VMOps.td"
+  OUTS
+    -gen-dialect-doc VMDialect.md
+)
diff --git a/iree/compiler/Dialect/VMLA/IR/BUILD b/iree/compiler/Dialect/VMLA/IR/BUILD
index a4be0d3..ebf00ec 100644
--- a/iree/compiler/Dialect/VMLA/IR/BUILD
+++ b/iree/compiler/Dialect/VMLA/IR/BUILD
@@ -12,6 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+load("//build_tools/bazel:iree_tablegen_doc.bzl", "iree_tablegen_doc")
 load("//build_tools/bazel:tblgen.bzl", "gentbl")
 
 package(
@@ -130,3 +131,19 @@
         "@llvm-project//mlir:OpBaseTdFiles",
     ],
 )
+
+iree_tablegen_doc(
+    name = "VMLADialecDocGen",
+    tbl_outs = [
+        ("-gen-dialect-doc", "VMLADialect.md"),
+    ],
+    tblgen = "@llvm-project//mlir:mlir-tblgen",
+    td_file = "VMLAOps.td",
+    td_srcs = [
+        ":td_files",
+        "//iree/compiler/Dialect/IREE/IR:td_files",
+        "//iree/compiler/Dialect/Shape/IR:td_files",
+        "@llvm-project//mlir:OpBaseTdFiles",
+        "@llvm-project//mlir:StdOpsTdFiles",
+    ],
+)
diff --git a/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt b/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt
index e926c87..0b193bb 100644
--- a/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt
+++ b/iree/compiler/Dialect/VMLA/IR/CMakeLists.txt
@@ -97,3 +97,12 @@
     -gen-op-interface-decls VMLAOpInterface.h.inc
     -gen-op-interface-defs VMLAOpInterface.cpp.inc
 )
+
+iree_tablegen_doc(
+  NAME
+    VMLADialecDocGen
+  TD_FILE
+    "VMLAOps.td"
+  OUTS
+    -gen-dialect-doc VMLADialect.md
+)