Getting Started to MLIR in 2021 - Thu, Jun 3, 2021
Tips and pitfalls bootstraping MLIR
I recently got some interest into making compilers, and MLIR seems to be a great choice.
The official guide suggests that you use these arguments to compile MLIR:
cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS=mlir \ -DLLVM_BUILD_EXAMPLES=ON \ -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON
However, it will lead to problems later if you are going to use MLIR in an external project. For example, if
you directly copy the official
example/standalone project, you will see this problem.
standalone example project is easy. First make sure that you install the build LLVM project to a prefix, and now you can compile the
standalone demo with:
cmake -G Ninja .. -DMLIR_DIR=$LLVM_INSTALL_PREFIX/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit
Note that the build dir is
<somewhere>/llvm-project/build if you use the official guide.
$LLVM_INSTALL_PREFIX is what you have input in
Adapting the MLIR tutorial
Basically what you need is to reduce the
standalone example project. If you want to see a complete repo, see here.