[SAoC] MLIR Support for LDC

Johan Engelen j at j.nl
Wed Oct 2 20:31:02 UTC 2019


On Wednesday, 2 October 2019 at 18:43:14 UTC, Roberto Rosmaninho 
wrote:
> Hi everyone,
> I'm here just to report the status of my project on its second 
> week:
>
>  - I Read all documentation from MLIR
>  - I Started to implement mlirstate.h and mlirstate.cpp
>  - I Started to implement mlircodegenerator.h 
> mlircodegenerator.cpp
>
> The main issue that I stuck this week was to compile ldc with 
> my modifications due to problems with mlir headers and 
> dmd/globals.h.
> So I had these 2 questions and I hope someone could help me:
>
>  - What is the best way to refer mlir (a project inside llvm, 
> like clang) into ldc CMakeLists.txt? I need the headers 
> provided by this project to write my codes.

As far as I can tell, if you checkout MLIR into your local LLVM 
checkout [1], then it is automatically built with LLVM and the 
header files will be part of the LLVM install. So to get to the 
headers you probably don't have to add anything in LDC's 
CMakeLists.txt.
For linking correctly, you probably have to add similar CMake 
code as is done for SPIR-V, see the cmake code around 
`LLVM_SPIRV_FOUND`.

>  - I'm trying to do the same things that ldc does to get LLVM 
> IR, so I tried to create a "DArray<const char> mlir_ext;" in 
> dmd/globals.h:296, but when I compile ldc with -vv it stops at 
> " Targeting 'x86_64-apple-macosx' (CPU 'core2' with features 
> '') " and tell me that the process finished with exit code 1. 
> How can I fix this? And if I'm doing something wrong, what is 
> the best way to get these variables for ldc and what is its 
> function on the program? I thought it was setting the file 
> extension, but I'm not sure.

globals.h _must exactly_ match with globals.d and there is no 
tool that will check that for you ('.h' is used by the C++ 
compiler, '.d' by the D compiler and they don't talk to each 
other). One way to look at it is that `globals.d` is the `.cpp` 
file belonging to `globals.h`.
For your particular issue: is you add `mlir_ext` to `globals.h`, 
you have to add it to `globals.d` in _exactly the same_ location 
in the `Global` struct.

Do you aim to take a similar approach as the SPIR-V/dcompute 
mechanism?

cheers,
   Johan

[1] https://github.com/tensorflow/mlir



More information about the Digitalmars-d mailing list