Initial version of Python API Docs. (#7183)
diff --git a/docs/api_docs/python/.gitignore b/docs/api_docs/python/.gitignore
new file mode 100644
index 0000000..69fa449
--- /dev/null
+++ b/docs/api_docs/python/.gitignore
@@ -0,0 +1 @@
+_build/
diff --git a/docs/api_docs/python/Makefile b/docs/api_docs/python/Makefile
new file mode 100644
index 0000000..d4bb2cb
--- /dev/null
+++ b/docs/api_docs/python/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS ?=
+SPHINXBUILD ?= sphinx-build
+SOURCEDIR = .
+BUILDDIR = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/docs/api_docs/python/README.md b/docs/api_docs/python/README.md
new file mode 100644
index 0000000..1dd0567
--- /dev/null
+++ b/docs/api_docs/python/README.md
@@ -0,0 +1,28 @@
+# Python API Docs
+
+Documentation for the Python API is built with Sphinx under this directory.
+When new versions are released, the documentation is generated and published
+to the website.
+
+## Building Docs
+
+### Install IREE binaries
+
+Either install python packages or, from the build directory:
+
+```shell
+export PYTHONPATH=$PWD/bindings/python:$PWD/compiler-api/python_package
+```
+
+### Install dependencies
+
+```shell
+python -m pip install -r requirements.txt
+```
+
+
+### Build docs
+
+```shell
+sphinx-build -b html . _build
+```
diff --git a/docs/api_docs/python/compiler/api.rst b/docs/api_docs/python/compiler/api.rst
new file mode 100644
index 0000000..be961a1
--- /dev/null
+++ b/docs/api_docs/python/compiler/api.rst
@@ -0,0 +1,12 @@
+In-Process Compiler API
+=======================
+
+IREE provides access to its MLIR-based compiler via a dedicated set of APIs
+presented here.
+
+.. automodule:: iree.compiler.api.driver
+ :imported-members:
+ :members: build_iree_vm_pass_pipeline, translate_module_to_vm_bytecode
+
+.. autoclass:: iree.compiler.api.driver.CompilerOptions
+ :members:
diff --git a/docs/api_docs/python/compiler/index.rst b/docs/api_docs/python/compiler/index.rst
new file mode 100644
index 0000000..e96052b
--- /dev/null
+++ b/docs/api_docs/python/compiler/index.rst
@@ -0,0 +1,13 @@
+Compiler API
+============
+
+.. toctree::
+ :maxdepth: 2
+ :caption: Compiler API
+
+ api.rst
+ tools.rst
+ iree_dialect.rst
+ iree_pydm_dialect.rst
+ mlir_dialects.rst
+ mlir.rst
diff --git a/docs/api_docs/python/compiler/iree_dialect.rst b/docs/api_docs/python/compiler/iree_dialect.rst
new file mode 100644
index 0000000..ae2329c
--- /dev/null
+++ b/docs/api_docs/python/compiler/iree_dialect.rst
@@ -0,0 +1,10 @@
+IREE Dialect
+============
+
+This dialect contains frontend-oriented ops and types which are intended to be
+used as input to IREE's compiler (in addition to various MLIR core dialects).
+
+.. automodule:: iree.compiler.dialects.iree
+ :imported-members:
+ :members:
+ :undoc-members:
diff --git a/docs/api_docs/python/compiler/iree_pydm_dialect.rst b/docs/api_docs/python/compiler/iree_pydm_dialect.rst
new file mode 100644
index 0000000..726f383
--- /dev/null
+++ b/docs/api_docs/python/compiler/iree_pydm_dialect.rst
@@ -0,0 +1,21 @@
+IREE Python DataModel Dialect
+=============================
+
+This dialect defines a data model for representing a Python program, suitable
+for compilation to IREE and for the construction of Python-based DSLs.
+
+Importer
+--------
+
+.. automodule:: iree.compiler.dialects.iree_pydm.importer
+ :imported-members:
+ :members:
+ :undoc-members:
+
+Operations and Types
+--------------------
+
+.. automodule:: iree.compiler.dialects.iree_pydm
+ :imported-members:
+ :members:
+ :undoc-members:
diff --git a/docs/api_docs/python/compiler/mlir.rst b/docs/api_docs/python/compiler/mlir.rst
new file mode 100644
index 0000000..a904aae
--- /dev/null
+++ b/docs/api_docs/python/compiler/mlir.rst
@@ -0,0 +1,19 @@
+Embedded MLIR API
+=================
+
+`iree.compiler.ir` module
+-------------------------
+
+.. automodule:: iree.compiler.ir
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`iree.compiler.passmanager` module
+----------------------------------
+
+.. automodule:: iree.compiler.passmanager
+ :imported-members:
+ :members:
+ :undoc-members:
diff --git a/docs/api_docs/python/compiler/mlir_dialects.rst b/docs/api_docs/python/compiler/mlir_dialects.rst
new file mode 100644
index 0000000..4cf44be
--- /dev/null
+++ b/docs/api_docs/python/compiler/mlir_dialects.rst
@@ -0,0 +1,81 @@
+MLIR Core Dialects
+==================
+
+`builtin` dialect
+-----------------
+
+.. automodule:: iree.compiler.dialects.builtin
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`linalg` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.linalg
+ :imported-members:
+ :members:
+ :undoc-members:
+
+`math` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.math
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`memref` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.memref
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`shape` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.shape
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`std` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.std
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`tensor` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.tensor
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`tosa` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.tosa
+ :imported-members:
+ :members:
+ :undoc-members:
+
+
+`vector` dialect
+----------------
+
+.. automodule:: iree.compiler.dialects.vector
+ :imported-members:
+ :members:
+ :undoc-members:
diff --git a/docs/api_docs/python/compiler/tools.rst b/docs/api_docs/python/compiler/tools.rst
new file mode 100644
index 0000000..7cc8911
--- /dev/null
+++ b/docs/api_docs/python/compiler/tools.rst
@@ -0,0 +1,71 @@
+Invoking Command Line Tools
+===========================
+
+As with many compilers, IREE's compiler consists of many command line tools,
+some of which are designed for compiler devs and are only accessible via source
+builds. User level tools are distributed via the Python packages and are also
+accessible via dedicated Python APIs, documented here.
+
+Core Compiler (`ireec`)
+-----------------------
+
+.. automodule:: iree.compiler.tools
+ :members: compile_file, compile_str
+ :imported-members:
+ :undoc-members:
+
+.. autoclass:: iree.compiler.tools.CompilerOptions
+.. autoenum:: iree.compiler.tools.InputType
+.. autoenum:: iree.compiler.tools.OutputFormat
+
+
+Debugging
+---------
+
+.. automodule:: iree.compiler.tools.debugging
+ :members:
+ :imported-members:
+ :undoc-members:
+
+
+TFLite Importer (`iree-import-tflite`)
+--------------------------------------
+
+Using the API below to access `iree-import-tflite` presumes that the tool itself
+is installed via the appropriate PIP package.
+
+.. automodule:: iree.compiler.tools.tflite
+ :members: compile_file, compile_str
+ :imported-members:
+ :undoc-members:
+
+.. autoclass:: iree.compiler.tools.tflite.ImportOptions
+
+
+TensorFlow Importer (`iree-import-tf`)
+--------------------------------------
+
+Using the API below to access `iree-import-tf` presumes that the tool itself
+is installed via the appropriate PIP package.
+
+.. automodule:: iree.compiler.tools.tf
+ :members: compile_saved_model, compile_module
+
+.. autoclass:: iree.compiler.tools.tf.ImportOptions
+.. autoenum:: iree.compiler.tools.tf.ImportType
+
+
+XLA Importer (`iree-import-xla`)
+--------------------------------
+
+Using the API below to access `iree-import-xla` presumes that the tool itself
+is installed via the appropriate PIP package. Note that IREE's core compiler
+directly supports `MHLO` compilation (the imported form of XLA protobufs)
+via the `input_type` option. This tool is primarily for importing XLA protos
+and its text format.
+
+.. automodule:: iree.compiler.tools.xla
+ :members: compile_file, compile_str
+
+.. autoclass:: iree.compiler.tools.xla.ImportOptions
+.. autoenum:: iree.compiler.tools.xla.ImportFormat
diff --git a/docs/api_docs/python/conf.py b/docs/api_docs/python/conf.py
new file mode 100644
index 0000000..da752fc
--- /dev/null
+++ b/docs/api_docs/python/conf.py
@@ -0,0 +1,76 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+# -- Project information -----------------------------------------------------
+
+project = 'IREE Python API'
+copyright = '2021, IREE Authors'
+author = 'IREE Authors'
+
+# The full version, including alpha/beta/rc tags
+release = 'snapshot'
+
+# -- General configuration ---------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
+# ones.
+extensions = [
+ 'myst_parser',
+ 'sphinx.ext.autodoc',
+ 'sphinx.ext.intersphinx',
+ 'sphinx.ext.napoleon',
+ 'enum_tools.autoenum',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
+
+napoleon_google_docstring = True
+napoleon_numpy_docstring = False
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'sphinx_rtd_theme'
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# -- Markdown from docstrings ------------------------------------------------
+
+# import commonmark
+
+# def docstring(app, what, name, obj, options, lines):
+# md = '\n'.join(lines)
+# ast = commonmark.Parser().parse(md)
+# rst = commonmark.ReStructuredTextRenderer().render(ast)
+# lines.clear()
+# lines += rst.splitlines()
+
+# def setup(app):
+# app.connect('autodoc-process-docstring', docstring)
diff --git a/docs/api_docs/python/index.rst b/docs/api_docs/python/index.rst
new file mode 100644
index 0000000..20478cb
--- /dev/null
+++ b/docs/api_docs/python/index.rst
@@ -0,0 +1,23 @@
+.. IREE Python API documentation master file, created by
+ sphinx-quickstart on Sat Sep 25 16:59:09 2021.
+ You can adapt this file completely to your liking, but it should at least
+ contain the root `toctree` directive.
+
+Welcome to IREE's Python API documentation!
+===========================================
+
+.. toctree::
+ :maxdepth: 2
+ :caption: API Docs
+
+ runtime.rst
+ compiler/index.rst
+
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
diff --git a/docs/api_docs/python/requirements.txt b/docs/api_docs/python/requirements.txt
new file mode 100644
index 0000000..23a8c34
--- /dev/null
+++ b/docs/api_docs/python/requirements.txt
@@ -0,0 +1,7 @@
+sphinx==4.2.0
+myst-parser==0.15.2 # For markdown
+sphinx_material==0.0.34
+sphinx_rtd_theme==1.0.0
+commonmark==0.9.1
+enum_tools==0.6.4
+sphinx_toolbox==2.14.1
diff --git a/docs/api_docs/python/runtime.rst b/docs/api_docs/python/runtime.rst
new file mode 100644
index 0000000..5e2de7a
--- /dev/null
+++ b/docs/api_docs/python/runtime.rst
@@ -0,0 +1,7 @@
+Runtime API
+===========
+
+.. automodule:: iree.runtime
+ :members:
+ :imported-members:
+ :undoc-members: