Trait rustc_codegen_ssa::traits::LayoutTypeMethods
source · pub trait LayoutTypeMethods<'tcx>: Backend<'tcx> {
// Required methods
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type;
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type;
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type;
fn reg_backend_type(&self, ty: &Reg) -> Self::Type;
fn immediate_backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type;
fn is_backend_immediate(&self, layout: TyAndLayout<'tcx>) -> bool;
fn is_backend_scalar_pair(&self, layout: TyAndLayout<'tcx>) -> bool;
fn backend_field_index(
&self,
layout: TyAndLayout<'tcx>,
index: usize
) -> u64;
fn scalar_pair_element_backend_type(
&self,
layout: TyAndLayout<'tcx>,
index: usize,
immediate: bool
) -> Self::Type;
// Provided method
fn scalar_copy_backend_type(
&self,
layout: TyAndLayout<'tcx>
) -> Option<Self::Type> { ... }
}Required Methods§
sourcefn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type
fn backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type
The backend type used for a rust type when it’s in memory, such as when it’s stack-allocated or when it’s being loaded or stored.
fn cast_backend_type(&self, ty: &CastTarget) -> Self::Type
fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type
fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Self::Type
fn reg_backend_type(&self, ty: &Reg) -> Self::Type
sourcefn immediate_backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type
fn immediate_backend_type(&self, layout: TyAndLayout<'tcx>) -> Self::Type
The backend type used for a rust type when it’s in an SSA register.
For nearly all types this is the same as the Self::backend_type, however
bool (and other 0-or-1 values) are kept as BaseTypeMethods::type_i1
in registers but as BaseTypeMethods::type_i8 in memory.
Converting values between the two different backend types is done using
from_immediate and
to_immediate_scalar.
fn is_backend_immediate(&self, layout: TyAndLayout<'tcx>) -> bool
fn is_backend_scalar_pair(&self, layout: TyAndLayout<'tcx>) -> bool
fn backend_field_index(&self, layout: TyAndLayout<'tcx>, index: usize) -> u64
fn scalar_pair_element_backend_type( &self, layout: TyAndLayout<'tcx>, index: usize, immediate: bool ) -> Self::Type
Provided Methods§
sourcefn scalar_copy_backend_type(
&self,
layout: TyAndLayout<'tcx>
) -> Option<Self::Type>
fn scalar_copy_backend_type( &self, layout: TyAndLayout<'tcx> ) -> Option<Self::Type>
A type that can be used in a super::BuilderMethods::load +
super::BuilderMethods::store pair to implement a typed copy,
such as a MIR *_0 = *_1.
It’s always legal to return None here, as the provided impl does,
in which case callers should use super::BuilderMethods::memcpy
instead of the load+store pair.
This can be helpful for things like arrays, where the LLVM backend type
[3 x i16] optimizes to three separate loads and stores, but it can
instead be copied via an i48 that stays as the single load+store.
(As of 2023-05 LLVM cannot necessarily optimize away a memcpy in these
cases, due to poison handling, but in codegen we have more information
about the type invariants, so can emit something better instead.)
This should return None for particularly-large types, where leaving
the memcpy may well be important to avoid code size explosion.