How to generate a reusable static LLVM IR module?

Hello, I am a beginner in Julia programming.

I need a way to generate a static LLVM IR module for functions written in Julia and modify the LLVM IR that was generated.

I saw on CUDAnative.jl , there are some features like CodegenHooks, CodegenParams to disable some incompatible language features and the function _dump_function . How can I use the same approach by using Julia 1.7.1 or a more recent version because CUDAnative was implemented for Julia 1.O ?

In the package GPUcompiler.jl the function Irgen can help me , but I don’t know how to use it. If someone could explain to me it would be great.

If there is another way to generate a static LLVM IR module by using Julia 1.7.1 or a more recent version. Don’t hesitate to explain to me.

Thanks in advance for your help.

While this isn’t super begginer stuff, you can use GPUCompiler.jl together with LLVM.jl to play around with the LLVM IR

1 Like

Do you have any examples that could help us understand how I can use GPUCompiler.jl with LLVM.jl to play with LLVM IR ?

I would look at the GPUCompiler.jl tests or the entire StaticCompiler.jl codebase since it’s pretty simple and should give you a nice headstart

1 Like

I looked at the functions of the StaticCompiler package and I finally found in the function generate_obj
the process that I had to use. The process works very well but unfortunately as soon as in my code I call global variables there is a segmentation fault in the function relocation_table!. And I don’t know how to fix it. Do you have any idea how I can fix it ?