LLVM
add-attribute
(Fn [LLVMValue, Int, LLVMAttribute] ())
Attach an attribute to a function/callsite at idx (see attr-*-index).
add-case
(Fn [LLVMValue, LLVMValue, LLVMBasicBlock] ())
Add a (on-val -> dest) case to a switch instruction.
add-function
(Fn [LLVMModule, (Ptr CChar), LLVMType] LLVMValue)
Declare a function name of type ty in mod.
add-global
(Fn [LLVMModule, LLVMType, (Ptr CChar)] LLVMValue)
Declare a global variable name of type ty in mod.
add-incoming
(Fn [LLVMValue, (Ref (Array LLVMValue) a), (Ref (Array LLVMBasicBlock) b)] ())
(add-incoming phi vals blocks)
Add incoming vals/blocks (parallel arrays) to a phi node.
add-module-flag
(Fn [LLVMModule, Int, (Ptr CChar), LLVMMetadata] ())
Add a module flag (key -> metadata) with a merge behavior.
add-named-metadata
(Fn [LLVMModule, (Ptr CChar), LLVMValue] ())
Append a value to a named metadata node (e.g. "llvm.ident").
append-block
(Fn [LLVMContext, LLVMValue, (Ptr CChar)] LLVMBasicBlock)
Append a basic block named name to function fn.
build-add
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs + rhs (integer).
build-alloca
(Fn [LLVMBuilder, LLVMType, (Ptr CChar)] LLVMValue)
Stack-allocate a slot of type ty.
build-ashr
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit arithmetic lhs >> rhs.
build-bit-cast
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Reinterpret a value as another type of the same size.
build-br
(Fn [LLVMBuilder, LLVMBasicBlock] LLVMValue)
Emit an unconditional branch to dest.
build-call
(Fn [LLVMBuilder, LLVMType, LLVMValue, (Ref (Array LLVMValue) a), (Ptr CChar)] LLVMValue)
(build-call b fnty fn args name)
Emit a call to fn (of type fnty) with args.
build-cond-br
(Fn [LLVMBuilder, LLVMValue, LLVMBasicBlock, LLVMBasicBlock] LLVMValue)
Branch to then if cond else else.
build-extract-element
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Extract the element at idx (a value) from a vector.
build-extract-value
(Fn [LLVMBuilder, LLVMValue, Int, (Ptr CChar)] LLVMValue)
Extract field idx from an aggregate value.
build-fadd
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs + rhs (floating point).
build-fcmp
(Fn [LLVMBuilder, Int, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit a floating-point comparison with one of the real-* predicates.
build-fdiv
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs / rhs (floating point).
build-fmul
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs * rhs (floating point).
build-fneg
(Fn [LLVMBuilder, LLVMValue, (Ptr CChar)] LLVMValue)
Emit -val (floating point).
build-fp-ext
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Extend a float to a wider float type.
build-fp-to-si
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Convert a float to a signed integer.
build-fp-to-ui
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Convert a float to an unsigned integer.
build-fp-trunc
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Truncate a float to a narrower float type.
build-frem
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs % rhs (floating point).
build-fsub
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs - rhs (floating point).
build-gep
(Fn [LLVMBuilder, LLVMType, LLVMValue, (Ref (Array LLVMValue) a), (Ptr CChar)] LLVMValue)
(build-gep b ty ptr indices name)
Emit a getelementptr into ptr (of pointee type ty) with indices.
build-global-string-ptr
(Fn [LLVMBuilder, (Ptr CChar), (Ptr CChar)] LLVMValue)
Intern str as a private global and yield an i8* to it.
build-icmp
(Fn [LLVMBuilder, Int, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit an integer comparison with one of the int-* predicates.
build-insert-element
(Fn [LLVMBuilder, LLVMValue, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Insert elt at idx (a value) into a vector.
build-insert-value
(Fn [LLVMBuilder, LLVMValue, LLVMValue, Int, (Ptr CChar)] LLVMValue)
Insert elt into field idx of an aggregate value.
build-int-to-ptr
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Cast an integer to a pointer.
build-load
(Fn [LLVMBuilder, LLVMType, LLVMValue, (Ptr CChar)] LLVMValue)
Load a ty value from pointer ptr.
build-lshr
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit logical lhs >> rhs.
build-mul
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs * rhs (integer).
build-ptr-to-int
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Cast a pointer to an integer.
build-sdiv
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit signed lhs / rhs.
build-select
(Fn [LLVMBuilder, LLVMValue, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit cond ? then : else.
build-sext
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Sign-extend an integer to a wider type.
build-shuffle-vector
(Fn [LLVMBuilder, LLVMValue, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Shuffle two vectors v1/v2 by the constant mask.
build-si-to-fp
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Convert a signed integer to a float.
build-srem
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit signed lhs % rhs.
build-struct-gep
(Fn [LLVMBuilder, LLVMType, LLVMValue, Int, (Ptr CChar)] LLVMValue)
Emit a getelementptr to field idx of the struct ty behind ptr.
build-sub
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit lhs - rhs (integer).
build-switch
(Fn [LLVMBuilder, LLVMValue, LLVMBasicBlock, Int] LLVMValue)
Emit a switch on val with else as default, reserving num-cases slots.
Add cases with add-case.
build-trunc
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Truncate an integer to a narrower type.
build-udiv
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit unsigned lhs / rhs.
build-ui-to-fp
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Convert an unsigned integer to a float.
build-urem
(Fn [LLVMBuilder, LLVMValue, LLVMValue, (Ptr CChar)] LLVMValue)
Emit unsigned lhs % rhs.
build-zext
(Fn [LLVMBuilder, LLVMValue, LLVMType, (Ptr CChar)] LLVMValue)
Zero-extend an integer to a wider type.
call-f32-f32
(Fn [Long, Float] Float)
Call a JIT'd (float)->float function at addr with a.
call-i32-i32-i32
(Fn [Long, Int, Int] Int)
Call a JIT'd (i32,i32)->i32 function at addr with a and b.
call-i32-i32-i32-i32
(Fn [Long, Int, Int, Int] Int)
Call a JIT'd (i32,i32,i32)->i32 function at addr with a, b, and c.
const-int
(Fn [LLVMType, Long, Int] LLVMValue)
An integer constant of type ty. sign-extend? sign-extends n.
const-null
(Fn [LLVMType] LLVMValue)
The all-zero/null constant of type ty (good for initializers).
const-vector
(Fn [(Ref (Array LLVMValue) a)] LLVMValue)
(const-vector elems)
A constant vector from the scalar constants elems.
context-create
(Fn [] LLVMContext)
Create a fresh LLVM context. Dispose with context-dispose.
create-enum-attribute
(Fn [LLVMContext, Int, Long] LLVMAttribute)
Create an enum attribute of the given kind (see enum-attribute-kind).
create-execution-engine
(Fn [LLVMModule] LLVMEngine)
Create an MCJIT engine that takes ownership of mod.
Returns a null handle on failure (check with engine-null?).
create-string-attribute
(Fn [LLVMContext, (Ptr CChar), (Ptr CChar)] LLVMAttribute)
Create a string (key=value) attribute.
create-target-data-layout
(Fn [LLVMTargetMachine] LLVMTargetData)
The data layout of a target machine.
Dispose with dispose-target-data; independent of the machine's lifetime.
create-target-machine
(Fn [LLVMTarget, (Ptr CChar), (Ptr CChar), (Ptr CChar), Int, Int, Int] LLVMTargetMachine)
Create a target machine. cpu/features may be empty C strings;
level/reloc/codemodel take the codegen-level-*/reloc-*/codemodel-* values.
debug-location
(Fn [LLVMContext, Int, Int, LLVMMetadata] LLVMMetadata)
A source location (line, col) within scope.
default-target-triple
(Fn [] String)
The host target triple (e.g. "arm64-apple-darwin24.6.0").
di-basic-type
(Fn [LLVMDIBuilder, (Ptr CChar), Long, Int] LLVMMetadata)
A DWARF base type (name, size-in-bits, a dwarf-* encoding).
di-builder-create
(Fn [LLVMModule] LLVMDIBuilder)
Create a debug-info builder for mod. Call di-finalize then
di-builder-dispose when done.
di-compile-unit
(Fn [LLVMDIBuilder, LLVMMetadata, (Ptr CChar)] LLVMMetadata)
A C-language DWARF compile unit for file (defaults: unoptimized, full emission).
di-file
(Fn [LLVMDIBuilder, (Ptr CChar), (Ptr CChar)] LLVMMetadata)
A debug-info file entry (name, dir).
di-finalize
(Fn [LLVMDIBuilder] ())
Resolve all deferred debug-info nodes. Call before disposing.
di-function
(Fn [LLVMDIBuilder, LLVMMetadata, (Ptr CChar), LLVMMetadata, Int, LLVMMetadata] LLVMMetadata)
A DWARF subprogram for a function (defaults: definition, not-local, unoptimized).
di-lexical-block-file
(Fn [LLVMDIBuilder, LLVMMetadata, LLVMMetadata, Int] LLVMMetadata)
A file-specific scope nested under a function scope, for synthesized functions whose instructions originate in many files.
di-subroutine-type
(Fn [LLVMDIBuilder, LLVMMetadata, (Ref (Array LLVMMetadata) a)] LLVMMetadata)
(di-subroutine-type b file param-types)
A function-type descriptor. param-types is [return-type, arg-types...].
dup
(Fn [(Ref a b)] a)
Duplicate a handle out of a reference (e.g. from an array or accessor).
Handles are trivially copyable pointers, but the @ operator needs a copy
implementation they can't have, so use this instead.
emit-to-file
(Fn [LLVMTargetMachine, LLVMModule, (Ptr CChar), Int] String)
Emit mod to path as filetype-object/filetype-assembly.
Returns "" on success or an error String.
enum-attribute-kind
(Fn [(Ptr CChar)] Int)
The numeric kind id for a named enum attribute (e.g. "noinline").
function-address
(Fn [LLVMEngine, (Ptr CChar)] Long)
Address of JIT-compiled function name as a Long, or 0 if absent.
function-type
(Fn [LLVMType, (Ref (Array LLVMType) a), Bool] LLVMType)
(function-type ret params vararg?)
Function type returning ret with parameter types params.
vararg? marks a C-style variadic function.
get-insert-block
(Fn [LLVMBuilder] LLVMBasicBlock)
The basic block the builder is currently appending to (needed as the incoming block for a phi after emitting a branch's body).
get-named-function
(Fn [LLVMModule, (Ptr CChar)] LLVMValue)
Look up a declared function by name (may be a null handle).
get-named-global
(Fn [LLVMModule, (Ptr CChar)] LLVMValue)
Look up a global variable by name (may be a null handle).
initialize-native-asm-printer
(Fn [] Int)
Initialize the host asm printer. Returns 0 on success.
initialize-native-target
(Fn [] Int)
Initialize codegen for the host target. Returns 0 on success.
instruction?
(Fn [LLVMValue] Bool)
Whether an LLVM value is an instruction rather than a constant, function, global, or argument.
link-in-mcjit
(Fn [] ())
Pull the MCJIT engine into the link. Call once before creating an engine.
md-kind-id
(Fn [LLVMContext, (Ptr CChar)] Int)
Intern a metadata kind name (e.g. "dbg", "tbaa") to an id.
md-node
(Fn [LLVMContext, (Ref (Array LLVMMetadata) a)] LLVMMetadata)
(md-node ctx operands)
Create a metadata node (tuple) from operands.
memory-buffer-of-file
(Fn [(Ptr CChar)] LLVMMemoryBuffer)
Read a file into a memory buffer, or a null handle on error.
metadata-as-value
(Fn [LLVMContext, LLVMMetadata] LLVMValue)
Wrap metadata as a value (for set-metadata/named metadata).
module-create
(Fn [(Ptr CChar), LLVMContext] LLVMModule)
Create a module named name in ctx.
module-null?
(Fn [LLVMModule] Bool)
Whether a module handle is null (e.g. a failed parse).
offset-of-element
(Fn [LLVMTargetData, LLVMType, Int] Long)
Byte offset of struct element idx under a data layout.
orc-add-module
(Fn [LLVMOrcLLJIT, LLVMOrcJITDylib, LLVMOrcThreadSafeModule] String)
Add a thread-safe module to the persistent JIT. The JIT takes ownership when called, including on failure. Returns an error string.
orc-add-module-tracked
(Fn [LLVMOrcLLJIT, LLVMOrcResourceTracker, LLVMOrcThreadSafeModule] String)
Add a thread-safe module under tracker. ORC
takes module ownership when called, including on failure.
orc-clear-dylib
(Fn [LLVMOrcJITDylib] String)
Remove every resource published in a JITDylib. Returns an error string; the LLJIT and its shared context remain alive.
orc-dispose-lljit
(Fn [LLVMOrcLLJIT] ())
Dispose a persistent LLJIT and all code it owns.
orc-dispose-thread-safe-context
(Fn [LLVMOrcThreadSafeContext] ())
Release the caller's shared-context reference.
orc-enable-process-symbols
(Fn [LLVMOrcLLJIT] String)
Make symbols from the current process and RTLD_GLOBAL libraries visible to JIT modules. Returns an error string.
orc-lookup
(Fn [LLVMOrcLLJIT, (Ptr CChar)] Long)
Look up a published symbol, returning its address or zero.
orc-release-resource-tracker
(Fn [LLVMOrcResourceTracker] ())
Release the caller's resource-tracker reference.
orc-remove-resources
(Fn [LLVMOrcResourceTracker] String)
Remove every JIT resource associated with a tracker.
orc-resource-tracker
(Fn [LLVMOrcJITDylib] LLVMOrcResourceTracker)
Create a resource tracker for one incremental module. Release the caller's reference after publishing or removing it.
orc-thread-safe-context
(Fn [LLVMContext] LLVMOrcThreadSafeContext)
Transfer ctx into a shared ORC context.
Do not dispose ctx separately after this call.
orc-thread-safe-module
(Fn [LLVMModule, LLVMOrcThreadSafeContext] LLVMOrcThreadSafeModule)
Wrap mod in the shared context and transfer
module ownership to the wrapper.
parse-ir
(Fn [LLVMContext, LLVMMemoryBuffer] LLVMModule)
Parse textual IR or bitcode in buf into a module (consumes buf).
Returns a null-module handle on error; check with module-null?.
pass-options-create
(Fn [] LLVMPassBuilderOptions)
Create pass-builder options. Dispose with pass-options-dispose.
position-at-end
(Fn [LLVMBuilder, LLVMBasicBlock] ())
Point the builder at the end of block.
print-module
(Fn [LLVMModule] String)
Render a module's textual IR as a Carp String (owns the copy).
run-passes
(Fn [LLVMModule, (Ptr CChar), LLVMTargetMachine, LLVMPassBuilderOptions] String)
Run a pass pipeline (e.g. "default", "instcombine,mem2reg") on mod.
Returns "" on success or an error String.
set-debug-location
(Fn [LLVMBuilder, LLVMMetadata] ())
Set the builder's current debug location for emitted instructions.
set-global-constant
(Fn [LLVMValue, Int] ())
Mark a global variable as constant (1) or mutable (0).
set-initializer
(Fn [LLVMValue, LLVMValue] ())
Set the constant initializer of a global variable.
set-instruction-debug-location
(Fn [LLVMValue, LLVMMetadata] ())
Attach a debug location directly to an instruction value.
set-linkage
(Fn [LLVMValue, Int] ())
Set the linkage of a function or global with a linkage-* value.
set-metadata
(Fn [LLVMValue, Int, LLVMValue] ())
Attach metadata node of kind kind-id to an instruction value.
set-module-data-layout
(Fn [LLVMModule, LLVMTargetData] ())
Attach a data layout to a module.
set-subprogram
(Fn [LLVMValue, LLVMMetadata] ())
Attach a di-function subprogram to a function value.
setup
Dynamic
(setup :rest prefix)
Wire include paths and linking against a Homebrew LLVM keg.
prefix defaults to the Homebrew LLVM keg on macOS and the output of
llvm-config --prefix elsewhere. Pass another LLVM prefix as the first
argument to override it.
struct-create-named
(Fn [LLVMContext, (Ptr CChar)] LLVMType)
Create an (initially opaque) named struct type in ctx.
Fill it in later with struct-set-body — this is how you build recursive types.
struct-set-body
(Fn [LLVMType, (Ref (Array LLVMType) a), Bool] ())
(struct-set-body ty elems packed?)
Set the field types of a named struct.
struct-type
(Fn [LLVMContext, (Ref (Array LLVMType) a), Bool] LLVMType)
(struct-type ctx elems packed?)
An anonymous struct type with fields elems. packed? removes padding.
target-from-triple
(Fn [(Ptr CChar)] LLVMTarget)
Look up the target for a triple. Null handle on failure (see target-null?).
value-as-metadata
(Fn [LLVMValue] LLVMMetadata)
View a value (e.g. a constant) as metadata.
value-null?
(Fn [LLVMValue] Bool)
Whether a value handle is null (e.g. a failed named lookup).
vector-type
(Fn [LLVMType, Int] LLVMType)
A fixed-width vector of count elements of type elem.
verify-module
(Fn [LLVMModule] String)
Verify a module. Returns "" if valid, else the error String.
write-bitcode-to-file
(Fn [LLVMModule, (Ptr CChar)] Int)
Write module bitcode to path. Returns 0 on success.
write-module-to-file
(Fn [LLVMModule, (Ptr CChar)] String)
Write textual IR to path. Returns "" on success or an error String.