@@ -92,6 +92,7 @@ class DataLayout {
92
92
// / The function pointer alignment is a multiple of the function alignment.
93
93
MultipleOfFunctionAlign,
94
94
};
95
+
95
96
private:
96
97
bool BigEndian = false ;
97
98
@@ -324,16 +325,38 @@ class DataLayout {
324
325
// / the backends/clients are updated.
325
326
Align getPointerPrefAlignment (unsigned AS = 0 ) const ;
326
327
327
- // / Layout pointer size in bytes, rounded up to a whole
328
- // / number of bytes.
328
+ // / The pointer representation size in bytes, rounded up to a whole number of
329
+ // / bytes. The difference between this function and getAddressSize() is that
330
+ // / this one returns the size of the entire pointer representation (including
331
+ // / metadata bits for fat pointers) and the latter only returns the number of
332
+ // / address bits.
333
+ // / \sa DataLayout::getAddressSizeInBits
329
334
// / FIXME: The defaults need to be removed once all of
330
335
// / the backends/clients are updated.
331
336
unsigned getPointerSize (unsigned AS = 0 ) const ;
332
337
333
- // Index size in bytes used for address calculation,
334
- // / rounded up to a whole number of bytes.
338
+ // / The index size in bytes used for address calculation, rounded up to a
339
+ // / whole number of bytes. This not only defines the size used in
340
+ // / getelementptr operations, but also the size of addresses in this \p AS.
341
+ // / For example, a 64-bit CHERI-enabled target has 128-bit pointers of which
342
+ // / only 64 are used to represent the address and the remaining ones are used
343
+ // / for metadata such as bounds and access permissions. In this case
344
+ // / getPointerSize() returns 16, but getIndexSize() returns 8.
345
+ // / To help with code understanding, the alias getAddressSize() can be used
346
+ // / instead of getIndexSize() to clarify that an address width is needed.
335
347
unsigned getIndexSize (unsigned AS) const ;
336
348
349
+ // / The integral size of a pointer in a given address space in bytes, which
350
+ // / is defined to be the same as getIndexSize(). This exists as a separate
351
+ // / function to make it clearer when reading code that the size of an address
352
+ // / is being requested. While targets exist where index size and the
353
+ // / underlying address width are not identical (e.g. AMDGPU fat pointers with
354
+ // / 48-bit addresses and 32-bit offsets indexing), there is currently no need
355
+ // / to differentiate these properties in LLVM.
356
+ // / \sa DataLayout::getIndexSize
357
+ // / \sa DataLayout::getAddressSizeInBits
358
+ unsigned getAddressSize (unsigned AS) const { return getIndexSize (AS); }
359
+
337
360
// / Return the address spaces containing non-integral pointers. Pointers in
338
361
// / this address space don't have a well-defined bitwise representation.
339
362
SmallVector<unsigned , 8 > getNonIntegralAddressSpaces () const {
@@ -358,29 +381,53 @@ class DataLayout {
358
381
return PTy && isNonIntegralPointerType (PTy);
359
382
}
360
383
361
- // / Layout pointer size, in bits
384
+ // / The size in bits of the pointer representation in a given address space.
385
+ // / This is not necessarily the same as the integer address of a pointer (e.g.
386
+ // / for fat pointers).
387
+ // / \sa DataLayout::getAddressSizeInBits()
362
388
// / FIXME: The defaults need to be removed once all of
363
389
// / the backends/clients are updated.
364
390
unsigned getPointerSizeInBits (unsigned AS = 0 ) const {
365
391
return getPointerSpec (AS).BitWidth ;
366
392
}
367
393
368
- // / Size in bits of index used for address calculation in getelementptr.
394
+ // / The size in bits of indices used for address calculation in getelementptr
395
+ // / and for addresses in the given AS. See getIndexSize() for more
396
+ // / information.
397
+ // / \sa DataLayout::getAddressSizeInBits()
369
398
unsigned getIndexSizeInBits (unsigned AS) const {
370
399
return getPointerSpec (AS).IndexBitWidth ;
371
400
}
372
401
373
- // / Layout pointer size, in bits, based on the type. If this function is
402
+ // / The size in bits of an address in for the given AS. This is defined to
403
+ // / return the same value as getIndexSizeInBits() since there is currently no
404
+ // / target that requires these two properties to have different values. See
405
+ // / getIndexSize() for more information.
406
+ // / \sa DataLayout::getIndexSizeInBits()
407
+ unsigned getAddressSizeInBits (unsigned AS) const {
408
+ return getIndexSizeInBits (AS);
409
+ }
410
+
411
+ // / The pointer representation size in bits for this type. If this function is
374
412
// / called with a pointer type, then the type size of the pointer is returned.
375
413
// / If this function is called with a vector of pointers, then the type size
376
414
// / of the pointer is returned. This should only be called with a pointer or
377
415
// / vector of pointers.
378
416
unsigned getPointerTypeSizeInBits (Type *) const ;
379
417
380
- // / Layout size of the index used in GEP calculation.
418
+ // / The size in bits of the index used in GEP calculation for this type .
381
419
// / The function should be called with pointer or vector of pointers type.
420
+ // / This is defined to return the same value as getAddressSizeInBits(),
421
+ // / but separate functions exist for code clarity.
382
422
unsigned getIndexTypeSizeInBits (Type *Ty) const ;
383
423
424
+ // / The size in bits of an address for this type.
425
+ // / This is defined to return the same value as getIndexTypeSizeInBits(),
426
+ // / but separate functions exist for code clarity.
427
+ unsigned getAddressSizeInBits (Type *Ty) const {
428
+ return getIndexTypeSizeInBits (Ty);
429
+ }
430
+
384
431
unsigned getPointerTypeSize (Type *Ty) const {
385
432
return getPointerTypeSizeInBits (Ty) / 8 ;
386
433
}
@@ -515,15 +562,21 @@ class DataLayout {
515
562
// / are set.
516
563
unsigned getLargestLegalIntTypeSizeInBits () const ;
517
564
518
- // / Returns the type of a GEP index in AddressSpace.
565
+ // / Returns the type of a GEP index in \p AddressSpace.
519
566
// / If it was not specified explicitly, it will be the integer type of the
520
567
// / pointer width - IntPtrType.
521
568
IntegerType *getIndexType (LLVMContext &C, unsigned AddressSpace) const ;
569
+ // / Returns the type of an address in \p AddressSpace
570
+ IntegerType *getAddressType (LLVMContext &C, unsigned AddressSpace) const {
571
+ return getIndexType (C, AddressSpace);
572
+ }
522
573
523
574
// / Returns the type of a GEP index.
524
575
// / If it was not specified explicitly, it will be the integer type of the
525
576
// / pointer width - IntPtrType.
526
577
Type *getIndexType (Type *PtrTy) const ;
578
+ // / Returns the type of an address in \p AddressSpace
579
+ Type *getAddressType (Type *PtrTy) const { return getIndexType (PtrTy); }
527
580
528
581
// / Returns the offset from the beginning of the type for the specified
529
582
// / indices.
0 commit comments