Values
General APIs
LLVM.Value — Type
LLVM.ValueAbstract type representing an LLVM value.
Properties
bb.name
bb.name = name::AbstractStringThe name of the basic block, like that of other values.
val.value_typeThe type of the value.
val.name
val.name = name::AbstractStringThe name of the value, or an empty string if it is unnamed. When assigning a name that is already in use in the same function or module, LLVM makes it unique by adding a suffix.
val.contextThe context in which the value was created.
val.usesThe uses of the value, as a read-only view that can be iterated. Each LLVM.Use refers to the user that has the value as an operand. Since LLVM 21, constants like integers do not keep track of their uses, so their uses are always empty.
val.usersThe users of the value, i.e., the user of each of its uses, as a read-only view that can be iterated. Like C++'s Value::users(), a user that uses the value multiple times (e.g., add %x, %x) occurs multiple times.
LLVM.isconstant — Method
isconstant(val::LLVM.Value)Check if the given value is a constant value.
LLVM.isundef — Function
isundef(val::LLVM.Value)Check if the given value is an undef value.
LLVM.ispoison — Function
ispoison(val::LLVM.Value)Check if the given value is a poison value.
LLVM.isnull — Function
isnull(val::LLVM.Value)Check if the given value is a null constant.
LLVM.take_name! — Function
take_name!(val::Value, from::Value)Give val the name of from, which becomes unnamed. Unlike assigning the name, this avoids LLVM making the name unique (by adding a suffix) because from still uses it.
LLVM.strip_pointer_casts — Function
strip_pointer_casts(val::Value)Strip pointer casts from a value, like C++'s Value::stripPointerCasts: bitcasts, address space casts, and getelementptr instructions or constant expressions with all-zero indices. Returns the underlying value, or val itself if it isn't a cast. This does not look through global aliases; see strip_pointer_casts_and_aliases for that.
LLVM.strip_pointer_casts_and_aliases — Function
strip_pointer_casts_and_aliases(val::Value)Strip pointer casts from a value, like strip_pointer_casts, and also look through global aliases to the value they alias.
User values
LLVM.User — Type
LLVM.User <: LLVM.ValueA value that uses other values.
See also the operands property.
Properties
user.operandsThe operands of a user, e.g., an instruction or a constant expression, as a view. For instructions and global values, the view is mutable: assigning to an element, inst.operands[i] = val, replaces that operand, and replace!(inst.operands, old => new) replaces every operand that is old. The operands of other constants cannot be changed, as LLVM uniques constants by their operands; use replace_uses! on the operand to update the constants that use it instead.
The properties of Value are available too.
Constant values
LLVM.Constant — Type
LLVM.Constant <: LLVM.UserAbstract supertype for all constant values.
LLVM.all_ones — Function
all_ones(typ::LLVMType)Create a constant with all bits set to one of the given type.
LLVM.PointerNull — Type
PointerNull <: LLVM.ConstantDataA null pointer constant.
LLVM.UndefValue — Type
UndefValue <: LLVM.ConstantDataAn undefined constant value.
LLVM.PoisonValue — Type
PoisonValue <: LLVM.ConstantDataA poison constant value.
LLVM.ConstantInt — Type
ConstantInt <: LLVM.ConstantDataA constant integer value.
Base.convert — Method
convert(::Type{<:Integer}, val::ConstantInt)Convert a constant integer value back to a Julia integer.
LLVM.ConstantFP — Type
ConstantFP <: LLVM.ConstantDataA constant floating point value.
Properties
val.bitpatternThe bit pattern of a constant floating point value, as the smallest unsigned integer that can hold it (e.g., UInt32 for float, or UInt128 for x86_fp80).
See also ConstantFP, which can create a constant from its bit pattern.
Base.convert — Method
convert(::Type{<:AbstractFloat}, val::ConstantFP)Convert a constant floating point value back to a Julia floating point number.
LLVM.ConstantStruct — Type
ConstantStruct <: LLVM.ConstantAggregateA constant struct of values.
LLVM.ConstantDataSequential — Type
LLVM.ConstantDataSequential <: LLVM.ConstantAbstract supertype of constant arrays and vectors of simple data values: ConstantDataArray and ConstantDataVector.
LLVM.ConstantDataArray — Type
ConstantDataArray <: LLVM.ConstantDataSequentialA constant array of simple data values, i.e., whose element type is a simple 1/2/4/8-byte integer or half/bfloat/float/double, and whose elements are just simple data values. Its elements are available as the elements property, see LLVM.ConstantAggregate.
See also: ConstantArray
LLVM.ConstantDataArray — Method
ConstantDataArray(typ::LLVMType, data::AbstractVector)Create a constant array of simple data values of the given type and data.
The element type needs to be a 1/2/4/8-byte integer or a half/bfloat/float/double type, of the same size as the elements of data, whose bits are used as-is.
LLVM.ConstantDataArray — Method
ConstantDataArray(data::AbstractVector)Create a constant array of simple data values from a Julia vector.
LLVM.isstring — Function
isstring(val::Value)Check whether the given value is a constant string, i.e., a constant array of i8 values, like C++'s ConstantDataSequential::isString. Its contents can be retrieved using String.
Core.String — Method
String(str::ConstantDataArray)Get the contents of a constant string, like C++'s ConstantDataSequential::getAsString. This includes all NUL characters, e.g., the one that terminates a C string. Throws an ArgumentError if the array is not a string; see isstring.
LLVM.ConstantDataVector — Type
ConstantDataVector <: LLVM.ConstantDataSequentialA constant vector of simple data values, i.e., whose element type is a simple 1/2/4/8-byte integer or half/bfloat/float/double, and whose elements are just simple data values. Its elements are available as the elements property, see LLVM.ConstantAggregate.
LLVM.ConstantArray — Type
ConstantArray <: LLVM.ConstantAggregateA constant array of values. Its elements are available as the elements property, see LLVM.ConstantAggregate.
LLVM.ConstantArray — Method
ConstantArray(typ::LLVMType, data::AbstractArray)Create a constant array of values of the given type and data.
When using simple data types, this constructor can also return a ConstantDataArray.
LLVM.ConstantArray — Method
ConstantArray(data::AbstractArray)Create a constant array of values from a Julia array, using the appropriate constant type.
LLVM.ConstantVector — Type
ConstantVector <: LLVM.ConstantAggregateA constant vector of other constants, which LLVM creates for vectors whose elements aren't simple data values (see ConstantDataVector). Its elements are available as the elements property, see LLVM.ConstantAggregate.
LLVM.ConstantAggregateZero — Type
ConstantAggregateZero <: LLVM.ConstantDataThe zeroinitializer of an array, structure or vector type, as created by null or by LLVM for aggregates whose elements are all zero. Its elements are available as the elements property, see LLVM.ConstantAggregate.
LLVM.ConstantAggregate — Type
LLVM.ConstantAggregate <: LLVM.ConstantAbstract supertype of constant arrays, structs and vectors whose elements are other constants: ConstantArray, ConstantStruct and ConstantVector.
Properties
c.elementsThe elements of an aggregate constant, as a read-only vector of constants, e.g., i32 2 for the second element of [3 x i32] [i32 1, i32 2, i32 3]. This property is also available for arrays and vectors of simple data (ConstantDataArray and ConstantDataVector) and for zeroinitializer (ConstantAggregateZero), which LLVM uses to represent aggregate constants whose elements are simple data or zero. Nested aggregates are elements themselves, i.e., the elements of a constant of type [2 x [2 x i32]] are two constants of type [2 x i32].
LLVM.InlineAsm — Type
InlineAsm <: LLVM.ConstantA constant inline assembly block.
LLVM.BlockAddress — Type
BlockAddress <: LLVM.ConstantThe address of a basic block, blockaddress(@f, %bb) in LLVM IR, e.g., as the destination of an indirectbr instruction.
Properties
ba.functionThe function that contains the basic block.
ba.blockThe basic block whose address this is.
LLVM.BlockAddress — Method
BlockAddress(bb::BasicBlock)Get the address of the basic block bb, which must be part of a function. Taking the address of the entry block of a function is not valid IR.
LLVM.ConstantTokenNone — Type
ConstantTokenNone <: LLVM.ConstantDataThe none token, e.g., the parent pad of a cleanuppad or catchswitch instruction that is not nested in another pad. It is the null value of the token type, so it is created using null(LLVM.TokenType()).
LLVM.ConstantTargetNone — Type
ConstantTargetNone <: LLVM.ConstantDataThe zeroinitializer of a target extension type (e.g., target("spirv.Event")), which only exists on LLVM 16 and later.
LLVM.ConstantPtrAuth — Type
ConstantPtrAuth <: LLVM.ConstantA signed pointer, ptrauth (ptr @f, i32 0) in LLVM IR, as used for pointer authentication (e.g., on arm64e). This constant only exists on LLVM 19 and later.
LLVM.convert_users_to_instructions! — Function
convert_users_to_instructions!(consts::AbstractVector{<:Constant};
func::Union{Nothing,LLVM.Function}=nothing,
remove_dead_constants::Bool=true,
include_self::Bool=false) -> BoolRewrite every constant expression or constant aggregate that (transitively) uses one of consts into equivalent instructions at each point of use; phi operands are materialized in their incoming block. Returns whether anything changed.
Optionally restrict the rewrite to func, keep dead constants around (remove_dead_constants=false), or also convert the passed constants themselves (include_self=true). These three options require LLVM 19 or later; the function itself requires LLVM 17 or later.
LLVM.remove_dead_constant_users! — Function
remove_dead_constant_users!(c::Constant)Remove the constants that use c, directly or transitively, but are not used themselves, like C++'s Constant::removeDeadConstantUsers. These are, e.g., constant expressions that remain after replacing or erasing the instructions that used them, and that keep c from being unused. c itself is not removed. Returns c.
Constant expressions
LLVM.ConstantExpr — Type
LLVM.ConstantExpr <: LLVM.ConstantA constant value that is initialized with an expression using other constant values.
Constant expressions are created using const_-prefixed functions, which correspond to the LLVM IR instructions: const_neg, const_not, etc.
Properties
ce.opcodeThe opcode of the constant expression, e.g., LLVM.Opcode.Add.
ce.source_element_typeThe type that a getelementptr constant expression indexes into. Throws an ArgumentError for other constant expressions.
ce.indicesThe indices of a getelementptr constant expression, i.e., its operands after the pointer, as a read-only view. Throws an ArgumentError for other constant expressions.
LLVM.const_add — Function
const_add(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression add of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_addrspacecast — Function
const_addrspacecast(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a addrspacecast. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_bitcast — Function
const_bitcast(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a bitcast. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_extractelement — Function
const_extractelement(vec::Constant, index::Constant) -> ConstantCreate the constant expression extractelement of the element at the 0-based index of vec. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_fcmp — Function
const_icmp(predicate::LLVM.IntPredicate.T, lhs::Constant, rhs::Constant)
-> Constant
const_fcmp(predicate::LLVM.RealPredicate.T, lhs::Constant, rhs::Constant)
-> ConstantCreate the constant expression icmp or fcmp that compares lhs and rhs using predicate. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_gep — Function
const_gep(type::LLVMType, ptr::Constant, indices::AbstractVector{<:Constant})
-> Constant
const_inbounds_gep(type::LLVMType, ptr::Constant,
indices::AbstractVector{<:Constant}) -> ConstantCreate the constant expression getelementptr (or getelementptr inbounds) that computes the address of an element of the value of type at ptr, using the 0-based indices. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_icmp — Function
const_icmp(predicate::LLVM.IntPredicate.T, lhs::Constant, rhs::Constant)
-> Constant
const_fcmp(predicate::LLVM.RealPredicate.T, lhs::Constant, rhs::Constant)
-> ConstantCreate the constant expression icmp or fcmp that compares lhs and rhs using predicate. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_inbounds_gep — Function
const_gep(type::LLVMType, ptr::Constant, indices::AbstractVector{<:Constant})
-> Constant
const_inbounds_gep(type::LLVMType, ptr::Constant,
indices::AbstractVector{<:Constant}) -> ConstantCreate the constant expression getelementptr (or getelementptr inbounds) that computes the address of an element of the value of type at ptr, using the 0-based indices. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_insertelement — Function
const_insertelement(vec::Constant, elt::Value, index::Constant) -> ConstantCreate the constant expression insertelement that replaces the element at the 0-based index of vec by elt. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_inttoptr — Function
const_inttoptr(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a inttoptr. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_mul — Function
const_mul(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression mul of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_neg — Function
const_neg(val::Constant) -> ConstantCreate the constant expression sub 0, val. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_not — Function
const_not(val::Constant) -> ConstantCreate the constant expression xor val, -1. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nswadd — Function
const_nswadd(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression add nsw of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nswmul — Function
const_nswmul(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression mul nsw of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nswneg — Function
const_nswneg(val::Constant) -> ConstantCreate the constant expression sub nsw 0, val. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nswsub — Function
const_nswsub(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression sub nsw of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nuwadd — Function
const_nuwadd(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression add nuw of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nuwmul — Function
const_nuwmul(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression mul nuw of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_nuwsub — Function
const_nuwsub(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression sub nuw of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_pointercast — Function
const_pointercast(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a pointer cast (bitcast, addrspacecast or ptrtoint). LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_ptrtoint — Function
const_ptrtoint(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a ptrtoint. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_shl — Function
const_shl(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression shl of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_shufflevector — Function
const_shufflevector(v1::Constant, v2::Constant, mask::Constant) -> ConstantCreate the constant expression shufflevector of v1 and v2, using the constant vector mask. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_splat — Method
const_splat(typ::LLVM.VectorType, value::Constant)
const_splat(typ::LLVM.VectorType, value::Real)Create a constant vector of type typ whose elements are all value, which must be a constant of the element type of typ, or a Julia number that is converted to one: using ConstantFP for a vector of floating-point values, or ConstantInt for a vector of integers, which requires an Integer. For example, to create a vector of floating-point ones:
const_splat(LLVM.VectorType(LLVM.FloatType(), 4), 1)The result is the constant that LLVM uses to represent the splat, e.g., a ConstantDataVector, or a ConstantAggregateZero for zeros, so it is only guaranteed to be a Constant.
LLVM.const_sub — Function
const_sub(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression sub of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_trunc — Function
const_trunc(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a trunc. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_truncorbitcast — Function
const_truncorbitcast(val::Constant, dest_type::LLVMType) -> ConstantCreate the constant expression that converts val to dest_type using a trunc (or bitcast, if the types have the same size). LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
LLVM.const_type! — Method
const_type!(builder::DIBuilder, type::DIType) -> DIDerivedTypeCreate a const-qualified type. Shorthand for qualified_type!(builder, DW_TAG_const_type, type).
LLVM.const_xor — Function
const_xor(lhs::Constant, rhs::Constant) -> ConstantCreate the constant expression xor of lhs and rhs. LLVM folds the expression if it can, so the result is a Constant, not necessarily a ConstantExpr.
Global values
LLVM.GlobalValue — Type
LLVM.GlobalValue <: LLVM.ConstantAbstract supertype for all global values.
Properties
gv.parentThe module that contains the global value.
gv.global_value_typeThe type of the global value.
This differs from the value_type property in that it is the type of the contained value, not the type of the global value itself, which is always a pointer type.
gv.linkage
gv.linkage = linkage::LLVM.Linkage.TThe linkage of the global value.
gv.section
gv.section = section::AbstractStringThe section of the global value, or an empty string if it isn't placed in a specific section. Only global objects (functions, global variables and ifuncs) can be assigned a section: the section of an alias is that of its aliasee, and cannot be changed.
gv.visibility
gv.visibility = visibility::LLVM.Visibility.TThe visibility of the global value.
gv.dllstorage
gv.dllstorage = storage::LLVM.DLLStorageClass.TThe DLL storage class of the global value.
gv.unnamed_addr
gv.unnamed_addr = kind::LLVM.UnnamedAddr.TWhether the address of the global value is significant: LLVM.UnnamedAddr.No if it is, LLVM.UnnamedAddr.Local if it is insignificant within the module (local_unnamed_addr), and LLVM.UnnamedAddr.Global if it is insignificant altogether (unnamed_addr), which allows merging it with other constants that have the same initializer.
LLVM.GlobalObject — Type
LLVM.GlobalObject <: LLVM.GlobalValueAbstract supertype for global values that are backed by an actual object in memory, i.e., functions, global variables and ifuncs, but not aliases.
Properties
inst.metadata
gv.metadataThe metadata attached to an instruction or a global object (a function or global variable), as a dictionary-like view that maps the kind of metadata to a metadata node. The kind can be an MDKind, like LLVM.MD_dbg, or the name of the kind, like "tbaa". The view can be iterated (in the case of an instruction, this includes its debug location), and is mutable: assign to a kind to attach metadata, e.g., inst.metadata["tbaa"] = node, and use delete! to remove it.
The properties of GlobalValue, User and Value are available too.
LLVM.isdeclaration — Function
isdeclaration(val::LLVM.GlobalValue)Check if the global value is a declaration, i.e. it does not have a definition.
Global variables
Global variables are a specific kind of global values, and have additional APIs:
LLVM.GlobalVariable — Type
GlobalVariable <: LLVM.GlobalObjectA global variable.
Properties
gv.initializer
gv.initializer = val::Union{LLVM.Constant,Nothing}The initializer of the global variable, or nothing if it has none (i.e., if it is a declaration). Assigning nothing removes the current initializer.
gv.threadlocal
gv.threadlocal = flag::BoolWhether the global variable is thread-local. This is a view of the threadlocal_mode property: assigning true to a variable that is not thread-local selects the general dynamic model, while assigning false makes the variable not thread-local. Assigning the current value does not change the thread-local mode.
gv.constant
gv.constant = flag::BoolWhether the global variable is a global constant, i.e., whether its value is immutable throughout the runtime execution of the program.
This differs from isconstant(gv), which checks whether a value is an LLVM constant, and is true for every global variable (which represents a constant address).
gv.threadlocal_mode
gv.threadlocal_mode = mode::LLVM.ThreadLocalMode.TThe thread-local storage model of the global variable, e.g., LLVM.ThreadLocalMode.GeneralDynamic, or LLVM.ThreadLocalMode.NotThreadLocal if it is not thread-local. See also the threadlocal property.
gv.externally_initialized
gv.externally_initialized = flag::BoolWhether the global variable is externally initialized, i.e., whether its value may be changed before the program starts running, so that optimizations cannot rely on its initializer.
gv.alignment
gv.alignment = bytes::IntegerThe alignment of the global variable in bytes, or 0 if it has no explicit alignment. The assigned alignment must be a power of 2, or 0 to remove the explicit alignment.
gv.next
gv.prevThe next or previous global variable in the module, or nothing if there is none.
The properties of GlobalObject, GlobalValue, User and Value are available too.
LLVM.erase! — Method
erase!(gv::GlobalVariable)Remove the global variable from its parent module and delete it.
Global variables are reordered using move!.
Global aliases
LLVM.GlobalAlias — Type
GlobalAlias <: LLVM.GlobalValueA global alias, i.e., a new symbol for an existing global value or constant expression.
Properties
alias.aliasee
alias.aliasee = val::LLVM.ConstantThe value that the global alias refers to. The type of an assigned value must match that of the alias.
alias.next
alias.prevThe next or previous global alias in the module, or nothing if there is none.
The properties of GlobalValue, User and Value are available too.
Global ifuncs
LLVM.GlobalIFunc — Type
GlobalIFunc <: LLVM.GlobalObjectAn indirect function, whose address is determined at load time by calling a resolver function.
Properties
ifunc.resolver
ifunc.resolver = val::LLVM.ConstantThe resolver of the ifunc. The type of an assigned value must be a pointer in the address space of the ifunc.
ifunc.next
ifunc.prevThe next or previous ifunc in the module, or nothing if there is none.
The properties of GlobalObject, GlobalValue, User and Value are available too.
LLVM.erase! — Method
erase!(ifunc::GlobalIFunc)Remove the ifunc from its parent module and delete it.
Uses
LLVM.replace_uses! — Function
replace_uses!(old::LLVM.Value, new::LLVM.Value)Replace all uses of an old value in the IR with new.
This does not replace uses in metadata, which must be done separately with replace_metadata_uses!.
LLVM.replace_metadata_uses! — Function
replace_metadata_uses!(old::LLVM.Value, new::LLVM.Value)Replace all uses of an old value in metadata with new. Before LLVM 18, the values need to have the same type, unless both are global values (e.g., when replacing a function by one with another signature, using typed pointers).