@@ -25,23 +25,22 @@ fn uncached_llvm_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
25
25
-> Type {
26
26
match layout. abi {
27
27
layout:: Abi :: Scalar ( _) => bug ! ( "handled elsewhere" ) ,
28
- layout:: Abi :: Vector => {
28
+ layout:: Abi :: Vector { ref element , count } => {
29
29
// LLVM has a separate type for 64-bit SIMD vectors on X86 called
30
30
// `x86_mmx` which is needed for some SIMD operations. As a bit of a
31
31
// hack (all SIMD definitions are super unstable anyway) we
32
32
// recognize any one-element SIMD vector as "this should be an
33
33
// x86_mmx" type. In general there shouldn't be a need for other
34
34
// one-element SIMD vectors, so it's assumed this won't clash with
35
35
// 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 &&
38
37
( ccx. sess ( ) . target . target . arch == "x86" ||
39
38
ccx. sess ( ) . target . target . arch == "x86_64" ) ;
40
39
if use_x86_mmx {
41
40
return Type :: x86_mmx ( ccx)
42
41
} 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 ) ;
45
44
}
46
45
}
47
46
layout:: Abi :: ScalarPair ( ..) => {
@@ -198,6 +197,8 @@ pub trait LayoutLlvmExt<'tcx> {
198
197
fn is_llvm_scalar_pair < ' a > ( & self ) -> bool ;
199
198
fn llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ) -> Type ;
200
199
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 ;
201
202
fn scalar_pair_element_llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ,
202
203
index : usize ) -> Type ;
203
204
fn llvm_field_index ( & self , index : usize ) -> u64 ;
@@ -210,7 +211,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
210
211
match self . abi {
211
212
layout:: Abi :: Uninhabited |
212
213
layout:: Abi :: Scalar ( _) |
213
- layout:: Abi :: Vector => true ,
214
+ layout:: Abi :: Vector { .. } => true ,
214
215
layout:: Abi :: ScalarPair ( ..) => false ,
215
216
layout:: Abi :: Aggregate { .. } => self . is_zst ( )
216
217
}
@@ -221,7 +222,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
221
222
layout:: Abi :: ScalarPair ( ..) => true ,
222
223
layout:: Abi :: Uninhabited |
223
224
layout:: Abi :: Scalar ( _) |
224
- layout:: Abi :: Vector |
225
+ layout:: Abi :: Vector { .. } |
225
226
layout:: Abi :: Aggregate { .. } => false
226
227
}
227
228
}
@@ -244,34 +245,19 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
244
245
if let Some ( & llty) = ccx. scalar_lltypes ( ) . borrow ( ) . get ( & self . ty ) {
245
246
return llty;
246
247
}
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 ( )
274
255
}
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 ) )
275
261
} ;
276
262
ccx. scalar_lltypes ( ) . borrow_mut ( ) . insert ( self . ty , llty) ;
277
263
return llty;
@@ -325,6 +311,24 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
325
311
self . llvm_type ( ccx)
326
312
}
327
313
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
+
328
332
fn scalar_pair_element_llvm_type < ' a > ( & self , ccx : & CrateContext < ' a , ' tcx > ,
329
333
index : usize ) -> Type {
330
334
// HACK(eddyb) special-case fat pointers until LLVM removes
@@ -358,25 +362,12 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyLayout<'tcx> {
358
362
return Type :: i1 ( ccx) ;
359
363
}
360
364
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)
380
371
}
381
372
382
373
fn llvm_field_index ( & self , index : usize ) -> u64 {
0 commit comments