Essentials

Initialization

LLVM.backendsFunction
backends()

Return a list of back-ends supported by the LLVM library.

source
LLVM.InitializeAllTargetsFunction
LLVM.InitializeAllTargets()
LLVM.InitializeXXXTarget()
LLVM.InitializeNativeTarget()

Enables use of specific targets.

source
LLVM.InitializeAllAsmParsersFunction
LLVM.InitializeAllAsmParsers()
LLVM.InitializeXXXAsmParser()
LLVM.InitializeNativeAsmParser()

Enables use of assembly parsing functionality for specific targets.

source
LLVM.InitializeAllAsmPrintersFunction
LLVM.InitializeAllAsmPrinters()
LLVM.InitializeXXXAsmPrinter()
LLVM.InitializeNativeAsmPrinter()

Enables use of assembly output functionality for specific targets.

source
LLVM.InitializeAllDisassemblersFunction
LLVM.InitializeAllDisassemblers()
LLVM.InitializeXXXDisassembler()
LLVM.InitializeNativeDisassembler()

Enables use of disassembly functionality for specific targets.

source

Contexts

LLVM.ContextType
LLVM.Context

Execution state for the core LLVM IR system. Created by calling the Context() constructor, and should be disposed of.

Most types are tied to a context instance. Multiple contexts can exist simultaneously. A single context is not thread safe. However, different contexts can execute on different threads simultaneously.

source
LLVM.ContextMethod
LLVM.Context(; opaque_pointers=nothing)

Create a new LLVM context. If opaque_pointers is true, the context will use opaque pointers instead of typed pointers (if suppoprted). Otherwise the behavior of the context depends on the LLVM version.

This object needs to be disposed of using dispose(::Context).

source
LLVM.disposeMethod
dispose(ctx::Context)

Dispose of the context, releasing all resources associated with it. The context should not be used after this operation.

source

LLVM.jl also tracks the context in task-local scope:

LLVM.contextMethod
context(; throw_error::Bool=true)

Get the active LLVM context for the current tasks. Throws an exception if no context is active, unless throw_error=false.

source
LLVM.activateMethod
activate(ctx::LLVM.Context)

Pushes a new context onto the context stack.

source
LLVM.deactivateMethod
deactivate(ctx::LLVM.Context)

Pops the current context from the context stack.

source
LLVM.context!Function
context!(ctx::LLVM.Context) do
    ...
end

Temporarily activates the given context for the duration of the block.

source
LLVM.ts_contextFunction
ts_context(; throw_error::Bool=true)

Get the active LLVM thread-safe context for the current tasks. Throws an exception if no context is active, unless throw_error=false.

source
LLVM.activateMethod
activate(ts_ctx::LLVM.ThreadSafeContext)

Pushes a new thread-safe context onto the context stack.

source
LLVM.deactivateMethod
deactivate(ts_ctx::LLVM.ThreadSafeContext)

Pops the current thread-safe context from the context stack.

source
LLVM.ts_context!Function
ts_context!(ts_ctx::LLVM.ThreadSafeContext) do
    ...
end

Temporarily activates the given thread-safe context for the duration of the block.

source

Resources

LLVM.@disposeMacro
@dispose foo=Foo() bar=Bar() begin
    ...
end

Helper macro for disposing resources (by calling the dispose function for every resource in reverse order) after executing a block of code. This is often equivalent to calling the recourse constructor with do-block syntax, but without using (potentially costly) closures.

source

Exceptions

LLVM.LLVMExceptionType
LLVMException

Exception type for errors in the LLVM API. Possibly thrown by diagnostic handlers, and fatal eror handlers.

source

Memory buffers

LLVM.MemoryBufferMethod
MemoryBuffer(data::Vector{T}, name::String="", copy::Bool=true)

Create a memory buffer from the given data. If copy is true, the data is copied into the buffer. Otherwise, the user is responsible for keeping the data alive across the lifetime of the buffer.

This object needs to be disposed of using dispose.

source
LLVM.MemoryBufferFileFunction
MemoryBufferFile(path::String)

Create a memory buffer from the contents of a file.

This object needs to be disposed of using dispose.

source
LLVM.disposeMethod
dispose(membuf::MemoryBuffer)

Dispose of the given memory buffer.

source

Other

LLVM.cloptsFunction
clopts(opts...)

Parse the given arguments using the LLVM command-line parser.

Note that this function modifies the global state of the LLVM library. It is also not safe to rely on the stability of the command-line options between different versions of LLVM.

source