Struct llvm_lib::core::values::ValueRef

source ·
pub struct ValueRef(/* private fields */);
Expand description

LLVM Value wrapper

Implementations§

source§

impl ValueRef

source

pub fn const_string_in_context( context: &ContextRef, string: &str, dont_null_terminate: bool, ) -> Self

Create a ConstantDataSequential and initialize it with a string.

§Details

Creates a constant string value in a specified LLVM context.

This function wraps the LLVMConstStringInContext function from the LLVM core library. It generates a constant string value within the specified LLVM context (context) using the provided string slice (string). The function also allows you to specify whether the string should be null-terminated.

§Parameters
  • context: A reference to the LLVM context (ContextRef) in which the constant string should be created.
  • string: A string slice that represents the content of the constant string. This string will be used to generate the LLVM constant.
  • dont_null_terminate: A boolean value indicating whether the string should not be null-terminated. If true, the string will not be null-terminated; if false, a null terminator will be added.
§Returns

Returns an instance of ValueRef, which encapsulates the constant string value created in the specified context.

source

pub fn const_string(string: &str, dont_null_terminate: bool) -> Self

Create a ConstantDataSequential with string content in the global context.

This is the same as const_string_in_context except it operates on the global context.

§Details

Creates a constant string value in the global LLVM context.

This function wraps the LLVMConstString function from the LLVM core library. It generates a constant string value within the global LLVM context using the provided string slice (string). The function also allows you to specify whether the string should be null-terminated. This function is similar to const_string_in_context, but it operates on the global context instead of a specified context.

§Parameters
  • string: A string slice that represents the content of the constant string. This string will be used to generate the LLVM constant.
  • dont_null_terminate: A boolean value indicating whether the string should not be null-terminated. If true, the string will not be null-terminated; if false, a null terminator will be added.
§Returns

Returns an instance of ValueRef, which encapsulates the constant string value created in the global context.

source

pub fn is_constant_string(&self) -> bool

Returns true if the specified constant is an array of i8.

§Details

Checks if the value is a constant string.

This function wraps the LLVMIsConstantString function from the LLVM core library. It determines whether the value represented by self is a constant string. This is useful when you need to verify if a particular LLVM value is a constant string within the IR.

§Returns

Returns true if the value is a constant string, otherwise returns false.

source

pub fn get_as_string(&self) -> Option<String>

Get the given constant data sequential as a string.

§Details

Retrieves the value as a string if the value is a constant string.

This function wraps the LLVMGetAsString function from the LLVM core library. It attempts to extract the value represented by self as a string if it is a constant string. The function returns None if the value is not a constant string, or Some(String) containing the string representation if it is.

§Returns

Returns an Option<String>:

  • Some(String) containing the string representation of the constant if it is a constant string.
  • None if the value is not a constant string.
source

pub fn const_struct_in_context( context: &ContextRef, constant_vals: &[Self], packed: bool, ) -> Self

Create an anonymous ConstantStruct with the specified values.

§Details

Creates a constant struct value in a specified LLVM context.

This function wraps the LLVMConstStructInContext function from the LLVM core library. It generates a constant struct value within the specified LLVM context (context) using an array of constant values (constant_vals). The packed parameter allows you to specify whether the struct should be packed, meaning that its fields are laid out without padding.

§Parameters
  • context: A reference to the LLVM context (ContextRef) in which the constant struct should be created.
  • constant_vals: A slice of constant values (&[Self]) that will be used as the fields of the struct. Each element in this slice corresponds to a field in the struct.
  • packed: A boolean value indicating whether the struct should be packed (true for packed, false for unpacked). A packed struct has its fields tightly packed without padding.
§Returns

Returns an instance of ValueRef, which encapsulates the constant struct value created in the specified context.

source

pub fn const_struct(constant_vals: &[Self], packed: bool) -> Self

Create a ConstantStruct in the global Context.

This is the same as constStruct_in_context except it operates on the global context.

§Details

Creates a constant struct value in the global LLVM context.

This function wraps the LLVMConstStruct function from the LLVM core library. It generates a constant struct value using an array of constant values (constant_vals). The packed parameter allows you to specify whether the struct should be packed, meaning that its fields are laid out without padding. This function operates in the global LLVM context, as opposed to a specific context.

§Parameters
  • constant_vals: A slice of constant values (&[Self]) that will be used as the fields of the struct. Each element in this slice corresponds to a field in the struct.
  • packed: A boolean value indicating whether the struct should be packed (true for packed, false for unpacked). A packed struct has its fields tightly packed without padding.
§Returns

Returns an instance of ValueRef, which encapsulates the constant struct value created in the global context.

source

pub fn const_array2(element_type: &TypeRef, constant_vals: &[Self]) -> Self

Create a ConstantArray from values.

§Details

Creates a constant array value with elements of a specified type.

This function wraps the LLVMConstArray2 function from the LLVM core library. It generates a constant array value with the specified element type (element_type) using an array of constant values (constant_vals). Each element in constant_vals must be of the same type as element_type.

§Parameters
  • element_type: A reference to the type of elements in the array (TypeRef). This specifies the type that each element in the array should have.
  • constant_vals: A slice of constant values (&[Self]) that will be used as the elements of the array. Each element in this slice corresponds to an element in the resulting array.
§Returns

Returns an instance of ValueRef, which encapsulates the constant array value created with the specified element type and elements.

source

pub fn const_named_struct(struct_type: &TypeRef, constant_vals: &[Self]) -> Self

Create a non-anonymous ConstantStruct from values.

§Details

Creates a constant named struct value with specified field values.

This function wraps the LLVMConstNamedStruct function from the LLVM core library. It generates a constant struct value of the specified named struct type (struct_type) using an array of constant values (constant_vals). Each element in constant_vals corresponds to a field in the struct.

§Parameters
  • struct_type: A reference to the named struct type (TypeRef) for the constant value. This type specifies the structure that the constant will represent.
  • constant_vals: A slice of constant values (&[Self]) that will be used as the fields of the struct. Each element in this slice corresponds to a field in the struct.
§Returns

Returns an instance of ValueRef, which encapsulates the constant named struct value created with the specified fields.

source

pub fn get_aggregate_element(&self, idx: u32) -> Option<Self>

Get element of a constant aggregate (struct, array or vector) at the specified index. Returns None if the index is out of range, or it’s not possible to determine the element (e.g., because the constant is a constant expression.)

§Details

Retrieves a specific element from an aggregate constant (e.g., an array or struct).

This function wraps the LLVMGetAggregateElement function from the LLVM core library. It returns the element at the specified index (idx) from the aggregate constant represented by self. If the index is out of bounds or the element cannot be retrieved, the function returns None.

§Parameters
  • idx: The index of the element to retrieve from the aggregate constant. This index should be within the bounds of the aggregate’s elements.
§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) containing the retrieved element if the index is valid and the element is found.
  • None if the index is out of bounds or the element cannot be retrieved.
source

pub fn const_vector(scalar_constant_vals: &[Self]) -> Self

Create a ConstantVector from values.

§Details

Creates a constant vector value from an array of scalar constant values.

This function wraps the LLVMConstVector function from the LLVM core library. It generates a constant vector using the provided array of scalar constant values (scalar_constant_vals). Each element in the array corresponds to an element in the resulting vector, and the type of the vector is inferred from the types of the scalar constants.

§Parameters
  • scalar_constant_vals: A slice of scalar constant values (&[Self]) that will be used as the elements of the vector. Each element in this slice corresponds to an element in the resulting vector.
§Returns

Returns an instance of ValueRef, which encapsulates the constant vector value created from the specified scalar constants.

source§

impl ValueRef

source

pub fn get_const_opcode(&self) -> Opcode

Get the opcode for a constant value.

§Details

Retrieves the opcode of a constant expression.

This function wraps the LLVMGetConstOpcode function from the LLVM core library, which returns the opcode (operation code) for a constant expression. The opcode indicates the specific operation that the constant expression represents, such as addition, multiplication, etc.

§Returns

Returns an Opcode enum value that represents the opcode of the constant expression. The Opcode enum provides a Rust-friendly abstraction over the raw opcode value returned by LLVM.

source

pub fn align_of(ty: &TypeRef) -> Self

Obtain the alignment of the specified type.

§Details

Creates a new constant integer value representing the alignment, in bytes, of a given type.

This function wraps the LLVMAlignOf function from the LLVM core library, which returns the alignment of the provided type in bytes as a constant integer value. Alignment is the byte boundary that the type must adhere to in memory, and understanding it is important for certain low-level operations.

§Arguments
  • ty - A reference to the TypeRef representing the type whose alignment is being queried.
§Returns

Returns a new constant integer value representing the alignment of the specified type in bytes.

source

pub fn size_of(ty: &TypeRef) -> Self

Obtain the size of the specified type.

§Details

Creates a new constant integer value representing the size, in bytes, of a given type.

This function wraps the LLVMSizeOf function from the LLVM core library, which returns the size of the provided type in bytes as a constant integer value. This can be useful for operations that require knowledge of the memory footprint of a particular type.

§Arguments
  • ty - A reference to the TypeRef representing the type whose size is being queried.
§Returns

Returns a new constant integer value representing the size of the specified type in bytes.

source

pub fn const_neg(&self) -> Self

Create a negation operation on a constant value.

§Details

Creates a new constant integer value representing the arithmetic negation of the original value.

This function wraps the LLVMConstNeg function from the LLVM core library, which computes the negation of the given constant value (-self).

§Returns

Returns a new constant integer value representing the result of the negation operation (-self).

source

pub fn const_nsw_neg(&self) -> Self

Create a NSW negation operation on a constant value.

§Details

Creates a new constant integer value representing the arithmetic negation of the original value with the nsw (No Signed Wrap) flag set.

The nsw flag indicates that signed overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen.

§Returns

Returns a new constant integer value representing the result of the negation operation (-self) with the nsw flag set.

source

pub fn const_nuw_neg(&self) -> Self

Create a NUW negation operation on a constant value.

§Details

Creates a new constant integer value representing the arithmetic negation of the original value, with the nuw (No Unsigned Wrap) flag set.

The nuw flag indicates that unsigned overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen during the negation operation.

§Returns

Returns a new constant integer value representing the result of the negation operation (-self) with the nuw flag set.

source

pub fn const_not(&self) -> Self

Create a logical NOT operation on a constant value.

§Details

Creates a new constant integer value representing the bitwise negation (NOT) of the original value.

This function wraps the LLVMConstNot function from the LLVM core library, which computes the bitwise complement of the given constant integer value (~self). The result is a new constant where each bit of the original value is inverted (i.e., 0 becomes 1 and 1 becomes 0).

§Returns

Returns a new constant integer value representing the result of the bitwise NOT operation (~self).

source

pub fn const_add(lhs: &Self, rhs: &Self) -> Self

Create an addition operation on two constant values.

§Details

Creates a new constant integer value representing the addition of two constant integer values.

This function wraps the LLVMConstAdd function from the LLVM core library, which performs the addition of two constant integer values and returns the result as a new constant value.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the sum of lhs and rhs.

source

pub fn const_nsw_add(lhs: &Self, rhs: &Self) -> Self

Create a NSW (No Signed Wrap) addition operation on two constant values.

§Details

Creates a new constant integer value representing the addition of two constant integer values, with the nsw (No Signed Wrap) flag set.

This function wraps the LLVMConstNSWAdd function from the LLVM core library, which performs the addition of two constant integer values and returns the result as a new constant value. The nsw flag indicates that signed overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the sum of lhs and rhs with the nsw flag set.

source

pub fn const_nuw_add(lhs: &Self, rhs: &Self) -> Self

Create a NUW (No Unsigned Wrap) addition operation on two constant values.

§Details

Creates a new constant integer value representing the addition of two constant integer values, with the nuw (No Unsigned Wrap) flag set.

This function wraps the LLVMConstNUWAdd function from the LLVM core library, which performs the addition of two constant integer values and returns the result as a new constant value. The nuw flag indicates that unsigned overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the sum of lhs and rhs with the nuw flag set.

source

pub fn const_sub(lhs: &Self, rhs: &Self) -> Self

Create a subtraction operation on two constant values.

§Details

Creates a new constant integer value representing the subtraction of two constant integer values.

This function wraps the LLVMConstSub function from the LLVM core library, which performs the subtraction of the right-hand side (RHS) constant integer value from the left-hand side (LHS) constant integer value and returns the result as a new constant value.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the result of subtracting rhs from lhs.

source

pub fn const_nsw_sub(lhs: &Self, rhs: &Self) -> Self

Create a NSW (No Signed Wrap) subtraction operation on two constant values.

§Details

Creates a new constant integer value representing the subtraction of two constant integer values, with the nsw (No Signed Wrap) flag set.

This function wraps the LLVMConstNSWSub function from the LLVM core library, which performs the subtraction of the right-hand side (RHS) constant integer value from the left-hand side (LHS) constant integer value and returns the result as a new constant value. The nsw flag indicates that signed overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen during the subtraction.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the result of subtracting rhs from lhs with the nsw flag set.

source

pub fn const_nuw_sub(lhs: &Self, rhs: &Self) -> Self

Create a NUW (No Unsigned Wrap) subtraction operation on two constant values.

§Details

Creates a new constant integer value representing the subtraction of two constant integer values, with the nuw (No Unsigned Wrap) flag set.

This function wraps the LLVMConstNUWSub function from the LLVM core library, which performs the subtraction of the right-hand side (RHS) constant integer value from the left-hand side (LHS) constant integer value and returns the result as a new constant value. The nuw flag indicates that unsigned overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen during the subtraction.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the result of subtracting rhs from lhs with the nuw flag set.

source

pub fn const_mul(lhs: &Self, rhs: &Self) -> Self

Create a multiplication operation on two constant values.

§Details

Creates a new constant integer value representing the multiplication of two constant integer values.

This function wraps the LLVMConstMul function from the LLVM core library, which performs the multiplication of two constant integer values and returns the result as a new constant value.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the product of lhs and rhs.

source

pub fn const_nsw_mul(lhs: &Self, rhs: &Self) -> Self

Create a NSW (No Signed Wrap) multiplication operation on two constant values.

§Details

Creates a new constant integer value representing the multiplication of two constant integer values, with the nsw (No Signed Wrap) flag set.

This function wraps the LLVMConstNSWMul function from the LLVM core library, which performs the multiplication of two constant integer values and returns the result as a new constant value. The nsw flag indicates that signed overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen during the multiplication.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the product of lhs and rhs with the nsw flag set.

source

pub fn const_nuw_mul(lhs: &Self, rhs: &Self) -> Self

Create a NUW (No Unsigned Wrap) multiplication operation on two constant values.

§Details

Creates a new constant integer value representing the multiplication of two constant integer values, with the nuw (No Unsigned Wrap) flag set.

This function wraps the LLVMConstNUWMul function from the LLVM core library, which performs the multiplication of two constant integer values and returns the result as a new constant value. The nuw flag indicates that unsigned overflow is not allowed, and if it occurs, the program’s behavior will be undefined. This allows LLVM to optimize the code under the assumption that overflow does not happen during the multiplication.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the product of lhs and rhs with the nuw flag set.

source

pub fn const_xor(lhs: &Self, rhs: &Self) -> Self

Create a logical XOR operation on two constant values.

§Details

Creates a new constant integer value representing the bitwise XOR (exclusive OR) of two constant integer values.

This function wraps the LLVMConstXor function from the LLVM core library, which performs the bitwise XOR operation between two constant integer values and returns the result as a new constant value. The XOR operation compares each corresponding bit of the two values, setting the resulting bit to 1 if the bits differ, and to 0 if they are the same.

§Arguments
  • lhs - A reference to the left-hand side (LHS) constant integer value.
  • rhs - A reference to the right-hand side (RHS) constant integer value.
§Returns

Returns a new constant integer value representing the result of the bitwise XOR operation between lhs and rhs.

source

pub fn const_icmp(predicate: IntPredicate, lhs: &Self, rhs: &Self) -> Self

Create an integer comparison operation on two constant values.

§Details

Performs a constant integer comparison between two values using a specified comparison predicate.

This function is a wrapper around the LLVMConstICmp function from the LLVM core library. It allows you to perform a comparison between two integer values (lhs and rhs) at compile time, returning a new value that represents the result of the comparison. The comparison is specified by the predicate, which determines the type of comparison to be made (e.g., equality, less than, greater than).

§Parameters
  • predicate: An instance of IntPredicate that specifies the kind of comparison to perform. This could be one of several variants like IntEQ (equal), IntNE (not equal), IntUGT (unsigned greater than), and others, depending on the type of integer comparison desired.
  • lhs: A reference to the left-hand side value (lhs) of the comparison. This is the first integer value to compare.
  • rhs: A reference to the right-hand side value (rhs) of the comparison. This is the second integer value to compare.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the comparison. The result is a constant value determined at compile time based on the specified predicate.

source

pub fn const_fcmp(predicate: RealPredicate, lhs: &Self, rhs: &Self) -> Self

Create a floating-point comparison operation on two constant values.

§Details

Performs a constant floating-point comparison between two values using a specified comparison predicate.

This function is a wrapper around the LLVMConstFCmp function from the LLVM core library. It allows you to perform a comparison between two floating-point values (lhs and rhs) at compile time, returning a new value that represents the result of the comparison. The comparison is specified by the predicate, which determines the type of comparison to be made (e.g., equal to, less than, greater than).

§Parameters
  • predicate: An instance of RealPredicate that specifies the kind of comparison to perform. This could be one of several variants like RealPredicate::RealOEQ (ordered and equal), RealPredicate::RealOLT (ordered and less than), RealPredicate::RealUGT (unordered and greater than), etc. The exact variant determines the nature of the floating-point comparison.
  • lhs: A reference to the left-hand side value (lhs) of the comparison. This is the first floating-point value to compare.
  • rhs: A reference to the right-hand side value (rhs) of the comparison. This is the second floating-point value to compare.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the comparison. The result is a constant value determined at compile time based on the specified predicate.

source

pub fn const_shl(lhs: &Self, rhs: &Self) -> Self

Create a left shift operation on two constant values.

§Details

Performs a constant bitwise left shift operation between two integer values.

This function is a wrapper around the LLVMConstShl function from the LLVM core library. It allows you to perform a left shift operation on two integer values (lhs and rhs) at compile time, returning a new value that represents the result of the shift. The left-hand side value (lhs) is shifted left by the number of bits specified by the right-hand side value (rhs).

§Parameters
  • lhs: A reference to the left-hand side value (lhs) of the shift operation. This is the integer value that will be shifted.
  • rhs: A reference to the right-hand side value (rhs) of the shift operation. This is the integer value that specifies the number of bits to shift.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the left shift operation. The result is a constant value determined at compile time based on shifting lhs to the left by rhs bits.

source

pub fn const_gep2( ty: &TypeRef, constant_val: &Self, constant_indices: &[Self], ) -> Self

Create a GEP (GetElementPtr) operation on a constant value.

§Details

Creates a constant GetElementPtr (GEP) instruction with an explicit type.

This function wraps the LLVMConstGEP2 function from the LLVM core library. It generates a constant GEP instruction, which calculates the address of a sub-element of an aggregate data structure (such as arrays or structs) at compile time. The GEP is calculated using the base pointer constant_val and the specified constant_indices.

§Parameters
  • ty: A reference to the type of the base pointer (constant_val). This specifies the type of the data structure from which the GEP is calculated.
  • constant_val: A reference to the base value from which the GEP is calculated. This is typically a pointer to an aggregate data structure.
  • constant_indices: A slice of references to constant values that represent the indices used in the GEP calculation.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the GEP calculation. The result is a constant value determined at compile time, representing the address of the sub-element within the aggregate data structure.

source

pub fn const_in_bounds_gep2( ty: &TypeRef, constant_val: &Self, constant_indices: &[Self], ) -> Self

Create an in-bounds GEP (GetElementPtr) operation on a constant value.

§Details

Creates a constant in-bounds GetElementPtr (GEP) instruction with an explicit type.

This function wraps the LLVMConstInBoundsGEP2 function from the LLVM core library. It generates a constant in-bounds GEP instruction, which calculates the address of a sub-element of an aggregate data structure (such as arrays or structs) at compile time. The in-bounds GEP ensures that the resulting address is within the bounds of the allocated object, allowing for more aggressive optimizations.

§Parameters
  • ty: A reference to the type of the base pointer (constant_val). This specifies the type of the data structure from which the GEP is calculated.
  • constant_val: A reference to the base value from which the GEP is calculated. This is typically a pointer to an aggregate data structure.
  • constant_indices: A slice of references to constant values that represent the indices used in the GEP calculation.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the in-bounds GEP calculation. The result is a constant value determined at compile time, representing the address of the sub-element within the aggregate data structure, with the guarantee that the address is within the bounds of the object.

source

pub fn const_trunc(&self, to_type: &TypeRef) -> Self

Truncate a constant value to the specified type.

§Details

Truncates a constant integer value to a smaller integer type.

This function wraps the LLVMConstTrunc function from the LLVM core library. It generates a constant truncation instruction, which reduces the bit width of the integer value represented by ValueRef to the bit width of the target type specified by to_type. This is typically used when you need to narrow a constant integer value to a smaller type at compile time.

§Parameters
  • to_type: A reference to the target type (TypeRef) to which the integer value should be truncated. This type must have a smaller bit width than the original integer type.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the truncation. The result is a constant value determined at compile time, representing the truncated integer value.

source

pub fn const_ptr_to_int(&self, to_type: &TypeRef) -> Self

Convert a constant pointer to an integer of the specified type.

§Details

Converts a constant pointer value to an integer of the specified type.

This function wraps the LLVMConstPtrToInt function from the LLVM core library. It generates a constant pointer-to-integer conversion, which interprets the pointer value represented by ValueRef as an integer of the type specified by to_type. This is commonly used in low-level programming to perform operations where a pointer needs to be treated as an integer at compile time.

§Parameters
  • to_type: A reference to the target integer type (TypeRef) to which the pointer value should be converted. This type specifies the bit width and signedness of the resulting integer.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the pointer-to-integer conversion. The result is a constant value determined at compile time, representing the integer interpretation of the pointer value.

source

pub fn const_int_to_ptr(&self, to_type: &TypeRef) -> Self

Convert a constant integer to a pointer of the specified type.

§Details

Converts a constant integer value to a pointer of the specified type.

This function wraps the LLVMConstIntToPtr function from the LLVM core library. It generates a constant integer-to-pointer conversion, which interprets the integer value represented by ValueRef as a pointer of the type specified by to_type. This is often used in low-level programming to perform operations where an integer needs to be treated as a pointer at compile time.

§Parameters
  • to_type: A reference to the target pointer type (TypeRef) to which the integer value should be converted. This type specifies the type of the pointer that the integer value will be interpreted as.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the integer-to-pointer conversion. The result is a constant value determined at compile time, representing the pointer interpretation of the integer value.

source

pub fn const_bit_cast(&self, to_type: &TypeRef) -> Self

Perform a bitcast operation on a constant value to the specified type.

§Details

Performs a constant bitcast of a value to another type without changing the bit representation.

This function wraps the LLVMConstBitCast function from the LLVM core library. It generates a constant bitcast instruction, which reinterprets the value represented by ValueRef as another type specified by to_type. The bitcast does not change the underlying bit representation of the value; it merely reinterprets it as a different type. This is typically used for converting between types of the same size, such as casting between integers and pointers or between different floating-point types.

§Parameters
  • to_type: A reference to the target type (TypeRef) to which the value should be cast. This type must have the same bit width as the original type.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the bitcast. The result is a constant value determined at compile time, representing the value reinterpreted as the target type.

source

pub fn const_addr_space_cast(&self, to_type: &TypeRef) -> Self

Perform an address space cast operation on a constant value to the specified type.

§Details

Casts a constant pointer value to a different address space.

This function wraps the LLVMConstAddrSpaceCast function from the LLVM core library. It generates a constant address space cast, which reinterprets the pointer value represented by ValueRef as a pointer in a different address space specified by to_type. This is commonly used in systems with multiple memory address spaces where pointers may need to be converted between them at compile time.

§Parameters
  • to_type: A reference to the target pointer type (TypeRef) that specifies the new address space. The type should have the same bit width as the original pointer type but reside in a different address space.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the address space cast. The result is a constant value determined at compile time, representing the pointer value in the new address space.

source

pub fn const_trunc_or_bit_cast(&self, to_type: &TypeRef) -> Self

Perform either a truncation or bitcast operation on a constant value to the specified type.

§Details

Performs a constant truncation or bitcast of a value to a specified type, depending on the target type’s bit width.

This function wraps the LLVMConstTruncOrBitCast function from the LLVM core library. It either truncates the value represented by ValueRef to a smaller integer type or performs a bitcast if the target type has the same bit width. The operation performed depends on the relationship between the original type and the target type’s bit width.

  • If the target type has a smaller bit width than the original type, a truncation is performed.
  • If the target type has the same bit width, a bitcast is performed, reinterpreting the value as the target type without changing its bit representation.
§Parameters
  • to_type: A reference to the target type (TypeRef) to which the value should be truncated or bitcast. The nature of the operation depends on the bit width of this type relative to the original type.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the truncation or bitcast. The result is a constant value determined at compile time, representing the value either truncated to a smaller type or reinterpreted as the target type.

source

pub fn const_pointer_cast(&self, to_type: &TypeRef) -> Self

Perform a pointer cast operation on a constant value to the specified type.

§Details

Casts a constant pointer value to a different pointer type without changing the address or bit representation.

This function wraps the LLVMConstPointerCast function from the LLVM core library. It generates a constant pointer cast, which reinterprets the pointer value represented by ValueRef as a different pointer type specified by to_type. The cast does not alter the underlying address or bit representation of the pointer; it simply changes the type of the pointer. This is typically used when you need to change the type of a pointer while preserving its address in memory.

§Parameters
  • to_type: A reference to the target pointer type (TypeRef) to which the pointer value should be cast. The target type must be a pointer type, but it may point to a different type than the original pointer.
§Returns

Returns an instance of ValueRef, which encapsulates the result of the pointer cast. The result is a constant value determined at compile time, representing the pointer value reinterpreted as the new type.

source

pub fn const_extract_element(&self, index: &Self) -> Self

Extract an element from a vector constant at the specified index.

§Details

Extracts a single element from a constant vector at a specified index.

This function wraps the LLVMConstExtractElement function from the LLVM core library. It generates a constant extract element instruction, which retrieves a specific element from the vector value represented by ValueRef at the position specified by index. This is commonly used when working with constant vectors, allowing you to extract a single element at compile time.

§Parameters
  • index: A reference to a constant value that specifies the index of the element to extract. The index should be an integer value and within the bounds of the vector.
§Returns

Returns an instance of ValueRef, which encapsulates the extracted element as a constant value determined at compile time.

source

pub fn const_insert_element(&self, element_value: &Self, index: &Self) -> Self

Insert an element into a vector constant at the specified index.

§Details

Inserts a constant element into a constant vector at a specified index.

This function wraps the LLVMConstInsertElement function from the LLVM core library. It generates a constant insert element instruction, which inserts the value represented by element_value into the vector value represented by ValueRef at the position specified by index. This is typically used to create or modify constant vectors by inserting elements at specific positions at compile time.

§Parameters
  • element_value: A reference to the constant value that should be inserted into the vector. This value must be of the same type as the elements of the vector.
  • index: A reference to a constant value that specifies the index at which the element should be inserted. The index should be an integer value and within the bounds of the vector.
§Returns

Returns an instance of ValueRef, which encapsulates the resulting vector after the insertion, as a constant value determined at compile time.

source

pub fn const_shuffle_vector( vector_a: &Self, vector_b: &Self, mask: &Self, ) -> Self

Create a shuffle vector operation on two vector constants.

§Details

Creates a constant shuffling of elements from two vectors according to a specified mask.

This function wraps the LLVMConstShuffleVector function from the LLVM core library. It generates a constant shuffle vector instruction, which produces a new vector by selecting elements from two input vectors, vector_a and vector_b, based on the indices specified by mask. The resulting vector is determined at compile time and is a permutation of elements from the original vectors according to the mask.

§Parameters
  • vector_a: A reference to the first input vector from which elements may be selected.
  • vector_b: A reference to the second input vector from which elements may be selected.
  • mask: A reference to a constant vector that specifies the indices of elements to select from vector_a and vector_b. The mask values determine which elements from the input vectors are placed in the resulting vector.
§Returns

Returns an instance of ValueRef, which encapsulates the resulting shuffled vector as a constant value determined at compile time.

source

pub fn block_address(function: &Self, basic_block: &BasicBlockRef) -> Self

Obtain the address of a basic block in a function.

§Details

Retrieves the address of a basic block within a specified function.

This function wraps the LLVMBlockAddress function from the LLVM core library. It generates a constant representing the address of a specific basic block within a given function. This is typically used for low-level operations such as creating labels or handling jumps within a function at compile time.

§Parameters
  • function: A reference to the function (ValueRef) that contains the basic block whose address is being retrieved.
  • basic_block: A reference to the basic block (BasicBlockRef) within the function whose address is to be retrieved.
§Returns

Returns an instance of ValueRef, which encapsulates the address of the specified basic block as a constant value determined at compile time.

source§

impl ValueRef

source

pub fn get_global_parent(&self) -> ModuleRef

Get the module that contains the global value.

§Details

Retrieves the parent module of a global value.

This function wraps the LLVMGetGlobalParent function from the LLVM core library. It returns the ModuleRef representing the parent module in which the global value represented by self is defined. The parent module contains all the global values (such as functions and global variables) that are part of a given LLVM module.

§Returns

Returns a ModuleRef representing the parent module of the global value.

source

pub fn is_declaration(&self) -> bool

Determine if the global value is a declaration.

§Details

Checks if the global value is a declaration.

This function wraps the LLVMIsDeclaration function from the LLVM core library. It determines whether the global value represented by self is merely a declaration (i.e., it declares the existence of a symbol but does not define it). Declarations are often used to reference functions or variables that are defined in another module or later in the same module.

§Returns

Returns true if the global value is a declaration, otherwise returns false.

source

pub fn get_linkage(&self) -> Linkage

Get the linkage of the global value.

§Details

Sets the linkage type for a global value.

This function wraps the LLVMSetLinkage function from the LLVM core library. It configures the linkage type for the global value represented by self. The linkage type determines how the symbol is treated during the linking process, particularly in relation to how it can be combined with other symbols and whether it is visible outside of the module.

§Parameters
  • linkage: A Linkage enum value that specifies the linkage type for the global value. Common linkage types include:
    • ExternalLinkage: The symbol is visible to other modules and can be linked against.
    • InternalLinkage: The symbol is only visible within the current module.
    • PrivateLinkage: The symbol is local to the file and not exposed to other modules.
    • LinkOnceODRLinkage: Ensures that the symbol is defined only once across all modules, complying with the One Definition Rule (ODR).
source

pub fn set_linkage(&self, linkage: Linkage)

Set the linkage of the global value.

§Details
source

pub fn get_section(&self) -> Option<String>

Get the section of the global value.

§Details

Retrieves the section name in which a global value is placed.

This function wraps the LLVMGetSection function from the LLVM core library. It returns the name of the section where the global value represented by self is placed. Sections are used to organize global values in the object file, allowing the linker and loader to place related values together or handle them in a specific way.

§Returns

Returns an Option<String>:

  • Some(String) containing the name of the section if the global value is placed in a specific section.
  • None if the global value is not associated with any section.
source

pub fn set_section(&self, section: &str)

Set the section of the global value.

§Details

Sets the section in which a global value should be placed.

This function wraps the LLVMSetSection function from the LLVM core library. It specifies the section name for the global value represented by self. Sections are used to organize global values in the object file, allowing the linker and loader to place related values together or handle them in a specific way.

§Parameters
  • section: A string slice (&str) representing the name of the section where the global value should be placed.
source

pub fn get_visibility(&self) -> Visibility

Get the visibility of the global value.

§Details

Retrieves the visibility attribute of a global value.

This function wraps the LLVMGetVisibility function from the LLVM core library. It returns the visibility attribute of the global value represented by self. The visibility attribute determines how the symbol is treated by the linker and whether it can be seen by other modules or shared libraries.

§Returns

Returns a Visibility enum value representing the visibility attribute of the global value:

  • DefaultVisibility: The symbol is visible to other modules.
  • HiddenVisibility: The symbol is not visible to other modules or shared libraries.
  • ProtectedVisibility: The symbol is visible to other modules but cannot be overridden.
source

pub fn set_visibility(&self, visibility: Visibility)

Set the visibility of the global value.

§Details

Sets the visibility attribute for a global value.

This function wraps the LLVMSetVisibility function from the LLVM core library. It configures the visibility attribute for the global value represented by self. The visibility attribute determines how the symbol is treated by the linker and whether it can be seen by other modules or shared libraries.

§Parameters
  • visibility: A Visibility enum value that specifies the visibility of the global value:
    • DefaultVisibility: The symbol is visible to other modules.
    • HiddenVisibility: The symbol is not visible to other modules or shared libraries.
    • ProtectedVisibility: The symbol is visible to other modules but cannot be overridden.
source

pub fn get_dll_storage_class(&self) -> DLLStorageClass

Get the DLL storage class of a global value.

§Details

Retrieves the DLL storage class of a global value.

This function wraps the LLVMGetDLLStorageClass function from the LLVM core library. It returns the DLLStorageClass of the global value represented by self. The DLL storage class determines how the global value is treated in relation to dynamic link libraries (DLLs) on platforms like Windows.

§Returns

Returns a DLLStorageClass enum value representing the DLL storage class of the global value:

  • DefaultStorageClass: The symbol is treated as a normal global symbol, not specifically marked for import or export from a DLL.
  • DLLImportStorageClass: The symbol is imported from a DLL.
  • DLLExportStorageClass: The symbol is exported to a DLL.
source

pub fn set_dll_storage_class(&self, class: DLLStorageClass)

Set the DLL storage class of a global value.

§Details

Sets the DLL storage class for a global value.

This function wraps the LLVMSetDLLStorageClass function from the LLVM core library. It configures the DLL storage class for the global value represented by self. The DLLStorageClass attribute determines how the global value is treated in relation to dynamic link libraries (DLLs) on platforms like Windows.

§Parameters
  • class: A DLLStorageClass enum value that specifies the DLL storage class for the global value.
    • DefaultStorageClass: The symbol is treated as a normal global symbol, not specifically marked for import or export from a DLL.
    • DLLImportStorageClass: The symbol is imported from a DLL.
    • DLLExportStorageClass: The symbol is exported to a DLL.
source

pub fn get_unnamed_address(&self) -> UnnamedAddr

Get the unnamed address of a global value.

§Details

Retrieves the unnamed address attribute of a global value.

This function wraps the LLVMGetUnnamedAddress function from the LLVM core library. It returns the UnnamedAddr attribute of the global value represented by self. This attribute specifies whether the address of the global value is significant, which can influence certain optimizations in LLVM.

§Returns

Returns an UnnamedAddr enum value representing the unnamed address attribute of the global value:

  • NoUnnamedAddr: The address of the global value is significant and must be unique.
  • LocalUnnamedAddr: The address is not significant within the module, allowing certain optimizations.
  • GlobalUnnamedAddr: The address is not significant across the entire program, enabling more aggressive optimizations.
source

pub fn set_unnamed_address(&self, unnamed_addr: UnnamedAddr)

Set the unnamed address of a global value.

§Details

Sets the unnamed address attribute for a global value.

This function wraps the LLVMSetUnnamedAddress function from the LLVM core library. It configures the unnamed address attribute for the global value represented by self. The UnnamedAddr attribute specifies whether the address of the global value is significant, which can influence certain optimizations in LLVM.

§Parameters
  • unnamed_addr: An UnnamedAddr enum value that specifies the unnamed address attribute for the global value.
    • NoUnnamedAddr: The address of the global value is significant and must be unique.
    • LocalUnnamedAddr: The address is not significant within the module, allowing certain optimizations.
    • GlobalUnnamedAddr: The address is not significant across the entire program, enabling more aggressive optimizations.
source

pub fn get_value_type(&self) -> TypeRef

Returns the “value type” of a global value. This differs from the formal type of a global value, which is always a pointer type.

§Details

Retrieves the type of the global value.

This function wraps the LLVMGlobalGetValueType function from the LLVM core library. It returns the TypeRef representing the type of the global value associated with self. Knowing the type of the global value is essential for understanding what kind of data it holds or operates on, as well as for performing type-specific operations or optimizations.

§Returns

Returns a TypeRef representing the type of the global value.

source

pub fn get_alignment(&self) -> u32

Obtain the preferred alignment of the value.

§Details

Retrieves the alignment of a global value in bytes.

This function wraps the LLVMGetAlignment function from the LLVM core library. It returns the alignment requirement of the global value represented by self, in terms of the number of bytes. Knowing the alignment can be useful for understanding how the global value is laid out in memory and ensuring that it meets the requirements of the target architecture.

§Returns

Returns a u32 representing the alignment of the global value in bytes.

source

pub fn set_alignment(&self, bytes: u32)

Set the preferred alignment of the value.

§Details

Sets the alignment for a global value in bytes.

This function wraps the LLVMSetAlignment function from the LLVM core library. It specifies the alignment requirement for the global value represented by self, in terms of the number of bytes. Proper alignment can be important for performance, particularly in low-level systems programming, where misaligned accesses can cause performance penalties or even hardware exceptions.

§Parameters
  • bytes: A u32 value representing the desired alignment in bytes. This value must be a power of two.
source

pub fn global_set_metadata(&self, kind: u32, md: &MetadataRef)

Sets a metadata attachment, erasing the existing metadata attachment if it already exists for the given kind.

§Details

Sets metadata of a specific kind for a global value.

This function wraps the LLVMGlobalSetMetadata function from the LLVM core library. It attaches metadata of the specified kind to the global value represented by self. If metadata of this kind already exists, it will be replaced with the new metadata provided. Metadata in LLVM is used to attach additional information to global values, such as functions or variables, which can be useful for debugging, optimization, or other purposes.

§Parameters
  • kind: A u32 representing the kind of metadata to be set. The kind ID specifies the category or type of the metadata.
  • md: A MetadataRef representing the metadata to be attached to the global value.
source

pub fn global_erase_metadata(&self, kind: u32)

Erases a metadata attachment of the given kind if it exists.

§Details

Erases metadata of a specific kind from a global value.

This function wraps the LLVMGlobalEraseMetadata function from the LLVM core library. It removes the metadata entry of the specified kind associated with the global value represented by self. If the global value has multiple metadata entries, only the entry matching the specified kind will be erased, leaving other metadata intact.

§Parameters
  • kind: A u32 representing the kind of metadata to be erased. The kind ID specifies the category or type of the metadata.
source

pub fn global_clear_metadata(&self)

Removes all metadata attachments from this value.

§Details

Clears all metadata attached to a global value.

This function wraps the LLVMGlobalClearMetadata function from the LLVM core library. It removes all metadata entries associated with the global value represented by self. This operation effectively detaches any metadata from the global value, which might be useful in scenarios where the metadata is no longer needed or should be reset.

source

pub fn dispose_value_metadata_entries(_entries: &[ValueMetadataEntry])

Destroys value metadata entries.

§Panics

This function is purely informative and panics with a message about the call being unavailable. Since there are no cases in which it can be called in safe code. For raw access, if there is such a need, must be called LLVMDisposeValueMetadataEntries directly.

source

pub fn global_copy_all_metadata(&self) -> Vec<ValueMetadataEntry>

Retrieves an array of metadata entries representing the metadata attached to this value.

§Details

Copies all metadata attached to a global value and returns it as a vector of ValueMetadataEntry.

This function wraps the LLVMGlobalCopyAllMetadata function from the LLVM core library. It retrieves all metadata entries associated with the global value represented by self and returns them as a vector of ValueMetadataEntry. Metadata in LLVM is used to attach additional information to various constructs, such as functions or global variables, which can be useful for debugging, optimization, or other purposes.

After copying the metadata entries, the function ensures that any allocated memory for the metadata entries is correctly freed by calling LLVMDisposeValueMetadataEntries.

§Returns

Returns a Vec<ValueMetadataEntry> containing all metadata entries attached to the global value. If no metadata is attached, an empty vector is returned.

source§

impl ValueRef

source

pub fn const_int(ty: &TypeRef, n: u64, sign_extend: bool) -> Self

Obtain a constant value for an integer type. The returned value corresponds to a llvm ConstantInt.

§Details

Creates a constant integer value of a specified type.

This function wraps the LLVMConstInt function from the LLVM core library. It generates a constant integer value of the type specified by ty, using the provided n as the value. The sign_extend parameter determines whether the value should be sign-extended to the specified type if the type is larger than the original value.

§Parameters
  • ty: A reference to the integer type (TypeRef) for the constant value. This specifies the bit width and signedness of the integer.
  • n: The integer value to be used for the constant. It will be interpreted according to the bit width and signedness of the target type.
  • sign_extend: A boolean value indicating whether the constant should be sign-extended to the target type. If true, the value will be sign-extended; if false, it will be zero-extended.
§Returns

Returns an instance of ValueRef, which encapsulates the constant integer value determined at compile time.

source

pub fn const_int_of_arbitrary_precision(ty: &TypeRef, words: &[u64]) -> Self

Obtain a constant value for an integer of arbitrary precision.

§Details

Creates a constant integer value of arbitrary precision.

This function wraps the LLVMConstIntOfArbitraryPrecision function from the LLVM core library. It generates a constant integer value of the specified type (ty) using an array of 64-bit words (words). This allows for the creation of integers that exceed the typical bit width limitations by providing multiple 64-bit words to represent the value.

§Parameters
  • ty: A reference to the integer type (TypeRef) for the constant value. This type specifies the bit width and signedness of the integer.
  • words: A slice of 64-bit words (u64) that represents the value of the constant integer. Each word in the array contributes to the overall bit representation of the integer, allowing for arbitrary precision.
§Returns

Returns an instance of ValueRef, which encapsulates the constant integer value with arbitrary precision, as determined at compile time.

source

pub fn const_int_of_string(ty: &TypeRef, text: &str, radix: u8) -> Self

Obtain a constant value for an integer parsed from a string.

A similar API, const_int_of_string_and_size is also available. If the string’s length is available, it is preferred to call that function instead.

§Details

Creates a constant integer value by parsing a string representation of the integer.

This function wraps the LLVMConstIntOfString function from the LLVM core library. It generates a constant integer value of the specified type (ty) by parsing the provided string (text) according to the specified radix (radix). This function is useful when you need to create constant integers from string literals in various bases (e.g., binary, octal, decimal, hexadecimal).

§Parameters
  • ty: A reference to the integer type (TypeRef) for the constant value. This type specifies the bit width and signedness of the integer.
  • text: A string slice that represents the integer value to be parsed. The string should be a valid representation of an integer in the specified radix.
  • radix: The radix (or base) used to interpret the string. Common values include 2 (binary), 8 (octal), 10 (decimal), and 16 (hexadecimal).
§Returns

Returns an instance of ValueRef, which encapsulates the constant integer value parsed from the string at compile time.

source

pub fn const_int_of_string_and_size(ty: &TypeRef, text: &str, radix: u8) -> Self

Obtain a constant value for an integer parsed from a string with specified length.

§Details

Creates a constant integer value by parsing a string representation of the integer, with a specified string length.

This function wraps the LLVMConstIntOfStringAndSize function from the LLVM core library. It generates a constant integer value of the specified type (ty) by parsing the provided string (text) according to the specified radix (radix). The length of the string is explicitly provided, which can be more efficient when the string length is known or can be easily determined, as it avoids the need for additional computation or checks.

§Parameters
  • ty: A reference to the integer type (TypeRef) for the constant value. This type specifies the bit width and signedness of the integer.
  • text: A string slice that represents the integer value to be parsed. The string should be a valid representation of an integer in the specified radix.
  • radix: The radix (or base) used to interpret the string. Common values include 2 (binary), 8 (octal), 10 (decimal), and 16 (hexadecimal).
§Returns

Returns an instance of ValueRef, which encapsulates the constant integer value parsed from the string at compile time.

§Efficiency

This function is recommended when the length of the string is known, as it may offer better performance compared to const_int_of_string by avoiding the overhead of calculating the string length within the function.

source

pub fn const_real(ty: &TypeRef, n: f64) -> Self

Obtain a constant value referring to a double floating point value.

§Details

Creates a constant floating-point value of a specified type.

This function wraps the LLVMConstReal function from the LLVM core library. It generates a constant floating-point value of the type specified by ty, using the provided floating-point number n. This is typically used to create floating-point constants within LLVM’s Intermediate Representation (IR) at compile time.

§Parameters
  • ty: A reference to the floating-point type (TypeRef) for the constant value. This type specifies the bit width of the floating-point value (e.g., f32, f64).
  • n: The floating-point value to be used for the constant. It will be interpreted according to the bit width of the target floating-point type.
§Returns

Returns an instance of ValueRef, which encapsulates the constant floating-point value determined at compile time.

source

pub fn const_real_of_string(ty: &TypeRef, text: &str) -> Self

Obtain a constant for a floating point value parsed from a string.

A similar API, const_real_of_string_and_size is also available. It should be used if the input string’s length is known.

§Details

Creates a constant floating-point value by parsing a string representation of the number.

This function wraps the LLVMConstRealOfString function from the LLVM core library. It generates a constant floating-point value of the specified type (ty) by parsing the provided string (text). This is useful when creating floating-point constants from string literals, especially when the value is specified in textual form rather than directly as a floating-point number.

§Parameters
  • ty: A reference to the floating-point type (TypeRef) for the constant value. This type specifies the bit width of the floating-point value (e.g., f32, f64).
  • text: A string slice that represents the floating-point value to be parsed. The string should be a valid representation of a floating-point number in the expected format.
§Returns

Returns an instance of ValueRef, which encapsulates the constant floating-point value parsed from the string at compile time.

source

pub fn const_real_of_string_and_size(ty: &TypeRef, text: &str) -> Self

Obtain a constant for a floating point value parsed from a string with specified length.

§Details

Creates a constant floating-point value by parsing a string representation of the number, with a specified string length.

This function wraps the LLVMConstRealOfStringAndSize function from the LLVM core library. It generates a constant floating-point value of the specified type (ty) by parsing the provided string (text) according to its length. This function is useful when the length of the input string is known, as it may provide better performance by avoiding the need to compute the string length internally.

§Parameters
  • ty: A reference to the floating-point type (TypeRef) for the constant value. This type specifies the bit width of the floating-point value (e.g., f32, f64).
  • text: A string slice that represents the floating-point value to be parsed. The string should be a valid representation of a floating-point number in the expected format.
§Returns

Returns an instance of ValueRef, which encapsulates the constant floating-point value parsed from the string at compile time.

§Efficiency

This function is recommended when the length of the string is known, as it may offer better performance compared to const_real_of_string by avoiding the overhead of calculating the string length within the function.

source

pub fn const_int_get_zext_value(&self) -> u64

Obtain the zero extended value for an integer constant value.

§Details

Retrieves the zero-extended value of a constant integer as a u64.

This function wraps the LLVMConstIntGetZExtValue function from the LLVM core library. It returns the value of the constant integer represented by self, zero-extending it to 64 bits if necessary. This is useful when you need to extract the numeric value of a constant integer in a form that can be used in regular Rust code.

§Returns

Returns a u64 that represents the zero-extended value of the constant integer.

source

pub fn const_int_get_sext_value(&self) -> i64

Obtain the sign extended value for an integer constant value.

§Details

Retrieves the sign-extended value of a constant integer as an i64.

This function wraps the LLVMConstIntGetSExtValue function from the LLVM core library. It returns the value of the constant integer represented by self, sign-extending it to 64 bits if necessary. This is useful when you need to extract the numeric value of a constant integer in a signed form that can be used in regular Rust code.

§Returns

Returns an i64 that represents the sign-extended value of the constant integer.

source

pub fn const_real_get_double(&self) -> (f64, bool)

Obtain the double value for a floating point constant value. losesInfo indicates if some precision was lost in the conversion.

§Details

Retrieves the double-precision floating-point value from a constant floating-point value.

This function wraps the LLVMConstRealGetDouble function from the LLVM core library. It extracts the value of the constant floating-point represented by self as an f64. The function also indicates if any precision was lost during the conversion by setting the losesInfo flag.

§Returns

Returns a tuple containing:

  • An f64 representing the double-precision floating-point value.
  • A bool flag (losesInfo) indicating whether some precision was lost in the conversion (true if precision was lost, false otherwise).
source§

impl ValueRef

source

pub fn type_of(&self) -> TypeRef

Obtain the type of the value.

§Details

Retrieves the LLVM type of the value.

This function wraps the LLVMTypeOf function from the LLVM core library. It returns the TypeRef representing the LLVM type of the value represented by self. This is useful for inspecting the type information of values within LLVM IR, such as determining whether a value is an integer, floating-point, pointer, or another type.

§Returns

Returns a TypeRef that represents the LLVM type of the value.

source

pub fn get_value_kind(&self) -> ValueKind

Returns the kind of the given LLVM value (Obtain the enumerated type of the Value instance.).

§Details

Retrieves the kind of value represented by this LLVM value.

This function wraps the LLVMGetValueKind function from the LLVM core library. It returns a ValueKind enumeration that identifies the specific kind of the value, such as whether it is an instruction, a constant, a global variable, a function, etc. This is useful for understanding what kind of entity a value represents within the LLVM IR.

§Returns

Returns a ValueKind enumeration that represents the kind of the value.

source

pub fn get_value_name(&self) -> Option<String>

Obtain the string name of a value.

§Details

Retrieves the name of the LLVM value, if it has one.

This function wraps the LLVMGetValueName2 function from the LLVM core library. It returns the name of the value represented by self as a String, if the value has a name. In LLVM IR, named values typically include functions, global variables, and named instructions. If the value does not have a name, the function returns None.

§Returns

Returns an Option<String>:

  • Some(String) containing the name of the value if it has one.
  • None if the value does not have a name.
source

pub fn set_value_name(&self, name: &str)

Set the string name of a value.

§Details

Sets the name of the LLVM value.

This function wraps the LLVMSetValueName2 function from the LLVM core library. It assigns a new name to the value represented by self. Naming a value in LLVM IR is useful for debugging, readability, and when generating human-readable IR. Named values typically include functions, global variables, and named instructions.

§Parameters
  • name: A string slice (&str) representing the new name to assign to the value.
§Example
let my_value: ValueRef; // Assume this is an LLVM value.
my_value.set_value_name("my_value_name");

After calling this function, the value will be named “my_value_name” in the LLVM IR.

source

pub fn dump_value(&self)

Dump a representation of a value to stderr.

§Details

Dumps a textual representation of the LLVM value to standard output.

This function wraps the LLVMDumpValue function from the LLVM core library. It prints a human-readable representation of the value represented by self to standard output. This is useful for debugging or inspecting the contents of a value during development.

source

pub fn print_value_to_string(&self) -> Option<String>

Return a string representation of the value. Use dispose_message to free the string.

§Details

Converts the LLVM value to a human-readable string representation.

This function wraps the LLVMPrintValueToString function from the LLVM core library. It returns a string containing a human-readable representation of the value represented by self. This is useful for debugging or inspecting the contents of a value programmatically.

The function returns None if the conversion fails or if the value cannot be represented as a string.

§Returns

Returns an Option<String>:

  • Some(String) containing the string representation of the value if successful.
  • None if the conversion fails or the value cannot be represented as a string.
source

pub fn replace_all_uses_with(&self, new_val: &Self)

Replace all uses of a value with another one.

§Details

Replaces all uses of this value with another value in the LLVM IR.

This function wraps the LLVMReplaceAllUsesWith function from the LLVM core library. It replaces every use of the value represented by self with the value represented by new_val. This is useful for modifying LLVM IR when you need to substitute one value with another throughout the IR.

§Parameters
  • new_val: A reference to the value that will replace all uses of ValueRef.
source

pub fn is_constant(&self) -> bool

Determines whether the specified value instance is constant.

§Details

Checks if the value is a constant in LLVM IR.

This function wraps the LLVMIsConstant function from the LLVM core library. It determines whether the value represented by self is a constant. In LLVM IR, constants are values that are known at compile time, such as integer literals, floating-point literals, or constant expressions.

§Returns

Returns true if the value is a constant, otherwise returns false.

source

pub fn is_undef(&self) -> bool

Determine whether a value instance is undefined.

§Details

Checks if the value is an ‘undefined’ value in LLVM IR.

This function wraps the LLVMIsUndef function from the LLVM core library. It determines whether the value represented by self is an ‘undefined’ value. In LLVM IR, an undefined value is a placeholder that can take any value of the specified type during program execution, often used in optimization phases.

§Returns

Returns true if the value is an undefined value, otherwise returns false.

source

pub fn is_poison(&self) -> bool

Determine whether a value instance is poisonous.

§Details

Checks if the value is a ‘poison’ value in LLVM IR.

This function wraps the LLVMIsPoison function from the LLVM core library. It determines whether the value represented by self is a ‘poison’ value. In LLVM IR, a poison value results from an operation with undefined behavior and can propagate through further operations, potentially leading to incorrect results.

§Returns

Returns true if the value is a poison value, otherwise returns false.

source

pub fn is_amd_node(&self) -> Self

Determines whether the specified value instance is an AMD node.

§Details

Checks if the value is an AMD node in LLVM IR and returns the corresponding value.

This function wraps the LLVMIsAMDNode function from the LLVM core library. It determines whether the value represented by self is an AMD node and returns the corresponding value if it is. AMD nodes are specific to AMD’s extensions in LLVM, and this function is used to identify and work with those nodes.

§Returns

Returns an instance of Self that represents the value if it is an AMD node.

source

pub fn is_value_as_metadata(&self) -> Self

Determines whether the specified value instance is a value as metadata.

§Details

Checks if the value can be treated as metadata in LLVM IR and returns the corresponding value.

This function wraps the LLVMIsAValueAsMetadata function from the LLVM core library. It determines whether the value represented by self can be treated as metadata and returns the corresponding value if it can. In LLVM IR, some values can also be used as metadata, which is often used for attaching additional information to instructions or other IR elements.

§Returns

Returns an instance of Self that represents the value if it can be treated as metadata.

source

pub fn is_amd_string(&self) -> Self

Determines whether the specified value instance is an AMD string.

§Details

Checks if the value is an AMD string in LLVM IR and returns the corresponding value.

This function wraps the LLVMIsAMDString function from the LLVM core library. It determines whether the value represented by self is an AMD string and returns the corresponding value if it is. AMD strings are specific to AMD’s extensions in LLVM, and this function is used to identify and work with those strings.

§Returns

Returns an instance of Self that represents the value if it is an AMD string.

source§

impl ValueRef

source

pub fn get_first_use(&self) -> Option<UseRef>

Obtain the first use of a value.

Uses are obtained in an iterator fashion. First, call this function to obtain a reference to the first use. Then, call get_next_use on that instance and all subsequently obtained instances until get_next_use returns NULL.

§Details

Obtains the first use of a value in the LLVM IR.

This function wraps the LLVMGetFirstUse function from the LLVM core library. It retrieves the first use of the value represented by ValueRef. In LLVM IR, a “use” represents an instance where a value is used by an instruction or another value. The use can be iterated over to find all instances where this value is used.

After obtaining the first use with this function, you can call get_next_use on the resulting UseRef to iterate over all uses of the value. Continue calling get_next_use on each subsequent UseRef until it returns None.

§Returns

Returns an Option<UseRef>:

  • Some(UseRef) if there is a use associated with the value.
  • None if there are no uses associated with the value.
source

pub fn get_next_use(&self, u: &UseRef) -> Option<UseRef>

Obtain the next use of a value.

This effectively advances the iterator. It returns NULL if you are on the final use and no more are available.

§Details

Obtains the next use of a value in the LLVM IR.

This function wraps the LLVMGetNextUse function from the LLVM core library. It advances the iterator of uses for a value, returning the next use after the provided UseRef. If there are no more uses, it returns None. This function is used in conjunction with get_first_use to iterate over all uses of a value in LLVM IR.

§Parameters
  • u: A reference to the current UseRef from which to obtain the next use.
§Returns

Returns an Option<UseRef>:

  • Some(UseRef) if there is a subsequent use associated with the value.
  • None if there are no more uses associated with the value.
source

pub fn get_user(&self, u: &UseRef) -> Self

Obtain the user value for a user.

The returned value corresponds to a UserRef type.

§Details

Obtains the value that is using another value in LLVM IR.

This function wraps the LLVMGetUser function from the LLVM core library. It retrieves the user value associated with the provided UseRef. In LLVM IR, a “user” is an entity (typically an instruction or another value) that makes use of a particular value. This function returns the value that corresponds to the user.

§Parameters
  • u: A reference to the UseRef for which to obtain the user value.
§Returns

Returns an instance of ValueRef, which represents the user value associated with the provided UseRef.

source

pub fn get_used_value(&self, u: &UseRef) -> Self

Obtain the value this use corresponds to.

§Details

Obtains the value that is being used by a specific use in LLVM IR.

This function wraps the LLVMGetUsedValue function from the LLVM core library. It retrieves the value associated with a specific UseRef, which represents the value that is being used. This is useful for understanding which value is being utilized in a particular operation or instruction within LLVM IR.

§Parameters
  • u: A reference to the UseRef for which to obtain the used value.
§Returns

Returns an instance of ValueRef, which represents the value that is being used by the provided UseRef.

source

pub fn get_operand(&self, index: u32) -> Option<Self>

Obtain an operand at a specific index in a LLVM User value.

§Details

Retrieves an operand at a specified index from a value in LLVM IR.

This function wraps the LLVMGetOperand function from the LLVM core library. It returns the operand at the specified index (index) from the value represented by ValueRef. Operands are the inputs to instructions or other values in LLVM IR. If the index is out of bounds or the operand cannot be retrieved, the function returns None.

§Parameters
  • index: The index of the operand to retrieve. This index should be within the bounds of the number of operands the value has.
§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) containing the retrieved operand if the index is valid and the operand is found.
  • None if the index is out of bounds or the operand cannot be retrieved.
source

pub fn get_operand_use(&self, index: u32) -> Option<UseRef>

Obtain the use of an operand at a specific index in a LLVM User value.

§Details

Retrieves the use of an operand at a specified index from a value in LLVM IR.

This function wraps the LLVMGetOperandUse function from the LLVM core library. It returns the UseRef associated with the operand at the specified index (index) from the value represented by ValueRef. In LLVM IR, a “use” refers to an instance where an operand is used by an instruction or another value. If the index is out of bounds or the operand use cannot be retrieved, the function returns None.

§Parameters
  • index: The index of the operand use to retrieve. This index should be within the bounds of the number of operands the value has.
§Returns

Returns an Option<UseRef>:

  • Some(UseRef) containing the retrieved operand use if the index is valid and the operand use is found.
  • None if the index is out of bounds or the operand use cannot be retrieved.
source

pub fn set_operand(&mut self, index: u32, val: &Self)

Set an operand at a specific index in a LLVM User value.

§Details

Sets the value of an operand at a specified index for a value in LLVM IR.

This function wraps the LLVMSetOperand function from the LLVM core library. It assigns a new value (val) to the operand at the specified index (index) for the value represented by ValueRef. This allows modification of the operands of an instruction or another value within LLVM IR.

§Parameters
  • index: The index of the operand to set. This index should be within the bounds of the number of operands the value has.
  • val: A reference to the new value (ValueRef) that will be assigned to the operand at the specified index.
source

pub fn get_num_operands(&self) -> i32

Obtain the number of operands in a LLVM User value.

§Details

Retrieves the number of operands associated with a value in LLVM IR.

This function wraps the LLVMGetNumOperands function from the LLVM core library. It returns the number of operands that the value represented by self has. This is useful for determining how many inputs or arguments a particular instruction or value takes within LLVM IR.

§Returns

Returns an i32 representing the number of operands associated with the value.

source§

impl ValueRef

That implementations related to LLVM Modules MemoryDef.

source

pub fn get_inline_asm_asm_string(&self) -> Option<String>

Get the template string used for an inline assembly snippet.

§Details

Retrieves the assembly code string from the inline assembly block in LLVM IR.

This function wraps the LLVMGetInlineAsmAsmString function from the LLVM core library. It returns the assembly code string used by the inline assembly block associated with self. This string contains the actual assembly instructions that will be executed as part of the inline assembly.

If the assembly string cannot be retrieved, the function returns None.

§Returns

Returns an Option<String>:

  • Some(String) containing the assembly code string if successful.
  • None if the assembly string cannot be retrieved.
source

pub fn get_inline_asm_constraint_string(&self) -> Option<String>

Get the raw constraint string for an inline assembly snippet.

§Details

Retrieves the constraint string associated with the inline assembly block in LLVM IR.

This function wraps the LLVMGetInlineAsmConstraintString function from the LLVM core library. It returns the constraint string used by the inline assembly block associated with self. The constraint string specifies the constraints on the operands used in the inline assembly, such as register classes or memory addressing modes.

If the constraint string cannot be retrieved, the function returns None.

§Returns

Returns an Option<String>:

  • Some(String) containing the constraint string if successful.
  • None if the constraint string cannot be retrieved.
source

pub fn get_inline_asm_dialect(&self) -> InlineAsmDialect

Get the dialect used by the inline asm snippet.

§Details

Retrieves the dialect of the inline assembly block in LLVM IR.

This function wraps the LLVMGetInlineAsmDialect function from the LLVM core library. It returns the InlineAsmDialect representing the dialect used by the inline assembly block associated with self. The dialect determines the syntax and conventions used in the inline assembly, which may vary between different assemblers (e.g., AT&T vs. Intel syntax).

§Returns

Returns an InlineAsmDialect that represents the dialect of the inline assembly block.

source

pub fn get_inline_asm_function_type(&self) -> TypeRef

Get the function type of the inline assembly snippet.

This is the same type that was passed into LLVMGetInlineAsm originally.

§Returns

Retrieves the function type of the inline assembly block in LLVM IR.

This function wraps the LLVMGetInlineAsmFunctionType function from the LLVM core library. It returns the TypeRef representing the function type of the inline assembly block associated with self. The function type defines the signature of the inline assembly, including the types of its arguments and return value.

§Returns

Returns a TypeRef that represents the function type of the inline assembly block.

source

pub fn get_inline_asm_has_side_effects(&self) -> bool

Get if the inline asm snippet has side effects

§Details

Checks whether an inline assembly block has side effects in LLVM IR.

This function wraps the LLVMGetInlineAsmHasSideEffects function from the LLVM core library. It determines whether the inline assembly represented by self has side effects, meaning that it may alter state or interact with external systems in ways that are not visible within the LLVM IR. This flag is important for optimizations, as it indicates that the inline assembly cannot be removed or reordered without potentially affecting program behavior.

§Returns

Returns true if the inline assembly block has side effects, otherwise returns false.

source

pub fn get_inline_asm_needs_aligned_stack(&self) -> bool

Get if the inline asm snippet needs an aligned stack

§Details

Checks whether an inline assembly block requires an aligned stack in LLVM IR.

This function wraps the LLVMGetInlineAsmNeedsAlignedStack function from the LLVM core library. It determines whether the inline assembly represented by self requires the stack to be aligned. Proper stack alignment may be necessary for certain instructions or calling conventions, and this flag indicates whether such alignment is needed.

§Returns

Returns true if the inline assembly block requires an aligned stack, otherwise returns false.

source

pub fn get_inline_asm_can_unwind(&self) -> bool

Get if the inline asm snippet may unwind the stack

§Details

Checks whether an inline assembly block can unwind in LLVM IR.

This function wraps the LLVMGetInlineAsmCanUnwind function from the LLVM core library. It determines whether the inline assembly represented by self is capable of unwinding, which can affect how exceptions and other control flows are handled during execution.

§Returns

Returns true if the inline assembly block can unwind, otherwise returns false.

source

pub fn get_debug_loc_directory(&self) -> Option<String>

Return the directory of the debug location for this value, which must be an LLVM Instruction, GlobalVariable, or Function.

§Details

Retrieves the directory from the debug location associated with this value in LLVM IR.

This function wraps the LLVMGetDebugLocDirectory function from the LLVM core library. It returns the directory of the source code location associated with the debug information for the value represented by self. If the directory cannot be retrieved, the function returns None.

§Returns

Returns an Option<String>:

  • Some(String) containing the directory associated with the value’s debug location if successful.
  • None if the directory cannot be retrieved.
source

pub fn get_debug_loc_filename(&self) -> Option<String>

Return the filename of the debug location for this value, which must be an LLVM Instruction, lGlobalVariable, or Function.

§Details

Retrieves the filename from the debug location associated with this value in LLVM IR.

This function wraps the LLVMGetDebugLocFilename function from the LLVM core library. It returns the filename of the source code location associated with the debug information for the value represented by self. If the filename cannot be retrieved, the function returns None.

§Returns

Returns an Option<String>:

  • Some(String) containing the filename associated with the value’s debug location if successful.
  • None if the filename cannot be retrieved.
source

pub fn get_debug_loc_line(&self) -> u32

Return the line number of the debug location for this value, which must be an LLVM Instruction, GlobalVariable, or Function.

§Details

Retrieves the line number from the debug location associated with this value in LLVM IR.

This function wraps the LLVMGetDebugLocLine function from the LLVM core library. It returns the line number of the source code location associated with the debug information for the value represented by self. This is useful for debugging and for tools that need to report precise source locations.

§Returns

Returns a u32 representing the line number in the source code associated with this value’s debug location.

source

pub fn get_debug_loc_column(&self) -> u32

Return the column number of the debug location for this value, which must be an LLVM Instruction.

§Details

Retrieves the column number from the debug location associated with this value in LLVM IR.

This function wraps the LLVMGetDebugLocColumn function from the LLVM core library. It returns the column number of the source code location associated with the debug information for the value represented by self. This is useful for debugging and for tools that need to report precise source locations.

§Returns

Returns a u32 representing the column number in the source code associated with this value’s debug location.

source

pub fn get_next_function(&self) -> Option<Self>

Advance a Function iterator to the next Function.

Returns None if the iterator was already at the end and there are no more functions.

§Details

Retrieves the next function in the module relative to this function, if it exists.

This function wraps the LLVMGetNextFunction function from the LLVM core library. It returns the next function in the module relative to the function represented by self. If there is no next function, the function returns None. This is useful for iterating over functions within a module in LLVM IR.

§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) containing the next function if it exists.
  • None if there is no next function in the module.
source

pub fn get_previous_function(&self) -> Option<Self>

Decrement a Function iterator to the previous Function.

Returns None if the iterator was already at the beginning and there are no previous functions.

§Details

Retrieves the previous function in the module relative to this function, if it exists.

This function wraps the LLVMGetPreviousFunction function from the LLVM core library. It returns the previous function in the module relative to the function represented by self. If there is no previous function, the function returns None. This is useful for iterating over functions within a module in LLVM IR.

§Returns

Returns an Option<ValueRef>:

  • Some(ValueRef) containing the previous function if it exists.
  • None if there is no previous function in the module.

Trait Implementations§

source§

impl Debug for ValueRef

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for ValueRef

source§

type Target = *mut LLVMValue

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl From<*mut LLVMValue> for ValueRef

source§

fn from(value_ref: LLVMValueRef) -> Self

Converts to this type from the input type.
source§

impl From<ConstValueRef> for ValueRef

source§

fn from(value: ConstValueRef) -> Self

Converts to this type from the input type.
source§

impl From<ValueRef> for ConstValueRef

source§

fn from(value: ValueRef) -> Self

Converts to this type from the input type.
source§

impl GetRef for ValueRef

source§

type RawRef = *mut LLVMValue

Raw LLVM reference type
source§

fn get_ref(&self) -> Self::RawRef

Get LLVM raw reference

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.