@@ -221,17 +221,18 @@ impl ReprOptions {
221221/// * Cranelift stores the base-2 log of the lane count in a 4 bit integer.
222222pub const MAX_SIMD_LANES : u64 = 1 << 0xF ;
223223
224- /// Informations relative to a specific address space.
224+ /// How pointers are represented in a given address space
225225#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
226- pub struct AddressSpaceInfo {
226+ pub struct PointerSpec {
227227 /// The size of the bitwise representation of the pointer.
228228 pointer_size : Size ,
229- /// The ABI alignment requirements for pointers in this address space.
229+ /// The alignment of pointers for this address space
230230 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 ,
235236}
236237
237238/// Parsed [Data layout](https://llvm.org/docs/LangRef.html#data-layout)
@@ -255,15 +256,15 @@ pub struct TargetDataLayout {
255256 pub vector_align : Vec < ( Size , AbiAlign ) > ,
256257
257258 pub default_address_space : AddressSpace ,
258- pub default_address_space_info : AddressSpaceInfo ,
259+ pub default_address_space_pointer_spec : PointerSpec ,
259260
260- /// The address space informations relative to all the known address spaces.
261+ /// Address space information of all known address spaces.
261262 ///
262263 /// # Note
263264 ///
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 ) > ,
267268
268269 pub instruction_address_space : AddressSpace ,
269270
@@ -295,11 +296,11 @@ impl Default for TargetDataLayout {
295296 ( Size :: from_bits( 128 ) , AbiAlign :: new( align( 128 ) ) ) ,
296297 ] ,
297298 default_address_space : AddressSpace :: ZERO ,
298- default_address_space_info : AddressSpaceInfo {
299+ default_address_space_pointer_spec : PointerSpec {
299300 pointer_size : Size :: from_bits ( 64 ) ,
300301 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 ,
303304 } ,
304305 address_space_info : vec ! [ ] ,
305306 instruction_address_space : AddressSpace :: ZERO ,
@@ -388,11 +389,18 @@ impl TargetDataLayout {
388389 [ "f64" , a @ ..] => dl. f64_align = parse_align_seq ( a, "f64" ) ?,
389390 [ "f128" , a @ ..] => dl. f128_align = parse_align_seq ( a, "f128" ) ?,
390391 [ 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 ;
392394
393395 // Some targets, such as CHERI, use the 'f' suffix in the p- spec to signal that
394396 // 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:
396404 // an error is emitted instead.
397405 if p. starts_with ( char:: is_alphabetic) {
398406 return Err ( TargetDataLayoutErrors :: UnknownPointerSpecification {
@@ -408,14 +416,14 @@ impl TargetDataLayout {
408416
409417 let pointer_size = parse_size ( s, "p-" ) ?;
410418 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,
413421 pointer_size,
414- pointer_preferred_align : pointer_align,
415422 pointer_align,
423+ _is_fat,
416424 } ;
417425 if addr_space == default_address_space {
418- dl. default_address_space_info = info;
426+ dl. default_address_space_pointer_spec = info;
419427 } else {
420428 match dl. address_space_info . iter_mut ( ) . find ( |( a, _) | * a == addr_space) {
421429 Some ( e) => e. 1 = info,
@@ -425,12 +433,19 @@ impl TargetDataLayout {
425433 }
426434 }
427435 }
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 ;
430439
431440 // Some targets, such as CHERI, use the 'f' suffix in the p- spec to signal that
432441 // 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:
434449 // an error is emitted instead.
435450 if p. starts_with ( char:: is_alphabetic) {
436451 return Err ( TargetDataLayoutErrors :: UnknownPointerSpecification {
@@ -444,15 +459,15 @@ impl TargetDataLayout {
444459 AddressSpace :: ZERO
445460 } ;
446461
447- let info = AddressSpaceInfo {
462+ let info = PointerSpec {
448463 pointer_size : parse_size ( s, "p-" ) ?,
449464 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 ,
452467 } ;
453468
454469 if addr_space == default_address_space {
455- dl. default_address_space_info = info;
470+ dl. default_address_space_pointer_spec = info;
456471 } else {
457472 match dl. address_space_info . iter_mut ( ) . find ( |( a, _) | * a == addr_space) {
458473 Some ( e) => e. 1 = info,
@@ -498,7 +513,7 @@ impl TargetDataLayout {
498513 }
499514 }
500515
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
502517 // default data address space.
503518 if ( dl. instruction_address_space != dl. default_address_space )
504519 && dl
@@ -507,8 +522,10 @@ impl TargetDataLayout {
507522 . find ( |( a, _) | * a == dl. instruction_address_space )
508523 . is_none ( )
509524 {
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+ ) ) ;
512529 }
513530
514531 Ok ( dl)
@@ -556,7 +573,7 @@ impl TargetDataLayout {
556573 #[ inline]
557574 pub fn ptr_sized_integer ( & self ) -> Integer {
558575 use Integer :: * ;
559- match self . pointer_index ( ) . bits ( ) {
576+ match self . pointer_offset ( ) . bits ( ) {
560577 16 => I16 ,
561578 32 => I32 ,
562579 64 => I64 ,
@@ -567,7 +584,7 @@ impl TargetDataLayout {
567584 #[ inline]
568585 pub fn ptr_sized_integer_in ( & self , address_space : AddressSpace ) -> Integer {
569586 use Integer :: * ;
570- match self . pointer_index_in ( address_space) . bits ( ) {
587+ match self . pointer_offset_in ( address_space) . bits ( ) {
571588 16 => I16 ,
572589 32 => I32 ,
573590 64 => I64 ,
@@ -595,14 +612,14 @@ impl TargetDataLayout {
595612 /// Get the pointer size in the default data address space.
596613 #[ inline]
597614 pub fn pointer_size ( & self ) -> Size {
598- self . default_address_space_info . pointer_size
615+ self . default_address_space_pointer_spec . pointer_size
599616 }
600617
601618 /// Get the pointer size in a specific address space.
602619 #[ inline]
603620 pub fn pointer_size_in ( & self , c : AddressSpace ) -> Size {
604621 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 ;
606623 }
607624
608625 if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
@@ -614,19 +631,19 @@ impl TargetDataLayout {
614631
615632 /// Get the pointer index in the default data address space.
616633 #[ 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
619636 }
620637
621638 /// Get the pointer index in a specific address space.
622639 #[ inline]
623- pub fn pointer_index_in ( & self , c : AddressSpace ) -> Size {
640+ pub fn pointer_offset_in ( & self , c : AddressSpace ) -> Size {
624641 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 ;
626643 }
627644
628645 if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
629- e. 1 . pointer_index
646+ e. 1 . pointer_offset
630647 } else {
631648 panic ! ( "Use of unknown address space {c:?}" ) ;
632649 }
@@ -635,14 +652,14 @@ impl TargetDataLayout {
635652 /// Get the pointer alignment in the default data address space.
636653 #[ inline]
637654 pub fn pointer_align ( & self ) -> AbiAlign {
638- self . default_address_space_info . pointer_align
655+ self . default_address_space_pointer_spec . pointer_align
639656 }
640657
641658 /// Get the pointer alignment in a specific address space.
642659 #[ inline]
643660 pub fn pointer_align_in ( & self , c : AddressSpace ) -> AbiAlign {
644661 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 ;
646663 }
647664
648665 if let Some ( e) = self . address_space_info . iter ( ) . find ( |( a, _) | a == & c) {
@@ -651,26 +668,6 @@ impl TargetDataLayout {
651668 panic ! ( "Use of unknown address space {c:?}" ) ;
652669 }
653670 }
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- }
674671}
675672
676673pub trait HasDataLayout {
0 commit comments