| # 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. | |
| # Build the IREE documentation with CMake. Designed for CI, but can be run | |
| # manually. This uses previously cached build results and does not clear the | |
| # build directory. | |
| set -x | |
| set -e | |
| ROOT_DIR=$(git rev-parse --show-toplevel) | |
| BUILD_DIR=${BUILD_DIR:-"build-docs"} | |
| CMAKE_BIN=${CMAKE_BIN:-$(which cmake)} | |
| "$CMAKE_BIN" --version | |
| ninja --version | |
| cd ${ROOT_DIR?} | |
| if [ -d ${BUILD_DIR} ] | |
| then | |
| echo "Build directory already exists. Will use cached results there." | |
| else | |
| echo "Build directory does not already exist. Creating a new one." | |
| mkdir ${BUILD_DIR} | |
| fi | |
| cd ${BUILD_DIR} | |
| "$CMAKE_BIN" .. -DCMAKE_BUILD_TYPE=Release \ | |
| -DIREE_BUILD_COMPILER=ON \ | |
| -DIREE_BUILD_TESTS=ON \ | |
| -DIREE_BUILD_SAMPLES=OFF \ | |
| -DIREE_BUILD_DOCS=ON \ | |
| -DIREE_BUILD_DEBUGGER=OFF \ | |
| -DIREE_BUILD_PYTHON_BINDINGS=OFF \ | |
| -G Ninja | |
| # Generate docs and also build iree-opt for generating more docs :) | |
| ninja iree-doc iree-opt | |
| cd ${ROOT_DIR} | |
| # Copy docs in source tree over | |
| cp README.md ${BUILD_DIR}/doc/index.md | |
| cp -rf docs/* ${BUILD_DIR}/doc/ | |
| # Update op_coverage.md | |
| scripts/update_op_coverage.py ${BUILD_DIR} | |
| # Update e2e_coverage.md | |
| PYTHON_BIN=`which python3` scripts/update_e2e_coverage.py ${BUILD_DIR} | |
| # Generate IR conversion flow examples | |
| # The list of input IR examples | |
| declare -a ir_examples=( | |
| iree/samples/ops/mhlo-dot.mlir | |
| ) | |
| # The list of compiler targets | |
| declare -a compiler_targets=( | |
| llvm-ir | |
| vmla | |
| vulkan-spirv | |
| ) | |
| mkdir -p ${BUILD_DIR}/doc/ir_examples | |
| for example in "${ir_examples[@]}"; do | |
| for target in "${compiler_targets[@]}"; do | |
| example_name=$(basename ${example%.mlir}) | |
| filepath=${BUILD_DIR}/doc/ir_examples/${example_name}-${target}.md | |
| title="${example_name} on ${target}" | |
| echo -e "# ${title}\n" > ${filepath} | |
| preamble=" | |
| This is an IR conversion example auto-generated by running \`iree-opt\` | |
| over [${example_name}](https://github.com/google/iree/tree/main/${example}). | |
| ### The command | |
| " | |
| echo -e "${preamble}" >> ${filepath} | |
| echo -e -n '```shell' >> ${filepath} | |
| cmd=" | |
| iree-opt -iree-transformation-pipeline \\ | |
| -iree-hal-target-backends=${target} \\ | |
| --print-ir-after-all \\ | |
| -mlir-disable-threading \\ | |
| -mlir-elide-elementsattrs-if-larger=8 \\ | |
| ${example} | |
| " | |
| echo -e "${cmd}" >> ${filepath} | |
| echo -e '```' >> ${filepath} | |
| echo -e "### Input IR\n" >> ${filepath} | |
| echo -e '```' >> ${filepath} | |
| cat ${example} >> ${filepath} | |
| tmpfile=$(mktemp) | |
| ${BUILD_DIR}/iree/tools/iree-opt \ | |
| -iree-transformation-pipeline \ | |
| -iree-hal-target-backends=${target} \ | |
| -print-ir-after-all \ | |
| -mlir-disable-threading \ | |
| -mlir-elide-elementsattrs-if-larger=8 \ | |
| ${example} 1>/dev/null 2>${tmpfile} | |
| # Turn pass comment into headers | |
| sed 's!^// \*\*\* IR Dump After \(.*\) \*\*\*$!```\n### IR Dump After \1\n```!' \ | |
| ${tmpfile} >> ${filepath} | |
| # Remove extra empty lines | |
| sed -i '/^$/N;/^\n$/D' ${filepath} | |
| echo -e '```' >> ${filepath} | |
| done | |
| done |