[SAoC] MLIR Support for LDC

Johan j at j.nl
Thu Oct 3 18:38:35 UTC 2019


On Thursday, 3 October 2019 at 12:58:38 UTC, Roberto Rosmaninho 
wrote:
> On Thursday, 3 October 2019 at 06:22:35 UTC, Johan Engelen 
> wrote:
>
>> This doesn't look quite right.
>> You should `ninja install` LLVM (set an install path using 
>> -DCMAKE_INSTALL_PREFIX="..." when running cmake to generate 
>> the ninja build file), such that you get a local LLVM 
>> installation that contains also the MLIR stuff. Are you sure 
>> that MLIR is built when building LLVM? Perhaps cmake argument 
>> -DLLVM_ENABLE_PROJECTS="mlir;compiler-rt;lld" is needed.
>>
>> -Johan
>
> Actually, this is a complex question. Today, to get MLIR, you 
> must clone LLVM and MLIR from different repositories by cloning 
> MLIR into the LLVM projects[1]. The expectation is to have MLIR 
> into LLVM 11 and then you will be able to get the project using 
> the -DLLVM_ENABLE_PROJECTS, which will download the project on 
> the same projects directory used today and referred on my CMake.

I know how MLIR is to be included into the LLVM source directory. 
This is the same method that compiler-rt and clang used to be 
before the single big LLVM repo happened recently.
But I think that also means that mlir will be installed in the 
LLVM installation dir. So instead of searching in 
"${LLVM_ROOT_DIR}/../projects/mlir" (which I think will only work 
with your directory layout), you should be able to find the 
include files in "${LLVM_ROOT_DIR}/include/mlir" no?
The benefit of that is that your MLIR branch will work for others 
that have mlir too (even if a distribution carries MLIR, without 
a user having to compiler it).

> I believe your point is that if users don't get this project on 
> they LLVM, then they won't be able to use LDC, please correct 
> me if I get it wrong. Well, the thing is I have to use some 
> header files to implement MLIR to LDC, maybe I can put some 
> Macros to not compile those files or codes that use MLIR if 
> that's the main issue.

Separate issue, but indeed. Simply do something like this in 
CMake and #ifdef code that cannot be compiled without MLIR:
if(LLVM_MLIR_FOUND)
     message(STATUS "Building with MLIR support")
     add_definitions("-DLDC_LLVM_MLIR_ENABLED")
endif()

(that's exactly how SPIR-V support is added to LDC)

cheers,
   Johan




More information about the Digitalmars-d mailing list