julia icon indicating copy to clipboard operation
julia copied to clipboard

Use llvm-dialects as specification layer for Julia LLVM IR

Open vchuravy opened this issue 1 year ago • 2 comments

The LLVM IR we emit in codegen uses pseudo-intrinsics to represent the additional language-specific semantics needed for the correct optimization of Julia code. Since Julia uses a precise GC we need to track values in the generated code. We could do so early, but that would clutter the code quite a bit and thus we decided to take a late-lowering approach. We represent enough semantics with our own LLVM dialect so that at the end of the optimization pipeline we can legalize/lower our Julia LLVM dialect to the general LLVM dialect that the backends can emit code for.

We thus far have an informal specification of this Julia LLVM dialect scattered across both codegen and optimizations, and other producers like Enzyme code-generator. The https://github.com/GPUOpen-Drivers/llvm-dialects project provides tools for using an approach similar to MLIR to specify a custom dialect on the LLVM substracte.

This PR is mostly meant to open up the discussion if we want this, but my goal for it is to make it easier for producers like Enzyme (and other GPUCompiler) to emit our dialect correctly, as well as unifying the definition across codegen and optimization passes, and having one place to document and specify the behaviour of our dialect operations.

(Side-comment we have technically at least two dialects one produced by codegen and lowered by late-lowering and then a second between late-lowering and final-lowering)

vchuravy avatar Jan 17 '24 17:01 vchuravy

So tblgen generates a couple .inc files which have the definitions from the .td files. How does someone downstream get this? Do we ship the .inc files or something like this?

gbaraldi avatar Jan 17 '24 18:01 gbaraldi

The generated headers we could ship, the generated cpp get compiled with the rest of the code. We don't check them into the source tree

vchuravy avatar Jan 17 '24 23:01 vchuravy