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