Julia integration

Essentials

LLVM.Interop.isghosttypeFunction
isghosttype(t::Type)
isghosttype(T::LLVMType)

Check if a type is a ghost type, implying it would not be emitted by the Julia compiler. This only works for types created by the Julia compiler (living in its LLVM context).

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

Calling 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 pointer 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

LLVM intrinsics

LLVM.Interop.assumeFunction
assume(cond::Bool)

Assume that the condition cond is true. This is a hint to the compiler, possibly enabling it to optimize more aggressively.

source