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.convert
— Methodconvert(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.
LLVM.Interop.create_function
— Functioncreate_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.
LLVM.Interop.call_function
— Functioncall_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.
Inline assembly
LLVM.Interop.@asmcall
— Macro@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
.
LLVM type support
LLVM.Interop.@typed_ccall
— Macro@typed_ccall(intrinsic, llvmcall, rettyp, (argtyps...), args...)
Perform a ccall
while more accurately preserving argument types like LLVM expects them:
Bool
s are passed asi1
, noti8
;- Pointers (both
Ptr
andCore.LLVMPtr
) are passed as typed pointers (instead of resp.i8*
andi64
); 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.
This macro is not needed anymore on Julia 1.12, where the llvmcall
ABI has been extended to preserve argument types more accurately.