I am wondering how to convert Julia code into runnable LLVM IR(the *.ll file).
There is a command named code_llvm
which can compile a Julia function into LLVM IR. But its result contains something like %jl_value_t*
which seems to be an (hidden?) object type, and it doesn't look like pure LLVM IR.
Is there a way to generate runnable LLVM IR from Julia, so that I can run it with lli xx.ll
(or do something else)?
The code_llvm
function just shows the Function by default, but you can also have it print out a complete module:
open("file.ll", "w") do io
code_llvm(io, +, (Int, Int); raw=true, dump_module=true, optimize=true)
end
This output (file.ll
) is now valid to use with other llvm tools, such as llc
and opt
. However, since it's just the code for this one function, and assumes the existence of all the other code and data, it's not necessarily going to work with lli
, so buyer beware.
If you want a complete system, you might be interested in the --output-bc
flag to Julia, which will dump a complete object file in LLVM format. This is used extensively internally to build and bootstrap Julia. It's also wrapped into a utility tool at https://github.com/JuliaLang/PackageCompiler.jl to automate some of these steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With