[SAoC] MLIR Support for LDC

Johan Engelen j at j.nl
Fri Oct 18 21:43:53 UTC 2019


On Friday, 18 October 2019 at 21:30:16 UTC, Roberto Rosmaninho 
wrote:
> On Thursday, 17 October 2019 at 22:05:30 UTC, Johan wrote:
>> Hey Roberto,
>>   It's fun to read your updates, thanks :)
>
> Hey Johan, I'm glad to hear that, thank you!!
>
>> I hope to get the LLVM 10 fixes into LDC master soon. Then you 
>> can rebase on top of that to make the specific MLIR changes 
>> more obvious and easier to view.
>
> Nic told me about your PR and I'm already trying to rebase my 
> code on it!

I just merged it into LDC master, so you can rebase on LDC master 
again.

>> (I didn't check if you already did this) I find it very 
>> helpful to look at test cases to see what functionality you 
>> are adding. The lit-based testsuite is very convenient for 
>> checking IR output. Did you already add MLIR tests there?
>
> Not yet, I'll use this test suite on this next phase, maybe I 
> can put some tests that I'm already writing there. :)

Exactly. I find it very helpful to immediately add the tests in 
the lit test suite while implementing things.

>> LLVM trunk compilation fixes (not related to MLIR) you can 
>> submit as PRs to LDC. That way your branch is solely about 
>> MLIR changes, and not cluttered by the general LLVM changes 
>> needed.
>
> I'm currently trying to use Linux to update the project and 
> find the projects directory to improve my FindMLIR.cmake but 
> I'm having the following problem over and over and I coudn't 
> figure out what I'm doing wrong:
>
> Commands:
> $ git clone http://github.com/ldc-developers/ldc
> $ cd ldc
> $ git checkout llvm10cmake
> $ mkdir build && cd build
> $ export DMD=~/dlang/dmd-2.087.1/linux/bin64/dmd
> $ cmake -G Ninja ..  -DCMAKE_BUILD_TYPE=Release
> # Cmake works ok and LLVM10 was found, I can put the log of 
> CMake here later if I request.
> $ ninja
> $ ninja install

For LDC, you don't have to do a `ninja install`. If you do, you 
should specify where to install it when running cmake. What I do 
is have a `run_cmake.sh` that runs cmake for me so I can remember 
what options I passed to cmake. For reference, this is my 
`run_cmake.sh` for building with LLVM trunk:
```
cmake -G Ninja -DRT_SUPPORT_SANITIZERS=ON 
-DLDC_DYNAMIC_COMPILE=False 
-DD_COMPILER="/Users/johan/ldc/ldc2-1.12.0-osx-x86_64/bin/ldmd2" 
-DCMAKE_BUILD_TYPE="Debug" 
-DCMAKE_INSTALL_PREFIX="/Users/johan/ldc/johan/installtrunk" 
-DLLVM_ROOT_DIR="/Users/johan/llvm/llvmtrunkinstall" ..
```

Note that I explicitly pass LLVM_ROOT_DIR where my LLVM trunk 
build is installed.

>> I was hoping you had solved these issues. I'm still confused 
>> by "reach projects directory", is it not possible to `ninja 
>> install` MLIR ?
>
> Well, the instructions on MLIR git just ask for a "cmake 
> --build . --target check-mlir" when you're compiling LLVM with 
> MLIR.

The instructions don't say it, because I think most people will 
already know what to do and there are many cases where one would 
_not_ want to install LLVM.
This is what my `run_cmake.sh` looks like for building LLVM:
```
cmake -G Ninja 
-DLLVM_ENABLE_PROJECTS="clang;compiler-rt;lld;polly" 
-DCMAKE_INSTALL_PREFIX="/Users/johan/llvm/llvmtrunkinstall" 
-DLLVM_TARGETS_TO_BUILD="AArch64;ARM;Mips;MSP430;NVPTX;PowerPC;X86" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="RISCV;WebAssembly" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_APPEND_VC_REV=ON -DLLVM_INSTALL_UTILS=ON ..
```
Note the "-DCMAKE_INSTALL_PREFIX", that's where LLVM will be 
installed. And that is what you need to pass to LDC CMake 
"-DLLVM_ROOT_DIR".

Hope that helps,
   Johan



More information about the Digitalmars-d mailing list