pub(crate) type Builder<'a, 'll, 'tcx> = GenericBuilder<'a, 'll, FullCx<'ll, 'tcx>>;Aliased Type§
pub(crate) struct Builder<'a, 'll, 'tcx> {
llbuilder_raw: NonNull<Builder<'ll>>,
pub cx: &'a GenericCx<'ll, FullCx<'ll, 'tcx>>,
pub span: Span,
}Fields§
§llbuilder_raw: NonNull<Builder<'ll>>Owning pointer that corresponds to an LLVMBuilderRef. Disposed on drop.
cx: &'a GenericCx<'ll, FullCx<'ll, 'tcx>>§span: SpanMethods from Deref<Target = GenericCx<'ll, FullCx<'ll, 'tcx>>>§
pub(crate) fn const_array( &self, ty: Type<'ll>, elts: &[Value<'ll>], ) -> Value<'ll>
pub(crate) fn const_bytes(&self, bytes: &[u8]) -> Value<'ll>
pub(crate) fn null_terminate_const_bytes(&self, bytes: &[u8]) -> Value<'ll>
pub(crate) fn const_get_elt(&self, v: Value<'ll>, idx: u64) -> Value<'ll>
pub(crate) fn const_null(&self, t: Type<'ll>) -> Value<'ll>
pub(crate) fn const_struct( &self, elts: &[Value<'ll>], packed: bool, ) -> Value<'ll>
pub(crate) fn alloc_to_backend( &self, global_alloc: GlobalAlloc<'tcx>, need_symbol_name: bool, schema: Option<&PointerAuthSchema>, ) -> Result<Value<'ll>, u64>
pub(crate) fn const_bitcast(&self, val: Value<'ll>, ty: Type<'ll>) -> Value<'ll>
pub(crate) fn const_pointercast( &self, val: Value<'ll>, ty: Type<'ll>, ) -> Value<'ll>
Sourcepub(crate) fn static_addr_of_mut(
&self,
cv: Value<'ll>,
align: Align,
kind: Option<&str>,
) -> Value<'ll>
pub(crate) fn static_addr_of_mut( &self, cv: Value<'ll>, align: Align, kind: Option<&str>, ) -> Value<'ll>
Create a global variable.
The returned global variable is a pointer in the default address space for globals. Fails if a symbol with the given name already exists.
Sourcepub(crate) fn static_addr_of_impl(
&self,
cv: Value<'ll>,
align: Align,
kind: Option<&str>,
) -> Value<'ll>
pub(crate) fn static_addr_of_impl( &self, cv: Value<'ll>, align: Align, kind: Option<&str>, ) -> Value<'ll>
Create a global constant.
The returned global variable is a pointer in the default address space for globals.
pub(crate) fn get_static(&self, def_id: DefId) -> Value<'ll>
fn get_static_inner(&self, def_id: DefId, llty: Type<'ll>) -> Value<'ll>
Sourcepub(crate) fn add_compiler_used_global(&self, global: Value<'ll>)
pub(crate) fn add_compiler_used_global(&self, global: Value<'ll>)
Add a global value to a list to be stored in the llvm.compiler.used variable,
an array of ptr.
fn define_objc_classname(&self, classname: &str) -> Value<'ll>
fn get_objc_class_t(&self) -> Type<'ll>
fn get_objc_classref(&self, classname: Symbol) -> Value<'ll>
fn get_objc_selref(&self, methname: Symbol) -> Value<'ll>
pub(crate) fn statics_to_rauw(&self) -> &RefCell<Vec<(Value<'ll>, Value<'ll>)>>
Sourcepub(crate) fn coverage_cx(&self) -> &CguCoverageContext<'ll, 'tcx>
pub(crate) fn coverage_cx(&self) -> &CguCoverageContext<'ll, 'tcx>
Extra state that is only available when coverage instrumentation is enabled.
pub(crate) fn create_used_variable_impl( &self, name: &'static CStr, values: &[Value<'ll>], )
Sourcepub(crate) fn objc_abi_version(&self) -> u32
pub(crate) fn objc_abi_version(&self) -> u32
The Objective-C ABI that is used.
This corresponds to the -fobjc-abi-version= flag in Clang / GCC.
pub(crate) fn add_ptrauth_elf_got_flag(&self)
pub(crate) fn add_ptrauth_sign_personality_flag(&self)
pub(crate) fn add_ptrauth_pauthabi_version_and_platform_flags( &self, aarch64_elf_pauthabi_version: u32, )
pub(crate) fn add_objc_module_flags(&self)
pub(crate) fn is_sanitizer_type_ignored( &self, sanitizer: &CStr, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, ) -> bool
pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> Value<'ll>
pub(crate) fn get_const_int(&self, ty: Type<'ll>, val: u64) -> Value<'ll>
pub(crate) fn get_const_i64(&self, n: u64) -> Value<'ll>
pub(crate) fn get_const_i32(&self, n: u64) -> Value<'ll>
pub(crate) fn get_const_i16(&self, n: u64) -> Value<'ll>
pub(crate) fn get_const_i8(&self, n: u64) -> Value<'ll>
pub(crate) fn get_md_kind_id(&self, name: &str) -> MetadataKindId
pub(crate) fn create_metadata(&self, name: &[u8]) -> &'ll Metadata
pub(crate) fn get_functions(&self) -> Vec<Value<'ll>>
pub(crate) fn get_intrinsic( &self, base_name: Cow<'static, str>, type_params: &[Type<'ll>], ) -> (Type<'ll>, Value<'ll>)
fn declare_intrinsic( &self, base_name: &str, type_params: &[Type<'ll>], ) -> (Type<'ll>, Value<'ll>)
Sourcepub(crate) fn generate_local_symbol_name(&self, prefix: &str) -> String
pub(crate) fn generate_local_symbol_name(&self, prefix: &str) -> String
Generates a new symbol name with the given prefix. This symbol name must
only be used for definitions with internal or private linkage.
Sourcepub(crate) fn generate_global_symbol_name(&self) -> String
pub(crate) fn generate_global_symbol_name(&self) -> String
Generates a new global symbol name with the given prefix.
Sourcepub(crate) fn md_node_in_context(
&self,
md_list: &[&'ll Metadata],
) -> &'ll Metadata
pub(crate) fn md_node_in_context( &self, md_list: &[&'ll Metadata], ) -> &'ll Metadata
Wrapper for LLVMMDNodeInContext2, i.e. llvm::MDNode::get.
Sourcepub(crate) fn set_metadata(
&self,
val: Value<'ll>,
kind_id: MetadataKindId,
md: &'ll Metadata,
)
pub(crate) fn set_metadata( &self, val: Value<'ll>, kind_id: MetadataKindId, md: &'ll Metadata, )
A wrapper for llvm::LLVMSetMetadata, but it takes Metadata as a parameter instead of Value.
Sourcepub(crate) fn set_metadata_node(
&self,
instruction: Value<'ll>,
kind_id: MetadataKindId,
md_list: &[&'ll Metadata],
) -> &'ll Metadata
pub(crate) fn set_metadata_node( &self, instruction: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) -> &'ll Metadata
Helper method for the sequence of calls:
LLVMMDNodeInContext2(to create anllvm::MDNodefrom a list of metadata)LLVMMetadataAsValue(to adapt that node to anllvm::Value)LLVMSetMetadata(to set that node as metadata ofkind_idforinstruction)
Sourcepub(crate) fn module_add_named_metadata_node(
&self,
module: Module<'ll>,
kind_name: &CStr,
md_list: &[&'ll Metadata],
)
pub(crate) fn module_add_named_metadata_node( &self, module: Module<'ll>, kind_name: &CStr, md_list: &[&'ll Metadata], )
Helper method for the sequence of calls:
LLVMMDNodeInContext2(to create anllvm::MDNodefrom a list of metadata)LLVMMetadataAsValue(to adapt that node to anllvm::Value)LLVMAddNamedMetadataOperand(to set that node as metadata ofkind_nameformodule)
Sourcepub(crate) fn global_add_metadata_node(
&self,
global: Value<'ll>,
kind_id: MetadataKindId,
md_list: &[&'ll Metadata],
)
pub(crate) fn global_add_metadata_node( &self, global: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], )
Helper method for the sequence of calls:
LLVMMDNodeInContext2(to create anllvm::MDNodefrom a list of metadata)LLVMGlobalAddMetadata(to set that node as metadata ofkind_idforglobal)
Sourcepub(crate) fn global_set_metadata_node(
&self,
global: Value<'ll>,
kind_id: MetadataKindId,
md_list: &[&'ll Metadata],
)
pub(crate) fn global_set_metadata_node( &self, global: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], )
Helper method for the sequence of calls:
LLVMMDNodeInContext2(to create anllvm::MDNodefrom a list of metadata)LLVMGlobalSetMetadata(to set that node as metadata ofkind_idforglobal)
Sourcefn covfun_section_name(&self) -> &CStr
fn covfun_section_name(&self) -> &CStr
Returns the section name to use when embedding per-function coverage information in the object file, according to the target’s object file format. LLVM’s coverage tools use information from this section when producing coverage reports.
Typical values are:
__llvm_covfunon Linux__LLVM_COV,__llvm_covfunon macOS (includes__LLVM_COV,segment prefix).lcovfun$Mon Windows (includes$Msorting suffix)
Sourcefn ensure_pgo_func_name_var(&self, instance: Instance<'tcx>) -> Value<'ll>
fn ensure_pgo_func_name_var(&self, instance: Instance<'tcx>) -> Value<'ll>
For LLVM codegen, returns a function-specific Value for a global
string, to hold the function name passed to LLVM intrinsic
instrprof.increment(). The Value is only created once per instance.
Multiple invocations with the same instance return the same Value.
This has the side-effect of causing coverage codegen to consider this function “used”, making it eligible to emit an associated covfun record.
Sourcefn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc
fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc
Looks up debug source information about a BytePos.
fn create_template_type_parameter( &self, name: &str, actual_type_metadata: &'ll Metadata, ) -> &'ll Metadata
Sourcepub(crate) fn debuginfo_finalize(&self)
pub(crate) fn debuginfo_finalize(&self)
Creates any deferred debug metadata nodes
Sourcepub(crate) fn declare_global(&self, name: &str, ty: Type<'ll>) -> Value<'ll>
pub(crate) fn declare_global(&self, name: &str, ty: Type<'ll>) -> Value<'ll>
Declare a global value.
If there’s a value with the same name already declared, the function will return its Value instead.
Sourcepub(crate) fn declare_global_in_addrspace(
&self,
name: &str,
ty: Type<'ll>,
addr_space: AddressSpace,
) -> Value<'ll>
pub(crate) fn declare_global_in_addrspace( &self, name: &str, ty: Type<'ll>, addr_space: AddressSpace, ) -> Value<'ll>
Declare a global value in a specific address space.
If there’s a value with the same name already declared, the function will return its Value instead.
Sourcepub(crate) fn declare_cfn(
&self,
name: &str,
unnamed: UnnamedAddr,
fn_type: Type<'ll>,
) -> Value<'ll>
pub(crate) fn declare_cfn( &self, name: &str, unnamed: UnnamedAddr, fn_type: Type<'ll>, ) -> Value<'ll>
Declare a C ABI function.
Only use this for foreign function ABIs and glue. For Rust functions use
declare_fn instead.
If there’s a value with the same name already declared, the function will update the declaration and return existing Value instead.
Sourcepub(crate) fn declare_entry_fn(
&self,
name: &str,
callconv: CallConv,
unnamed: UnnamedAddr,
fn_type: Type<'ll>,
) -> Value<'ll>
pub(crate) fn declare_entry_fn( &self, name: &str, callconv: CallConv, unnamed: UnnamedAddr, fn_type: Type<'ll>, ) -> Value<'ll>
Declare an entry Function
The ABI of this function can change depending on the target (although for now the same as
declare_cfn)
If there’s a value with the same name already declared, the function will update the declaration and return existing Value instead.
Sourcepub(crate) fn declare_fn(
&self,
name: &str,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
instance: Option<Instance<'tcx>>,
) -> Value<'ll>
pub(crate) fn declare_fn( &self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, instance: Option<Instance<'tcx>>, ) -> Value<'ll>
Declare a Rust function.
If there’s a value with the same name already declared, the function will update the declaration and return existing Value instead.
Sourcepub(crate) fn define_global(
&self,
name: &str,
ty: Type<'ll>,
) -> Option<Value<'ll>>
pub(crate) fn define_global( &self, name: &str, ty: Type<'ll>, ) -> Option<Value<'ll>>
Declare a global with an intention to define it.
Use this function when you intend to define a global. This function will
return None if the name already has a definition associated with it. In that
case an error should be reported to the user, because it usually happens due
to user’s fault (e.g., misuse of #[no_mangle] or #[export_name] attributes).
Sourcepub(crate) fn get_declared_value(&self, name: &str) -> Option<Value<'ll>>
pub(crate) fn get_declared_value(&self, name: &str) -> Option<Value<'ll>>
Gets declared value by name.
Sourcepub(crate) fn get_defined_value(&self, name: &str) -> Option<Value<'ll>>
pub(crate) fn get_defined_value(&self, name: &str) -> Option<Value<'ll>>
Gets defined or externally defined (AvailableExternally linkage) value by name.
fn predefine_without_aliases( &self, instance: Instance<'tcx>, attrs: &CodegenFnAttrs, linkage: Linkage, visibility: Visibility, symbol_name: &str, ) -> Value<'ll>
Sourcefn add_static_aliases(
&self,
aliasee: Value<'ll>,
aliases: &[(DefId, Linkage, Visibility)],
)
fn add_static_aliases( &self, aliasee: Value<'ll>, aliases: &[(DefId, Linkage, Visibility)], )
LLVM has the concept of an alias.
We need this for the “externally implementable items” feature,
though it’s generally useful.
On macos, though this might be a more general problem, function symbols have a fixed target architecture. This is necessary, since macos binaries may contain code for both ARM and x86 macs.
LLVM can add attributes for target architecture to function symbols, cannot do so for statics, but importantly, also cannot for aliases even when aliases may refer to a function symbol.
This is not a problem: instead of using LLVM aliases, we can just generate a new function symbol (with target architecture!) which effectively comes down to:
fn alias_name(...args) {
original_name(...args)
}That’s also an alias.
This does mean that the alias symbol has a different address than the original symbol (assuming no optimizations by LLVM occur). This is unacceptable for statics. So for statics we do want to use LLVM aliases, which is fine, since for those we don’t care about target architecture anyway.
So, this function is for static aliases. See add_function_aliases for the alternative.
Sourcefn add_function_aliases(
&self,
aliasee_instance: Instance<'tcx>,
aliasee: Value<'ll>,
attrs: &CodegenFnAttrs,
aliases: &[(DefId, Linkage, Visibility)],
)
fn add_function_aliases( &self, aliasee_instance: Instance<'tcx>, aliasee: Value<'ll>, attrs: &CodegenFnAttrs, aliases: &[(DefId, Linkage, Visibility)], )
See add_static_aliases for docs.
Sourcepub(crate) fn assume_dso_local(
&self,
llval: Value<'ll>,
is_declaration: bool,
) -> bool
pub(crate) fn assume_dso_local( &self, llval: Value<'ll>, is_declaration: bool, ) -> bool
A definition or declaration can be assumed to be local to a group of libraries that form a single DSO or executable. Marks the local as DSO if so.
fn set_visibility( &self, lldecl: Value<'ll>, linkage: Linkage, visibility: Visibility, )
fn should_assume_dso_local( &self, llval: Value<'ll>, is_declaration: bool, ) -> bool
pub(crate) fn type_named_struct(&self, name: &str) -> Type<'ll>
pub(crate) fn set_struct_body(&self, ty: Type<'ll>, els: &[Type<'ll>])
pub(crate) fn set_struct_body_packed(&self, ty: Type<'ll>, els: &[Type<'ll>])
pub(crate) fn type_void(&self) -> Type<'ll>
Sourcepub(crate) fn type_ix(&self, num_bits: u64) -> Type<'ll>
pub(crate) fn type_ix(&self, num_bits: u64) -> Type<'ll>
x Creates an integer type with the given number of bits, e.g., i24
pub(crate) fn type_vector(&self, ty: Type<'ll>, count: u64) -> Type<'ll>
pub(crate) fn type_scalable_vector( &self, ty: Type<'ll>, count: u64, ) -> Type<'ll>
pub(crate) fn add_func(&self, name: &str, ty: Type<'ll>) -> Value<'ll>
pub(crate) fn get_return_type(&self, ty: Type<'ll>) -> Type<'ll>
pub(crate) fn func_params_types(&self, ty: Type<'ll>) -> Vec<Type<'ll>>
pub(crate) fn func_is_variadic(&self, ty: Type<'ll>) -> bool
pub(crate) fn struct_element_types(&self, ty: Type<'ll>) -> Vec<Type<'ll>>
pub(crate) fn type_int_from_ty(&self, t: IntTy) -> Type<'ll>
pub(crate) fn type_uint_from_ty(&self, t: UintTy) -> Type<'ll>
pub(crate) fn type_float_from_ty(&self, t: FloatTy) -> Type<'ll>
Sourcepub(crate) fn type_padding_filler(&self, size: Size, align: Align) -> Type<'ll>
pub(crate) fn type_padding_filler(&self, size: Size, align: Align) -> Type<'ll>
Return an LLVM type that has at most the required alignment, and exactly the required size, as a best-effort padding array.
pub(crate) fn llcx(&self) -> Context<'ll>
pub(crate) fn llmod(&self) -> Module<'ll>
pub(crate) fn isize_ty(&self) -> Type<'ll>
pub(crate) fn type_variadic_func( &self, args: &[Type<'ll>], ret: Type<'ll>, ) -> Type<'ll>
pub(crate) fn type_i1(&self) -> Type<'ll>
pub(crate) fn type_struct(&self, els: &[Type<'ll>]) -> Type<'ll>
pub(crate) fn type_packed_struct(&self, els: &[Type<'ll>]) -> Type<'ll>
pub(crate) fn type_bf16(&self) -> Type<'ll>
pub(crate) fn type_array(&self, ty: Type<'ll>, len: u64) -> Type<'ll>
Sourcepub(crate) fn type_kind(&self, ty: Type<'ll>) -> TypeKind
pub(crate) fn type_kind(&self, ty: Type<'ll>) -> TypeKind
Prefer more specific methods (e.g. int_width, float_type, vector_element_type) when
possible.
pub(crate) fn align_of(&self, ty: Ty<'tcx>) -> Align
pub(crate) fn size_of(&self, ty: Ty<'tcx>) -> Size
pub(crate) fn size_and_align_of(&self, ty: Ty<'tcx>) -> (Size, Align)
pub(crate) fn spanned_size_and_align_of( &self, ty: Ty<'tcx>, span: Span, ) -> (Size, Align)
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes