Julia/LLVM interop

This section lists functionality for connecting Julia with LLVM.jl, e.g. emitting code for the Julia JIT or creating types that are compatible with Julia's global state.

Base functionality

LLVM.Interop.JuliaContextFunction
JuliaContext()
JuliaContext(f::Function)

Returns the (session-bound) LLVM context used by the Julia compiler. This only works on Julia 1.5 or below; starting with Julia 1.6 there is no global context. On those versions, you need to use the do-block version of this function to create a temporary context, and pipe it through instead of assuming and accessing a single global contex. The do-block version also works on 1.5 and below, where it just returns the global context.

source
Base.convertMethod
convert(LLVMType, typ::Type, ctx::Context; allow_boxed=true)

Convert a Julia type typ to its LLVM representation. Fails if the type would be boxed.

source
LLVM.Interop.create_functionFunction
create_function(rettyp::LLVMType, argtyp::Vector{LLVMType}, [name::String])

Create an LLVM function, given its return type rettyp and a vector of argument types argtyp. The function is marked for inlining, to be embedded in the caller's body. Returns both the newly created function, and its type.

source
LLVM.Interop.call_functionFunction
call_function(f::LLVM.Function, rettyp::Type, argtyp::Type, args::Expr)

Generate a call to an LLVM function f, given its return type rettyp and a tuple-type for the arguments. The arguments should be passed as an expression yielding a tuple of the argument values (eg. :((1,2))), which will be splatted into the call to the function.

source

Inline assembly

LLVM.Interop.@asmcallMacro
@asmcall asm::String [constraints::String] [side_effects::Bool=false]
         rettyp=Nothing argtyp=Tuple{} args...

Call some inline assembly asm, optionally constrained by constraints and denoting other side effects in side_effects, specifying the return type in rettyp and types of arguments as a tuple-type in argtyp.

source