Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use llvm-dialects as specification layer for Julia LLVM IR #52945

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

vchuravy
Copy link
Member

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 vchuravy added speculative Whether the change will be implemented is speculative compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM labels Jan 17, 2024
@gbaraldi
Copy link
Member

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?

@vchuravy
Copy link
Member Author

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

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs seem very sparse (https://github.com/GPUOpen-Drivers/llvm-dialects/blob/dev/docs/Constraints.md), but if it can equivalently encode our JuliaFunction descriptors, it seems useful enough to go with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM speculative Whether the change will be implemented is speculative
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants