11//! Implements all of the required methods for computing the layouts of types.
22
33use hash_codegen:: {
4- repr:: { Layout , LayoutShape , TyInfo , Variants } ,
4+ repr:: { Layout , TyInfo } ,
55 target:: abi:: AbiRepresentation ,
66 traits:: layout:: LayoutMethods ,
77} ;
8- use hash_ir:: ty:: ReprTyId ;
98use hash_storage:: store:: statics:: StoreId ;
109
11- use super :: { LLVMBuilder , ty :: TyMemoryRemap } ;
10+ use super :: LLVMBuilder ;
1211use crate :: ctx:: CodeGenCtx ;
1312
1413impl < ' b > LayoutMethods < ' b > for CodeGenCtx < ' b , ' _ > {
15- fn backend_field_index ( & self , info : TyInfo , index : usize ) -> u64 {
16- info. layout . map ( |layout| layout. llvm_field_index ( self , info. ty , index) )
17- }
18-
1914 fn is_backend_immediate ( & self , info : TyInfo ) -> bool {
2015 info. layout . map ( |layout| layout. is_llvm_immediate ( ) )
2116 }
@@ -26,10 +21,6 @@ impl<'b> LayoutMethods<'b> for CodeGenCtx<'b, '_> {
2621}
2722
2823impl < ' b > LayoutMethods < ' b > for LLVMBuilder < ' _ , ' b , ' _ > {
29- fn backend_field_index ( & self , info : TyInfo , index : usize ) -> u64 {
30- self . ctx . backend_field_index ( info, index)
31- }
32-
3324 fn is_backend_immediate ( & self , ty : TyInfo ) -> bool {
3425 self . ctx . is_backend_immediate ( ty)
3526 }
@@ -40,14 +31,11 @@ impl<'b> LayoutMethods<'b> for LLVMBuilder<'_, 'b, '_> {
4031}
4132
4233pub trait ExtendedLayoutMethods < ' m > {
43- /// Compute the field index from the backend specific type.
44- fn llvm_field_index ( & self , cx : & CodeGenCtx < ' _ , ' m > , ty : ReprTyId , index : usize ) -> u64 ;
45-
4634 /// Check if this is type is represented as an immediate value.
4735 fn is_llvm_immediate ( & self ) -> bool ;
4836
4937 /// Returns true if this [Layout] ABI is represented as is a
50- /// [`AbiRepresentation::Pair(..) `]
38+ /// [`AbiRepresentation::Pair`]
5139 fn is_llvm_scalar_pair ( & self ) -> bool ;
5240}
5341
@@ -63,40 +51,4 @@ impl<'m> ExtendedLayoutMethods<'m> for &Layout {
6351 fn is_llvm_scalar_pair ( & self ) -> bool {
6452 matches ! ( self . abi, AbiRepresentation :: Pair ( ..) )
6553 }
66-
67- fn llvm_field_index ( & self , ctx : & CodeGenCtx < ' _ , ' m > , ty : ReprTyId , index : usize ) -> u64 {
68- // Field index of scalar and scalar pairs is not applicable since
69- // it is handled else where.
70- match self . abi {
71- AbiRepresentation :: Scalar ( _) | AbiRepresentation :: Pair ( ..) => {
72- panic ! ( "cannot get field index of scalar or scalar pair" )
73- }
74- _ => { }
75- } ;
76-
77- match self . shape {
78- LayoutShape :: Primitive | LayoutShape :: Union { .. } => {
79- panic ! ( "cannot get field index of primitive or union" )
80- }
81- LayoutShape :: Array { .. } => index as u64 ,
82-
83- // Here, we have to rely on the re-mapped version of the layout since
84- // we had to adjust it to account for all of the padding that was added
85- // to the struct/aggregate.
86- LayoutShape :: Aggregate { .. } => {
87- let variant_index = match self . variants {
88- Variants :: Single { index } => Some ( index) ,
89- Variants :: Multiple { .. } => None ,
90- } ;
91-
92- match ctx. ty_remaps . borrow ( ) . get ( & ( ty, variant_index) ) {
93- Some ( TyMemoryRemap { remap : Some ( remap) , .. } ) => remap[ index] as u64 ,
94- Some ( TyMemoryRemap { remap : None , .. } ) => {
95- self . shape . memory_index ( index) as u64
96- }
97- None => panic ! ( "cannot find remapped layout for `{}`" , ty) ,
98- }
99- }
100- }
101- }
10254}
0 commit comments