@@ -221,17 +221,18 @@ impl ReprOptions {
221
221
/// * Cranelift stores the base-2 log of the lane count in a 4 bit integer.
222
222
pub const MAX_SIMD_LANES : u64 = 1 << 0xF ;
223
223
224
- /// Informations relative to a specific address space.
224
+ /// How pointers are represented in a given address space
225
225
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
226
- pub struct AddressSpaceInfo {
226
+ pub struct PointerSpec {
227
227
/// The size of the bitwise representation of the pointer.
228
228
pointer_size : Size ,
229
- /// The ABI alignment requirements for pointers in this address space.
229
+ /// The alignment of pointers for this address space
230
230
pointer_align : AbiAlign ,
231
- /// The preferred alignment specification for pointers in this address space.
232
- pointer_preferred_align : AbiAlign ,
233
- /// The size of the index that used for address calculations on pointers in this address space.
234
- pointer_index : Size ,
231
+ /// The size of the value a pointer can be offset by in this address space.
232
+ pointer_offset : Size ,
233
+ /// Pointers into this address space contain extra metadata
234
+ /// FIXME(workingjubilee): Consider adequately reflecting this in the compiler?
235
+ _is_fat : bool ,
235
236
}
236
237
237
238
/// Parsed [Data layout](https://llvm.org/docs/LangRef.html#data-layout)
@@ -255,15 +256,15 @@ pub struct TargetDataLayout {
255
256
pub vector_align : Vec < ( Size , AbiAlign ) > ,
256
257
257
258
pub default_address_space : AddressSpace ,
258
- pub default_address_space_info : AddressSpaceInfo ,
259
+ pub default_address_space_pointer_spec : PointerSpec ,
259
260
260
- /// The address space informations relative to all the known address spaces.
261
+ /// Address space information of all known address spaces.
261
262
///
262
263
/// # Note
263
264
///
264
- /// This vector does not contain the [`AddressSpaceInfo `] relative to the default address space,
265
- /// which instead lives in [`Self::default_address_space_info `].
266
- address_space_info : Vec < ( AddressSpace , AddressSpaceInfo ) > ,
265
+ /// This vector does not contain the [`PointerSpec `] relative to the default address space,
266
+ /// which instead lives in [`Self::default_address_space_pointer_spec `].
267
+ address_space_info : Vec < ( AddressSpace , PointerSpec ) > ,
267
268
268
269
pub instruction_address_space : AddressSpace ,
269
270
@@ -295,11 +296,11 @@ impl Default for TargetDataLayout {
295
296
( Size :: from_bits( 128 ) , AbiAlign :: new( align( 128 ) ) ) ,
296
297
] ,
297
298
default_address_space : AddressSpace :: ZERO ,
298
- default_address_space_info : AddressSpaceInfo {
299
+ default_address_space_pointer_spec : PointerSpec {
299
300
pointer_size : Size :: from_bits ( 64 ) ,
300
301
pointer_align : AbiAlign :: new ( align ( 64 ) ) ,
301
- pointer_preferred_align : AbiAlign :: new ( align ( 64 ) ) ,
302
- pointer_index : Size :: from_bits ( 64 ) ,
302
+ pointer_offset : Size :: from_bits ( 64 ) ,
303
+ _is_fat : false ,
303
304
} ,
304
305
address_space_info : vec ! [ ] ,
305
306
instruction_address_space : AddressSpace :: ZERO ,
@@ -388,11 +389,18 @@ impl TargetDataLayout {
388
389
[ "f64" , a @ ..] => dl. f64_align = parse_align_seq ( a, "f64" ) ?,
389
390
[ "f128" , a @ ..] => dl. f128_align = parse_align_seq ( a, "f128" ) ?,
390
391
[ p, s, a @ ..] if p. starts_with ( "p" ) => {
391
- let p = p. strip_prefix ( 'p' ) . unwrap ( ) ;
392
+ let mut p = p. strip_prefix ( 'p' ) . unwrap ( ) ;
393
+ let mut _is_fat = false ;
392
394
393
395
// Some targets, such as CHERI, use the 'f' suffix in the p- spec to signal that
394
396
// they use 'fat' pointers. The resulting prefix may look like `pf<addr_space>`.
395
- // However, we currently don't take into account those further specifications:
397
+
398
+ if p. starts_with ( 'f' ) {
399
+ p = p. strip_prefix ( 'f' ) . unwrap ( ) ;
400
+ _is_fat = true ;
401
+ }
402
+
403
+ // However, we currently don't take into account further specifications:
396
404
// an error is emitted instead.
397
405
if p. starts_with ( char:: is_alphabetic) {
398
406
return Err ( TargetDataLayoutErrors :: UnknownPointerSpecification {
@@ -408,14 +416,14 @@ impl TargetDataLayout {
408
416
409
417
let pointer_size = parse_size ( s, "p-" ) ?;
410
418
let pointer_align = parse_align_seq ( a, "p-" ) ?;
411
- let info = AddressSpaceInfo {
412
- pointer_index : pointer_size,
419
+ let info = PointerSpec {
420
+ pointer_offset : pointer_size,
413
421
pointer_size,
414
- pointer_preferred_align : pointer_align,
415
422
pointer_align,
423
+ _is_fat,
416
424
} ;
417
425
if addr_space == default_address_space {
418
- dl. default_address_space_info = info;
426
+ dl. default_address_space_pointer_spec = info;
419
427
} else {
420
428
match dl. address_space_info . iter_mut ( ) . find ( |( a, _) | * a == addr_space) {
421
429
Some ( e) => e. 1 = info,
@@ -425,12 +433,19 @@ impl TargetDataLayout {
425
433
}
426
434
}
427
435
}
428
- [ p, s, a, pr, i] if p. starts_with ( "p" ) => {
429
- let p = p. strip_prefix ( 'p' ) . unwrap ( ) ;
436
+ [ p, s, a, _pr, i] if p. starts_with ( "p" ) => {
437
+ let mut p = p. strip_prefix ( 'p' ) . unwrap ( ) ;
438
+ let mut _is_fat = false ;
430
439
431
440
// Some targets, such as CHERI, use the 'f' suffix in the p- spec to signal that
432
441
// they use 'fat' pointers. The resulting prefix may look like `pf<addr_space>`.
433
- // However, we currently don't take into account those further specifications:
442
+
443
+ if p. starts_with ( 'f' ) {
444
+ p = p. strip_prefix ( 'f' ) . unwrap ( ) ;
445
+ _is_fat = true ;
446
+ }
447
+
448
+ // However, we currently don't take into account further specifications:
434
449
// an error is emitted instead.
435
450
if p. starts_with ( char:: is_alphabetic) {
436
451
return Err ( TargetDataLayoutErrors :: UnknownPointerSpecification {
@@ -444,15 +459,15 @@ impl TargetDataLayout {
444
459
AddressSpace :: ZERO
445
460
} ;
446
461
447
- let info = AddressSpaceInfo {
462
+ let info = PointerSpec {
448
463
pointer_size : parse_size ( s, "p-" ) ?,
449
464
pointer_align : parse_align_str ( a, "p-" ) ?,
450
- pointer_preferred_align : parse_align_str ( pr , "p-" ) ?,
451
- pointer_index : parse_size ( i , "p-" ) ? ,
465
+ pointer_offset : parse_size ( i , "p-" ) ?,
466
+ _is_fat ,
452
467
} ;
453
468
454
469
if addr_space == default_address_space {
455
- dl. default_address_space_info = info;
470
+ dl. default_address_space_pointer_spec = info;
456
471
} else {
457
472
match dl. address_space_info . iter_mut ( ) . find ( |( a, _) | * a == addr_space) {
458
473
Some ( e) => e. 1 = info,
@@ -498,7 +513,7 @@ impl TargetDataLayout {
498
513
}
499
514
}
500
515
501
- // Inherit, if not given, address space informations for specific LLVM elements from the
516
+ // Inherit, if not given, address space information for specific LLVM elements from the
502
517
// default data address space.
503
518
if ( dl. instruction_address_space != dl. default_address_space )
504
519
&& dl
@@ -507,8 +522,10 @@ impl TargetDataLayout {
507
522
. find ( |( a, _) | * a == dl. instruction_address_space )
508
523
. is_none ( )
509
524
{
510
- dl. address_space_info
511
- . push ( ( dl. instruction_address_space , dl. default_address_space_info . clone ( ) ) ) ;
525
+ dl. address_space_info . push ( (
526
+ dl. instruction_address_space ,
527
+ dl. default_address_space_pointer_spec . clone ( ) ,
528
+ ) ) ;
512
529
}
513
530
514
531
Ok ( dl)
@@ -556,7 +573,7 @@ impl TargetDataLayout {
556
573
#[ inline]
557
574
pub fn ptr_sized_integer ( & self ) -> Integer {
558
575
use Integer :: * ;
559
- match self . pointer_index ( ) . bits ( ) {
576
+ match self . pointer_offset ( ) . bits ( ) {
560
577
16 => I16 ,
561
578
32 => I32 ,
562
579
64 => I64 ,
@@ -567,7 +584,7 @@ impl TargetDataLayout {
567
584
#[ inline]
568
585
pub fn ptr_sized_integer_in ( & self , address_space : AddressSpace ) -> Integer {
569
586
use Integer :: * ;
570
- match self . pointer_index_in ( address_space) . bits ( ) {
587
+ match self . pointer_offset_in ( address_space) . bits ( ) {
571
588
16 => I16 ,
572
589
32 => I32 ,
573
590
64 => I64 ,
@@ -595,14 +612,14 @@ impl TargetDataLayout {
595
612
/// Get the pointer size in the default data address space.
596
613
#[ inline]
597
614
pub fn pointer_size ( & self ) -> Size {
598
- self . default_address_space_info . pointer_size
615
+ self . default_address_space_pointer_spec . pointer_size
599
616
}
600
617
601
618
/// Get the pointer size in a specific address space.
602
619
#[ inline]
603
620
pub fn pointer_size_in ( & self , c : AddressSpace ) -> Size {
604
621
if c == self . default_address_space {
605
- return self . default_address_space_info . pointer_size ;
622
+ return self . default_address_space_pointer_spec . pointer_size ;
606
623
}
607
624
608
625
if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
@@ -614,19 +631,19 @@ impl TargetDataLayout {
614
631
615
632
/// Get the pointer index in the default data address space.
616
633
#[ inline]
617
- pub fn pointer_index ( & self ) -> Size {
618
- self . default_address_space_info . pointer_index
634
+ pub fn pointer_offset ( & self ) -> Size {
635
+ self . default_address_space_pointer_spec . pointer_offset
619
636
}
620
637
621
638
/// Get the pointer index in a specific address space.
622
639
#[ inline]
623
- pub fn pointer_index_in ( & self , c : AddressSpace ) -> Size {
640
+ pub fn pointer_offset_in ( & self , c : AddressSpace ) -> Size {
624
641
if c == self . default_address_space {
625
- return self . default_address_space_info . pointer_index ;
642
+ return self . default_address_space_pointer_spec . pointer_offset ;
626
643
}
627
644
628
645
if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
629
- e. 1 . pointer_index
646
+ e. 1 . pointer_offset
630
647
} else {
631
648
panic ! ( "Use of unknown address space {c:?}" ) ;
632
649
}
@@ -635,14 +652,14 @@ impl TargetDataLayout {
635
652
/// Get the pointer alignment in the default data address space.
636
653
#[ inline]
637
654
pub fn pointer_align ( & self ) -> AbiAlign {
638
- self . default_address_space_info . pointer_align
655
+ self . default_address_space_pointer_spec . pointer_align
639
656
}
640
657
641
658
/// Get the pointer alignment in a specific address space.
642
659
#[ inline]
643
660
pub fn pointer_align_in ( & self , c : AddressSpace ) -> AbiAlign {
644
661
if c == self . default_address_space {
645
- return self . default_address_space_info . pointer_align ;
662
+ return self . default_address_space_pointer_spec . pointer_align ;
646
663
}
647
664
648
665
if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
@@ -651,26 +668,6 @@ impl TargetDataLayout {
651
668
panic ! ( "Use of unknown address space {c:?}" ) ;
652
669
}
653
670
}
654
-
655
- /// Get the preferred pointer alignment in the default data address space.
656
- #[ inline]
657
- pub fn pointer_preferred_align ( & self ) -> AbiAlign {
658
- self . default_address_space_info . pointer_preferred_align
659
- }
660
-
661
- /// Get the preferred pointer alignment in a specific address space.
662
- #[ inline]
663
- pub fn pointer_preferred_align_in ( & self , c : AddressSpace ) -> AbiAlign {
664
- if c == self . default_address_space {
665
- return self . default_address_space_info . pointer_preferred_align ;
666
- }
667
-
668
- if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
669
- e. 1 . pointer_preferred_align
670
- } else {
671
- panic ! ( "Use of unknown address space {c:?}" ) ;
672
- }
673
- }
674
671
}
675
672
676
673
pub trait HasDataLayout {
0 commit comments