LLVM’s MLIR is a really exciting project, unlocking many possibilities for cutting-edge compiler development. However, as is notorious with LLVM’s documentation, the instructions to install it are rather opaque.
This post aims to rectify this situation by enumerating how MLIR can be installed on MacOS. It is also available as a gist.
Build dependencies
On MacOS, building MLIR requires installing ninja
and cmake
, along with
xcode’s developer tools.
Build commands
The following commands modified from https://mlir.llvm.org/getting_started/#unix-like-compiletesting can then be run to build MLIR. The changes include only shallow copying the LLVM repo and including the commented out clang flags for CMake.
1git clone --depth=1 https://github.com/llvm/llvm-project.git
2mkdir llvm-project/build
3cd llvm-project/build
4cmake -G Ninja ../llvm \
5 -DLLVM_ENABLE_PROJECTS=mlir \
6 -DLLVM_BUILD_EXAMPLES=ON \
7 -DLLVM_TARGETS_TO_BUILD="Native;NVPTX;AMDGPU" \
8 -DCMAKE_BUILD_TYPE=Release \
9 -DLLVM_ENABLE_ASSERTIONS=ON \
10 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
11cmake --build . --target check-mlir
Including built binaries in the PATH
Then, the built binaries can be moved to ~/.local/share
and symlinked to
~/.local/bin
to be included in the users PATH
with:
1mv bin ~/.local/share/mlir
2ln -s $HOME/.local/share/mlir/mlir-opt mlir-opt # + whatever other tools are being used
Testing the installation
And you can test if this has worked with
1mlir-opt --help
Cleaning up
Finally, the llvm-project/
directory can be deleted.