@@ -25,23 +25,22 @@ fn uncached_llvm_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2525 -> Type {
2626 match layout. abi {
2727 layout:: Abi :: Scalar ( _) => bug ! ( "handled elsewhere" ) ,
28- layout:: Abi :: Vector => {
28+ layout:: Abi :: Vector { ref element , count } => {
2929 // LLVM has a separate type for 64-bit SIMD vectors on X86 called
3030 // `x86_mmx` which is needed for some SIMD operations. As a bit of a
3131 // hack (all SIMD definitions are super unstable anyway) we
3232 // recognize any one-element SIMD vector as "this should be an
3333 // x86_mmx" type. In general there shouldn't be a need for other
3434 // one-element SIMD vectors, so it's assumed this won't clash with
3535 // much else.
36- let use_x86_mmx = layout. fields . count ( ) == 1 &&
37- layout. size . bits ( ) == 64 &&
36+ let use_x86_mmx = count == 1 && layout. size . bits ( ) == 64 &&
3837 ( ccx. sess ( ) . target . target . arch == "x86" ||
3938 ccx. sess ( ) . target . target . arch == "x86_64" ) ;
4039 if use_x86_mmx {
4140 return Type :: x86_mmx ( ccx)
4241 } else {
43- return Type :: vector ( & layout. field ( ccx, 0 ) . llvm_type ( ccx ) ,
44- layout . fields . count ( ) as u64 ) ;
42+ let element = layout. scalar_llvm_type_at ( ccx, element , Size :: from_bytes ( 0 ) ) ;
43+ return Type :: vector ( & element , count ) ;
4544 }
4645 }
4746 layout:: Abi :: ScalarPair ( ..) => {
@@ -198,6 +197,8 @@ pub trait LayoutLlvmExt<'tcx> {
198197 fn is_llvm_scalar_pair < ' a > ( & self ) -> bool ;
199198 fn llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> Type ;
200199 fn immediate_llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> Type ;
200+ fn scalar_llvm_type_at < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ,
201+ scalar : & layout:: Scalar , offset : Size ) -> Type ;
201202 fn scalar_pair_element_llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ,
202203 index : usize ) -> Type ;
203204 fn llvm_field_index ( & self , index : usize ) -> u64 ;
@@ -210,7 +211,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
210211 match self . abi {
211212 layout:: Abi :: Uninhabited |
212213 layout:: Abi :: Scalar ( _) |
213- layout:: Abi :: Vector => true ,
214+ layout:: Abi :: Vector { .. } => true ,
214215 layout:: Abi :: ScalarPair ( ..) => false ,
215216 layout:: Abi :: Aggregate { .. } => self . is_zst ( )
216217 }
@@ -221,7 +222,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
221222 layout:: Abi :: ScalarPair ( ..) => true ,
222223 layout:: Abi :: Uninhabited |
223224 layout:: Abi :: Scalar ( _) |
224- layout:: Abi :: Vector |
225+ layout:: Abi :: Vector { .. } |
225226 layout:: Abi :: Aggregate { .. } => false
226227 }
227228 }
@@ -244,34 +245,19 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
244245 if let Some ( & llty) = ccx. scalar_lltypes ( ) . borrow ( ) . get ( & self . ty ) {
245246 return llty;
246247 }
247- let llty = match scalar. value {
248- layout:: Int ( i, _) => Type :: from_integer ( ccx, i) ,
249- layout:: F32 => Type :: f32 ( ccx) ,
250- layout:: F64 => Type :: f64 ( ccx) ,
251- layout:: Pointer => {
252- let pointee = match self . ty . sty {
253- ty:: TyRef ( _, ty:: TypeAndMut { ty, .. } ) |
254- ty:: TyRawPtr ( ty:: TypeAndMut { ty, .. } ) => {
255- ccx. layout_of ( ty) . llvm_type ( ccx)
256- }
257- ty:: TyAdt ( def, _) if def. is_box ( ) => {
258- ccx. layout_of ( self . ty . boxed_ty ( ) ) . llvm_type ( ccx)
259- }
260- ty:: TyFnPtr ( sig) => {
261- let sig = ccx. tcx ( ) . erase_late_bound_regions_and_normalize ( & sig) ;
262- FnType :: new ( ccx, sig, & [ ] ) . llvm_type ( ccx)
263- }
264- _ => {
265- // If we know the alignment, pick something better than i8.
266- if let Some ( pointee) = self . pointee_info_at ( ccx, Size :: from_bytes ( 0 ) ) {
267- Type :: pointee_for_abi_align ( ccx, pointee. align )
268- } else {
269- Type :: i8 ( ccx)
270- }
271- }
272- } ;
273- pointee. ptr_to ( )
248+ let llty = match self . ty . sty {
249+ ty:: TyRef ( _, ty:: TypeAndMut { ty, .. } ) |
250+ ty:: TyRawPtr ( ty:: TypeAndMut { ty, .. } ) => {
251+ ccx. layout_of ( ty) . llvm_type ( ccx) . ptr_to ( )
252+ }
253+ ty:: TyAdt ( def, _) if def. is_box ( ) => {
254+ ccx. layout_of ( self . ty . boxed_ty ( ) ) . llvm_type ( ccx) . ptr_to ( )
274255 }
256+ ty:: TyFnPtr ( sig) => {
257+ let sig = ccx. tcx ( ) . erase_late_bound_regions_and_normalize ( & sig) ;
258+ FnType :: new ( ccx, sig, & [ ] ) . llvm_type ( ccx) . ptr_to ( )
259+ }
260+ _ => self . scalar_llvm_type_at ( ccx, scalar, Size :: from_bytes ( 0 ) )
275261 } ;
276262 ccx. scalar_lltypes ( ) . borrow_mut ( ) . insert ( self . ty , llty) ;
277263 return llty;
@@ -325,6 +311,24 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
325311 self . llvm_type ( ccx)
326312 }
327313
314+ fn scalar_llvm_type_at < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ,
315+ scalar : & layout:: Scalar , offset : Size ) -> Type {
316+ match scalar. value {
317+ layout:: Int ( i, _) => Type :: from_integer ( ccx, i) ,
318+ layout:: F32 => Type :: f32 ( ccx) ,
319+ layout:: F64 => Type :: f64 ( ccx) ,
320+ layout:: Pointer => {
321+ // If we know the alignment, pick something better than i8.
322+ let pointee = if let Some ( pointee) = self . pointee_info_at ( ccx, offset) {
323+ Type :: pointee_for_abi_align ( ccx, pointee. align )
324+ } else {
325+ Type :: i8 ( ccx)
326+ } ;
327+ pointee. ptr_to ( )
328+ }
329+ }
330+ }
331+
328332 fn scalar_pair_element_llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ,
329333 index : usize ) -> Type {
330334 // HACK(eddyb) special-case fat pointers until LLVM removes
@@ -358,25 +362,12 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
358362 return Type :: i1 ( ccx) ;
359363 }
360364
361- match scalar. value {
362- layout:: Int ( i, _) => Type :: from_integer ( ccx, i) ,
363- layout:: F32 => Type :: f32 ( ccx) ,
364- layout:: F64 => Type :: f64 ( ccx) ,
365- layout:: Pointer => {
366- // If we know the alignment, pick something better than i8.
367- let offset = if index == 0 {
368- Size :: from_bytes ( 0 )
369- } else {
370- a. value . size ( ccx) . abi_align ( b. value . align ( ccx) )
371- } ;
372- let pointee = if let Some ( pointee) = self . pointee_info_at ( ccx, offset) {
373- Type :: pointee_for_abi_align ( ccx, pointee. align )
374- } else {
375- Type :: i8 ( ccx)
376- } ;
377- pointee. ptr_to ( )
378- }
379- }
365+ let offset = if index == 0 {
366+ Size :: from_bytes ( 0 )
367+ } else {
368+ a. value . size ( ccx) . abi_align ( b. value . align ( ccx) )
369+ } ;
370+ self . scalar_llvm_type_at ( ccx, scalar, offset)
380371 }
381372
382373 fn llvm_field_index ( & self , index : usize ) -> u64 {
0 commit comments