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

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

Convert a Julia type typ to its LLVM representation in the current context. The allow_boxed argument determines whether boxed types are allowed.

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...)

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 a tuple expression containing 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

LLVM type support

LLVM.Interop.@typed_ccallMacro
@typed_ccall(intrinsic, llvmcall, rettyp, (argtyps...), args...)

Perform a ccall while more accurately preserving argument types like LLVM expects them:

  • Bools are passed as i1, not i8;
  • Pointers (both Ptr and Core.LLVMPtr) are passed as typed pointers (instead of resp. i8* and i64);
  • Val-typed arguments will be passed as constants, if supported.

These features can be useful to call LLVM intrinsics, which may expect a specific set of argument types.

Note

This macro is not needed anymore on Julia 1.12, where the llvmcall ABI has been extended to preserve argument types more accurately.

source