# How to generate a reusable static LLVM IR module?

**URL:** <https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226>\
**Category:** GPU\
**Created:** [June 23, 2022, 7:57am UTC](https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226 "2022-06-23T07:57:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![knlv.ok](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@knlv.ok](https://discourse.julialang.org/u/knlv.ok)\
**Post date:** [June 23, 2022, 7:57am UTC](https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226/1 "2022-06-23T07:57:44Z")

</div>

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](https://github.com/JuliaGPU/CUDAnative.jl/blob/e9a5b4f5cef552bc4901f7b9d5a290de947062d7/src/jit.jl#L65-L67)**, **[CodegenParams](https://github.com/JuliaGPU/CUDAnative.jl/blob/e9a5b4f5cef552bc4901f7b9d5a290de947062d7/src/jit.jl#L68-L72)** to disable some incompatible language features and the function **[\_dump\_function](https://github.com/JuliaGPU/CUDAnative.jl/blob/e9a5b4f5cef552bc4901f7b9d5a290de947062d7/src/jit.jl#L73-L76)**. 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](https://github.com/JuliaGPU/GPUCompiler.jl/blob/master/src/irgen.jl#L3-L106)** 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.

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [June 23, 2022, 11:55am UTC](https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226/2 "2022-06-23T11:55:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knlv.ok](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@knlv.ok](https://discourse.julialang.org/u/knlv.ok)\
**Post date:** [July 1, 2022, 3:54pm UTC](https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226/3 "2022-07-01T15:54:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [July 1, 2022, 5:50pm UTC](https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226/4 "2022-07-01T17:50:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knlv.ok](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@knlv.ok](https://discourse.julialang.org/u/knlv.ok)\
**Post date:** [July 25, 2022, 11:44am UTC](https://discourse.julialang.org/t/how-to-generate-a-reusable-static-llvm-ir-module/83226/5 "2022-07-25T11:44:21Z")

</div>

I looked at the functions of the StaticCompiler package and I finally found in the function [generate\_obj](https://github.com/tshort/StaticCompiler.jl/blob/master/src/StaticCompiler.jl#L139-L158)  
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!](https://github.com/tshort/StaticCompiler.jl/blob/master/src/StaticCompiler.jl#L154). And I don’t know how to fix it. Do you have any idea how I can fix it ?
