| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef LLVM_IR_DATALAYOUT_H |
| 20 |
#define LLVM_IR_DATALAYOUT_H |
| 21 |
|
| 22 |
#include "llvm/ADT/APInt.h" |
| 23 |
#include "llvm/ADT/ArrayRef.h" |
| 24 |
#include "llvm/ADT/STLExtras.h" |
| 25 |
#include "llvm/ADT/SmallVector.h" |
| 26 |
#include "llvm/ADT/StringRef.h" |
| 27 |
#include "llvm/IR/DerivedTypes.h" |
| 28 |
#include "llvm/IR/Type.h" |
| 29 |
#include "llvm/Support/Casting.h" |
| 30 |
#include "llvm/Support/ErrorHandling.h" |
| 31 |
#include "llvm/Support/MathExtras.h" |
| 32 |
#include "llvm/Support/Alignment.h" |
| 33 |
#include "llvm/Support/TrailingObjects.h" |
| 34 |
#include "llvm/Support/TypeSize.h" |
| 35 |
#include <cassert> |
| 36 |
#include <cstdint> |
| 37 |
#include <string> |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
using LLVMTargetDataRef = struct LLVMOpaqueTargetData *; |
| 42 |
|
| 43 |
namespace llvm { |
| 44 |
|
| 45 |
class GlobalVariable; |
| 46 |
class LLVMContext; |
| 47 |
class Module; |
| 48 |
class StructLayout; |
| 49 |
class Triple; |
| 50 |
class Value; |
| 51 |
|
| 52 |
|
| 53 |
enum AlignTypeEnum { |
| 54 |
INVALID_ALIGN = 0, |
| 55 |
INTEGER_ALIGN = 'i', |
| 56 |
VECTOR_ALIGN = 'v', |
| 57 |
FLOAT_ALIGN = 'f', |
| 58 |
AGGREGATE_ALIGN = 'a' |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
struct LayoutAlignElem { |
| 74 |
|
| 75 |
unsigned AlignType : 8; |
| 76 |
unsigned TypeBitWidth : 24; |
| 77 |
Align ABIAlign; |
| 78 |
Align PrefAlign; |
| 79 |
|
| 80 |
static LayoutAlignElem get(AlignTypeEnum align_type, Align abi_align, |
| 81 |
Align pref_align, uint32_t bit_width); |
| 82 |
|
| 83 |
bool operator==(const LayoutAlignElem &rhs) const; |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
struct PointerAlignElem { |
| 93 |
Align ABIAlign; |
| 94 |
Align PrefAlign; |
| 95 |
uint32_t TypeBitWidth; |
| 96 |
uint32_t AddressSpace; |
| 97 |
uint32_t IndexBitWidth; |
| 98 |
|
| 99 |
|
| 100 |
static PointerAlignElem getInBits(uint32_t AddressSpace, Align ABIAlign, |
| 101 |
Align PrefAlign, uint32_t TypeBitWidth, |
| 102 |
uint32_t IndexBitWidth); |
| 103 |
|
| 104 |
bool operator==(const PointerAlignElem &rhs) const; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
class DataLayout { |
| 114 |
public: |
| 115 |
enum class FunctionPtrAlignType { |
| 116 |
|
| 117 |
Independent, |
| 118 |
|
| 119 |
MultipleOfFunctionAlign, |
| 120 |
}; |
| 121 |
private: |
| 122 |
|
| 123 |
bool BigEndian; |
| 124 |
|
| 125 |
unsigned AllocaAddrSpace; |
| 126 |
MaybeAlign StackNaturalAlign; |
| 127 |
unsigned ProgramAddrSpace; |
| 128 |
unsigned DefaultGlobalsAddrSpace; |
| 129 |
|
| 130 |
MaybeAlign FunctionPtrAlign; |
| 131 |
FunctionPtrAlignType TheFunctionPtrAlignType; |
| 132 |
|
| 133 |
enum ManglingModeT { |
| 134 |
MM_None, |
| 135 |
MM_ELF, |
| 136 |
MM_MachO, |
| 137 |
MM_WinCOFF, |
| 138 |
MM_WinCOFFX86, |
| 139 |
MM_GOFF, |
| 140 |
MM_Mips, |
| 141 |
MM_XCOFF |
| 142 |
}; |
| 143 |
ManglingModeT ManglingMode; |
| 144 |
|
| 145 |
SmallVector<unsigned char, 8> LegalIntWidths; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
using AlignmentsTy = SmallVector<LayoutAlignElem, 16>; |
| 150 |
AlignmentsTy Alignments; |
| 151 |
|
| 152 |
AlignmentsTy::const_iterator |
| 153 |
findAlignmentLowerBound(AlignTypeEnum AlignType, uint32_t BitWidth) const { |
| 154 |
return const_cast<DataLayout *>(this)->findAlignmentLowerBound(AlignType, |
| 155 |
BitWidth); |
| 156 |
} |
| 157 |
|
| 158 |
AlignmentsTy::iterator |
| 159 |
findAlignmentLowerBound(AlignTypeEnum AlignType, uint32_t BitWidth); |
| 160 |
|
| 161 |
|
| 162 |
std::string StringRepresentation; |
| 163 |
|
| 164 |
using PointersTy = SmallVector<PointerAlignElem, 8>; |
| 165 |
PointersTy Pointers; |
| 166 |
|
| 167 |
const PointerAlignElem &getPointerAlignElem(uint32_t AddressSpace) const; |
| 168 |
|
| 169 |
|
| 170 |
mutable void *LayoutMap = nullptr; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
SmallVector<unsigned, 8> NonIntegralAddressSpaces; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
Error setAlignment(AlignTypeEnum align_type, Align abi_align, |
| 179 |
Align pref_align, uint32_t bit_width); |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
Error setPointerAlignmentInBits(uint32_t AddrSpace, Align ABIAlign, |
| 184 |
Align PrefAlign, uint32_t TypeBitWidth, |
| 185 |
uint32_t IndexBitWidth); |
| 186 |
|
| 187 |
|
| 188 |
Align getIntegerAlignment(uint32_t BitWidth, bool abi_or_pref) const; |
| 189 |
|
| 190 |
|
| 191 |
Align getAlignment(Type *Ty, bool abi_or_pref) const; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
Error parseSpecifier(StringRef Desc); |
| 196 |
|
| 197 |
|
| 198 |
void clear(); |
| 199 |
|
| 200 |
public: |
| 201 |
|
| 202 |
explicit DataLayout(StringRef LayoutDescription) { |
| 203 |
reset(LayoutDescription); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
explicit DataLayout(const Module *M); |
| 208 |
|
| 209 |
DataLayout(const DataLayout &DL) { *this = DL; } |
| 210 |
|
| 211 |
~DataLayout(); |
| 212 |
|
| 213 |
DataLayout &operator=(const DataLayout &DL) { |
| 214 |
clear(); |
| 215 |
StringRepresentation = DL.StringRepresentation; |
| 216 |
BigEndian = DL.isBigEndian(); |
| 217 |
AllocaAddrSpace = DL.AllocaAddrSpace; |
| 218 |
StackNaturalAlign = DL.StackNaturalAlign; |
| 219 |
FunctionPtrAlign = DL.FunctionPtrAlign; |
| 220 |
TheFunctionPtrAlignType = DL.TheFunctionPtrAlignType; |
| 221 |
ProgramAddrSpace = DL.ProgramAddrSpace; |
| 222 |
DefaultGlobalsAddrSpace = DL.DefaultGlobalsAddrSpace; |
| 223 |
ManglingMode = DL.ManglingMode; |
| 224 |
LegalIntWidths = DL.LegalIntWidths; |
| 225 |
Alignments = DL.Alignments; |
| 226 |
Pointers = DL.Pointers; |
| 227 |
NonIntegralAddressSpaces = DL.NonIntegralAddressSpaces; |
| 228 |
return *this; |
| 229 |
} |
| 230 |
|
| 231 |
bool operator==(const DataLayout &Other) const; |
| 232 |
bool operator!=(const DataLayout &Other) const { return !(*this == Other); } |
| 233 |
|
| 234 |
void init(const Module *M); |
| 235 |
|
| 236 |
|
| 237 |
void reset(StringRef LayoutDescription); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
static Expected<DataLayout> parse(StringRef LayoutDescription); |
| 242 |
|
| 243 |
|
| 244 |
bool isLittleEndian() const { return !BigEndian; } |
| 245 |
bool isBigEndian() const { return BigEndian; } |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
const std::string &getStringRepresentation() const { |
| 253 |
return StringRepresentation; |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
bool isDefault() const { return StringRepresentation.empty(); } |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
bool isLegalInteger(uint64_t Width) const { |
| 267 |
return llvm::is_contained(LegalIntWidths, Width); |
| 268 |
} |
| 269 |
|
| 270 |
bool isIllegalInteger(uint64_t Width) const { return !isLegalInteger(Width); } |
| 271 |
|
| 272 |
|
| 273 |
bool exceedsNaturalStackAlignment(Align Alignment) const { |
| 274 |
return StackNaturalAlign && (Alignment > *StackNaturalAlign); |
| 275 |
} |
| 276 |
|
| 277 |
Align getStackAlignment() const { |
| 278 |
assert(StackNaturalAlign && "StackNaturalAlign must be defined"); |
| 279 |
return *StackNaturalAlign; |
| 280 |
} |
| 281 |
|
| 282 |
unsigned getAllocaAddrSpace() const { return AllocaAddrSpace; } |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
MaybeAlign getFunctionPtrAlign() const { return FunctionPtrAlign; } |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
FunctionPtrAlignType getFunctionPtrAlignType() const { |
| 292 |
return TheFunctionPtrAlignType; |
| 293 |
} |
| 294 |
|
| 295 |
unsigned getProgramAddressSpace() const { return ProgramAddrSpace; } |
| 296 |
unsigned getDefaultGlobalsAddressSpace() const { |
| 297 |
return DefaultGlobalsAddrSpace; |
| 298 |
} |
| 299 |
|
| 300 |
bool hasMicrosoftFastStdCallMangling() const { |
| 301 |
return ManglingMode == MM_WinCOFFX86; |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
bool doNotMangleLeadingQuestionMark() const { |
| 307 |
return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86; |
| 308 |
} |
| 309 |
|
| 310 |
bool hasLinkerPrivateGlobalPrefix() const { return ManglingMode == MM_MachO; } |
| 311 |
|
| 312 |
StringRef getLinkerPrivateGlobalPrefix() const { |
| 313 |
if (ManglingMode == MM_MachO) |
| 314 |
return "l"; |
| 315 |
return ""; |
| 316 |
} |
| 317 |
|
| 318 |
char getGlobalPrefix() const { |
| 319 |
switch (ManglingMode) { |
| 320 |
case MM_None: |
| 321 |
case MM_ELF: |
| 322 |
case MM_GOFF: |
| 323 |
case MM_Mips: |
| 324 |
case MM_WinCOFF: |
| 325 |
case MM_XCOFF: |
| 326 |
return '\0'; |
| 327 |
case MM_MachO: |
| 328 |
case MM_WinCOFFX86: |
| 329 |
return '_'; |
| 330 |
} |
| 331 |
llvm_unreachable("invalid mangling mode"); |
| 332 |
} |
| 333 |
|
| 334 |
StringRef getPrivateGlobalPrefix() const { |
| 335 |
switch (ManglingMode) { |
| 336 |
case MM_None: |
| 337 |
return ""; |
| 338 |
case MM_ELF: |
| 339 |
case MM_WinCOFF: |
| 340 |
return ".L"; |
| 341 |
case MM_GOFF: |
| 342 |
return "@"; |
| 343 |
case MM_Mips: |
| 344 |
return "$"; |
| 345 |
case MM_MachO: |
| 346 |
case MM_WinCOFFX86: |
| 347 |
return "L"; |
| 348 |
case MM_XCOFF: |
| 349 |
return "L.."; |
| 350 |
} |
| 351 |
llvm_unreachable("invalid mangling mode"); |
| 352 |
} |
| 353 |
|
| 354 |
static const char *getManglingComponent(const Triple &T); |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
bool fitsInLegalInteger(unsigned Width) const { |
| 362 |
for (unsigned LegalIntWidth : LegalIntWidths) |
| 363 |
if (Width <= LegalIntWidth) |
| 364 |
return true; |
| 365 |
return false; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
Align getPointerABIAlignment(unsigned AS) const; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
Align getPointerPrefAlignment(unsigned AS = 0) const; |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
unsigned getPointerSize(unsigned AS = 0) const; |
| 381 |
|
| 382 |
|
| 383 |
unsigned getMaxIndexSize() const; |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
unsigned getIndexSize(unsigned AS) const; |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
ArrayRef<unsigned> getNonIntegralAddressSpaces() const { |
| 392 |
return NonIntegralAddressSpaces; |
| 393 |
} |
| 394 |
|
| 395 |
bool isNonIntegralAddressSpace(unsigned AddrSpace) const { |
| 396 |
ArrayRef<unsigned> NonIntegralSpaces = getNonIntegralAddressSpaces(); |
| 397 |
return is_contained(NonIntegralSpaces, AddrSpace); |
| 398 |
} |
| 399 |
|
| 400 |
bool isNonIntegralPointerType(PointerType *PT) const { |
| 401 |
return isNonIntegralAddressSpace(PT->getAddressSpace()); |
| 402 |
} |
| 403 |
|
| 404 |
bool isNonIntegralPointerType(Type *Ty) const { |
| 405 |
auto *PTy = dyn_cast<PointerType>(Ty); |
| 406 |
return PTy && isNonIntegralPointerType(PTy); |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
unsigned getPointerSizeInBits(unsigned AS = 0) const { |
| 413 |
return getPointerAlignElem(AS).TypeBitWidth; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
unsigned getMaxIndexSizeInBits() const { |
| 418 |
return getMaxIndexSize() * 8; |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
unsigned getIndexSizeInBits(unsigned AS) const { |
| 423 |
return getPointerAlignElem(AS).IndexBitWidth; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
unsigned getPointerTypeSizeInBits(Type *) const; |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
unsigned getIndexTypeSizeInBits(Type *Ty) const; |
| 436 |
|
| 437 |
unsigned getPointerTypeSize(Type *Ty) const { |
| 438 |
return getPointerTypeSizeInBits(Ty) / 8; |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
TypeSize getTypeSizeInBits(Type *Ty) const; |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
TypeSize getTypeStoreSize(Type *Ty) const { |
| 475 |
TypeSize BaseSize = getTypeSizeInBits(Ty); |
| 476 |
return {divideCeil(BaseSize.getKnownMinSize(), 8), BaseSize.isScalable()}; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
TypeSize getTypeStoreSizeInBits(Type *Ty) const { |
| 487 |
return 8 * getTypeStoreSize(Ty); |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
bool typeSizeEqualsStoreSize(Type *Ty) const { |
| 495 |
return getTypeSizeInBits(Ty) == getTypeStoreSizeInBits(Ty); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
TypeSize getTypeAllocSize(Type *Ty) const { |
| 507 |
|
| 508 |
return alignTo(getTypeStoreSize(Ty), getABITypeAlignment(Ty)); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
TypeSize getTypeAllocSizeInBits(Type *Ty) const { |
| 520 |
return 8 * getTypeAllocSize(Ty); |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
uint64_t getABITypeAlignment(Type *Ty) const; |
| 526 |
|
| 527 |
|
| 528 |
Align getABITypeAlign(Type *Ty) const; |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
inline Align getValueOrABITypeAlignment(MaybeAlign Alignment, |
| 533 |
Type *Ty) const { |
| 534 |
return Alignment ? *Alignment : getABITypeAlign(Ty); |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
Align getABIIntegerTypeAlignment(unsigned BitWidth) const { |
| 540 |
return getIntegerAlignment(BitWidth, true); |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
uint64_t getPrefTypeAlignment(Type *Ty) const; |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
Align getPrefTypeAlign(Type *Ty) const; |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
IntegerType *getIntPtrType(LLVMContext &C, unsigned AddressSpace = 0) const; |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
Type *getIntPtrType(Type *) const; |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
Type *getSmallestLegalIntType(LLVMContext &C, unsigned Width = 0) const; |
| 567 |
|
| 568 |
|
| 569 |
Type *getLargestLegalIntType(LLVMContext &C) const { |
| 570 |
unsigned LargestSize = getLargestLegalIntTypeSizeInBits(); |
| 571 |
return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize); |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
unsigned getLargestLegalIntTypeSizeInBits() const; |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
Type *getIndexType(Type *PtrTy) const; |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef<Value *> Indices) const; |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
SmallVector<APInt> getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const; |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
Optional<APInt> getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const; |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
const StructLayout *getStructLayout(StructType *Ty) const; |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
Align getPreferredAlign(const GlobalVariable *GV) const; |
| 610 |
}; |
| 611 |
|
| 612 |
inline DataLayout *unwrap(LLVMTargetDataRef P) { |
| 613 |
return reinterpret_cast<DataLayout *>(P); |
| 614 |
} |
| 615 |
|
| 616 |
inline LLVMTargetDataRef wrap(const DataLayout *P) { |
| 617 |
return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout *>(P)); |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
class StructLayout final : public TrailingObjects<StructLayout, uint64_t> { |
| 623 |
uint64_t StructSize; |
| 624 |
Align StructAlignment; |
| 625 |
unsigned IsPadded : 1; |
| 626 |
unsigned NumElements : 31; |
| 627 |
|
| 628 |
public: |
| 629 |
uint64_t getSizeInBytes() const { return StructSize; } |
| 630 |
|
| 631 |
uint64_t getSizeInBits() const { return 8 * StructSize; } |
| 632 |
|
| 633 |
Align getAlignment() const { return StructAlignment; } |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
bool hasPadding() const { return IsPadded; } |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
unsigned getElementContainingOffset(uint64_t Offset) const; |
| 642 |
|
| 643 |
MutableArrayRef<uint64_t> getMemberOffsets() { |
| 644 |
return llvm::makeMutableArrayRef(getTrailingObjects<uint64_t>(), |
| 645 |
NumElements); |
| 646 |
} |
| 647 |
|
| 648 |
ArrayRef<uint64_t> getMemberOffsets() const { |
| 649 |
return llvm::makeArrayRef(getTrailingObjects<uint64_t>(), NumElements); |
| 650 |
} |
| 651 |
|
| 652 |
uint64_t getElementOffset(unsigned Idx) const { |
| 653 |
assert(Idx < NumElements && "Invalid element idx!"); |
| 654 |
return getMemberOffsets()[Idx]; |
| 655 |
} |
| 656 |
|
| 657 |
uint64_t getElementOffsetInBits(unsigned Idx) const { |
| 658 |
return getElementOffset(Idx) * 8; |
| 659 |
} |
| 660 |
|
| 661 |
private: |
| 662 |
friend class DataLayout; |
| 663 |
|
| 664 |
StructLayout(StructType *ST, const DataLayout &DL); |
| 665 |
|
| 666 |
size_t numTrailingObjects(OverloadToken<uint64_t>) const { |
| 667 |
return NumElements; |
| 668 |
} |
| 669 |
}; |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
inline TypeSize DataLayout::getTypeSizeInBits(Type *Ty) const { |
| 674 |
assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!"); |
| 675 |
switch (Ty->getTypeID()) { |
| 676 |
case Type::LabelTyID: |
| 677 |
return TypeSize::Fixed(getPointerSizeInBits(0)); |
| 678 |
case Type::PointerTyID: |
| 679 |
return TypeSize::Fixed(getPointerSizeInBits(Ty->getPointerAddressSpace())); |
| 680 |
case Type::ArrayTyID: { |
| 681 |
ArrayType *ATy = cast<ArrayType>(Ty); |
| 682 |
return ATy->getNumElements() * |
| 683 |
getTypeAllocSizeInBits(ATy->getElementType()); |
| 684 |
} |
| 685 |
case Type::StructTyID: |
| 686 |
|
| 687 |
return TypeSize::Fixed( |
| 688 |
getStructLayout(cast<StructType>(Ty))->getSizeInBits()); |
| 689 |
case Type::IntegerTyID: |
| 690 |
return TypeSize::Fixed(Ty->getIntegerBitWidth()); |
| 691 |
case Type::HalfTyID: |
| 692 |
case Type::BFloatTyID: |
| 693 |
return TypeSize::Fixed(16); |
| 694 |
case Type::FloatTyID: |
| 695 |
return TypeSize::Fixed(32); |
| 696 |
case Type::DoubleTyID: |
| 697 |
case Type::X86_MMXTyID: |
| 698 |
return TypeSize::Fixed(64); |
| 699 |
case Type::PPC_FP128TyID: |
| 700 |
case Type::FP128TyID: |
| 701 |
return TypeSize::Fixed(128); |
| 702 |
case Type::X86_AMXTyID: |
| 703 |
return TypeSize::Fixed(8192); |
| 704 |
|
| 705 |
|
| 706 |
case Type::X86_FP80TyID: |
| 707 |
return TypeSize::Fixed(80); |
| 708 |
case Type::FixedVectorTyID: |
| 709 |
case Type::ScalableVectorTyID: { |
| 710 |
VectorType *VTy = cast<VectorType>(Ty); |
| 711 |
auto EltCnt = VTy->getElementCount(); |
| 712 |
uint64_t MinBits = EltCnt.getKnownMinValue() * |
| 713 |
getTypeSizeInBits(VTy->getElementType()).getFixedSize(); |
| 714 |
return TypeSize(MinBits, EltCnt.isScalable()); |
| 715 |
} |
| 716 |
default: |
| 717 |
llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type"); |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
} |
| 722 |
|
| 723 |
#endif |