Add an option to disable use of bundled LLVM. (#12256)

* Adds an option `IREE_BUILD_BUNDLED_LLVM` (default ON) which builds
LLVM+tools from the in-repo submodule (`third_party/llvm-project`). When
disabled, CMake must be configured such that find_package for `LLVM`,
`MLIR`, and `LLD` functions and are at commit levels appropriate.
* Re-organizes the LLVM cmake setup to be better contained and
normalized vs in-tree/bundled and installed.
* Switches MLIR sub-projects iree-dialects, mlir-hlo and torch-dialects
to configure from the main IREE build so that they can be used on top of
a locally built or installed LLVM.
* Updates mechanisms for locating lit so that it is consistent between
the two modes.
* Moves the binary directory for `third_party/llvm-project/llvm` ->
`llvm-project`. This means that folks interacting with the bundled LLVM
in the build directory will say things like `ninja llvm-project/all` or
`./llvm-project/bin/mlir-opt`.
* Moves the MLIR sub-projects from under
`llvm-project/tools/{subproject}` ->
`llvm-external-projects/{subproject}` so that it is consistent between
bundled and installed modes. Practically, this means that if invoking
`iree-dialects-opt` from the command line, it is in a different place.
* Fix to a transform dialect ODR issue which was latent and a namespace
conflict with upstream. Not sure what triggered it but put it down to
the vagaries of linking.
* Fix to the VMVX dependent dialects that came up when building IREE
with all backends disabled.

With this, I was able to install my own LLVM with these commands:

```
cd third_party/llvm-project
mkdir build
cd build
cmake -G Ninja ../llvm \
   -DLLVM_ENABLE_PROJECTS="mlir;lld" \
   -DLLVM_BUILD_EXAMPLES=OFF \
   -DLLVM_TARGETS_TO_BUILD="" \
   -DLLVM_INSTALL_UTILS=ON \
   -DCMAKE_BUILD_TYPE=Release \
   -DLLVM_ENABLE_ASSERTIONS=ON \
   -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON \
   -DLLVM_CCACHE_BUILD=ON
ninja
cmake -DCMAKE_INSTALL_PREFIX=$HOME/tmp/llvm -P cmake_install.cmake
```

```
cmake -GNinja -B ../iree-build-inst/ -S . \
    -DIREE_TARGET_BACKEND_DEFAULTS=OFF \
    -DIREE_HAL_DRIVER_DEFAULTS=OFF \
    -DIREE_HAL_DRIVER_LOCAL_SYNC=ON \
    -DIREE_HAL_DRIVER_LOCAL_TASK=ON \
    -DIREE_BUILD_BUNDLED_LLVM=OFF \
    -DLLVM_DIR=$HOME/tmp/llvm/lib/cmake/llvm \
    -DMLIR_DIR=$HOME/tmp/llvm/lib/cmake/mlir \
    -DLLD_DIR=$HOME/tmp/llvm/lib/cmake/lld \
    -DCMAKE_BUILD_TYPE=Release
```

* Python builds have not yet been tested in the installed path and need
some ergonomic help.
* Will follow-up with a script to build various configurations of
LLVM/MLIR/LLD so that we can wire it up to CI.

Progress on #12231
22 files changed
tree: b182bfbe13c882d3e36ed5a2bccc214d7c82281c
  1. .github/
  2. benchmarks/
  3. build_tools/
  4. compiler/
  5. docs/
  6. experimental/
  7. integrations/
  8. llvm-external-projects/
  9. runtime/
  10. samples/
  11. tests/
  12. third_party/
  13. tools/
  14. .bazelignore
  15. .bazelrc
  16. .bazelversion
  17. .clang-format
  18. .dockerignore
  19. .gitignore
  20. .gitmodules
  21. .pylintrc
  22. .style.yapf
  23. .yamllint.yml
  24. AUTHORS
  25. BUILD.bazel
  26. CITATION.cff
  27. CMakeLists.txt
  28. configure_bazel.py
  29. CONTRIBUTING.md
  30. LICENSE
  31. README.md
  32. WORKSPACE
README.md

IREE: Intermediate Representation Execution Environment

IREE (Intermediate Representation Execution Environment, pronounced as “eerie”) is an MLIR-based end-to-end compiler and runtime that lowers Machine Learning (ML) models to a unified IR that scales up to meet the needs of the datacenter and down to satisfy the constraints and special considerations of mobile and edge deployments.

See our website for project details, user guides, and instructions on building from source.

CI Status

Project Status

IREE is still in its early phase. We have settled down on the overarching infrastructure and are actively improving various software components as well as project logistics. It is still quite far from ready for everyday use and is made available without any support at the moment. With that said, we welcome any kind of feedback on any communication channels!

Communication Channels

Related Project Channels

  • MLIR topic within LLVM Discourse: IREE is enabled by and heavily relies on MLIR. IREE sometimes is referred to in certain MLIR discussions. Useful if you are also interested in MLIR evolution.

Architecture Overview

IREE Architecture IREE Architecture

See our website for more information.

Presentations and Talks

  • 2021-06-09: IREE Runtime Design Tech Talk (recording and slides)
  • 2020-08-20: IREE CodeGen: MLIR Open Design Meeting Presentation (recording and slides)
  • 2020-03-18: Interactive HAL IR Walkthrough (recording)
  • 2020-01-31: End-to-end MLIR Workflow in IREE: MLIR Open Design Meeting Presentation (recording and slides)

License

IREE is licensed under the terms of the Apache 2.0 License with LLVM Exceptions. See LICENSE for more information.