LLVM: include/llvm/IR/DataLayout.h Source File (original) (raw)

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

37#include

38#include

39#include

40

41

42

44

45namespace llvm {

46

52

53

54

55

56

57

58

59

60

61

62

63

65public:

66

74

75

81

82

83

84

85

87

88

89

91

92

93

94

96

98

100 };

101

108

109private:

110 bool BigEndian = false;

111

112 unsigned AllocaAddrSpace = 0;

113 unsigned ProgramAddrSpace = 0;

114 unsigned DefaultGlobalsAddrSpace = 0;

115

118 FunctionPtrAlignType TheFunctionPtrAlignType =

120

121 enum ManglingModeT {

122 MM_None,

123 MM_ELF,

124 MM_MachO,

125 MM_WinCOFF,

126 MM_WinCOFFX86,

127 MM_GOFF,

128 MM_Mips,

129 MM_XCOFF

130 };

131 ManglingModeT ManglingMode = MM_None;

132

133

134 SmallVector<unsigned char, 8> LegalIntWidths;

135

136

140

141

143

144

145 std::string StringRepresentation;

146

147

150

151

152 mutable void *LayoutMap = nullptr;

153

154

155 void setPrimitiveSpec(char Specifier, uint32_t BitWidth, Align ABIAlign,

156 Align PrefAlign);

157

158

159

160 LLVM_ABI const PointerSpec &getPointerSpec(uint32_t AddrSpace) const;

161

162

164 Align PrefAlign, uint32_t IndexBitWidth,

165 bool HasUnstableRepr, bool HasExternalState,

166 StringRef AddrSpaceName);

167

168

170

171

172 Align getAlignment(Type *Ty, bool abi_or_pref) const;

173

174

175 Error parsePrimitiveSpec(StringRef Spec);

176

177

178 Error parseAggregateSpec(StringRef Spec);

179

180

181 Error parsePointerSpec(StringRef Spec,

182 SmallDenseSet<StringRef, 8> &AddrSpaceNames);

183

184

185 Error parseSpecification(StringRef Spec,

186 SmallVectorImpl &NonIntegralAddressSpaces,

187 SmallDenseSet<StringRef, 8> &AddrSpaceNames);

188

189

190 Error parseLayoutString(StringRef LayoutString);

191

192public:

193

195

196

197

199

201

203

205

208

209

210

212

213

216

217

218

219

220

221

223 return StringRepresentation;

224 }

225

226

227 bool isDefault() const { return StringRepresentation.empty(); }

228

229

230

231

232

233

234

235

239

241

242

243

245

247

251

252

253

254

256

257

258

260 return TheFunctionPtrAlignType;

261 }

262

265 return DefaultGlobalsAddrSpace;

266 }

267

269 return ManglingMode == MM_WinCOFFX86;

270 }

271

272

273

275 return ManglingMode == MM_WinCOFF || ManglingMode == MM_WinCOFFX86;

276 }

277

279

281 if (ManglingMode == MM_MachO)

282 return "l";

283 return "";

284 }

285

287 switch (ManglingMode) {

288 case MM_None:

289 case MM_ELF:

290 case MM_GOFF:

291 case MM_Mips:

292 case MM_WinCOFF:

293 case MM_XCOFF:

294 return '\0';

295 case MM_MachO:

296 case MM_WinCOFFX86:

297 return '_';

298 }

300 }

301

303 switch (ManglingMode) {

304 case MM_None:

305 return "";

306 case MM_ELF:

307 case MM_WinCOFF:

308 return ".L";

309 case MM_GOFF:

310 return "L#";

311 case MM_Mips:

312 return "$";

313 case MM_MachO:

314 case MM_WinCOFFX86:

315 return "L";

316 case MM_XCOFF:

317 return "L..";

318 }

320 }

321

322

323

324

325

326

328 for (unsigned LegalIntWidth : LegalIntWidths)

329 if (Width <= LegalIntWidth)

330 return true;

331 return false;

332 }

333

334

336

338

340

341

342

343

345

346

347

348

349

350

351

352

353

355

356

357

358

359

360

361

362

363

364

366

367

368

369

370

371

372

373

374

375

377

378

379

382 for (const PointerSpec &PS : PointerSpecs) {

383 if (PS.HasUnstableRepresentation || PS.HasExternalState ||

384 PS.BitWidth != PS.IndexBitWidth)

385 AddrSpaces.push_back(PS.AddrSpace);

386 }

387 return AddrSpaces;

388 }

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

407 const auto &PS = getPointerSpec(AddrSpace);

408 return PS.BitWidth != PS.IndexBitWidth || PS.HasUnstableRepresentation ||

409 PS.HasExternalState;

410 }

411

412

413

414

415

416

418 return getPointerSpec(AddrSpace).HasUnstableRepresentation;

419 }

424

425

426

427

428

429

430

431

432

434 return getPointerSpec(AddrSpace).HasExternalState;

435 }

440

441

442

443

444

445

446

447

448

449

453

454

455

456

457

458

459

460

464

468

473

478

483

484

485

486

487

488

489

491 return getPointerSpec(AS).BitWidth;

492 }

493

494

495

496

497

499 return getPointerSpec(AS).IndexBitWidth;

500 }

501

502

503

504

505

506

510

511

512

513

514

515

517

518

519

520

521

523

524

525

526

530

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

560

561

562

563

564

565

566

567

573

574

575

576

577

578

579

580

585 return {AlignedSizeInBits, BaseSize.isScalable()};

586 }

587

588

589

590

591

595

596

597

598

599

600

601

602

603

605

606

607

608

609

610

611

612

613

617

618

620

621

622

624 Type *Ty) const {

626 }

627

628

629

631 return getIntegerAlignment(BitWidth, true);

632 }

633

634

635

636

637

639

640

641

644

645

646

648

649

650

652 unsigned Width = 0) const;

653

654

657 return (LargestSize == 0) ? nullptr : Type::getIntNTy(C, LargestSize);

658 }

659

660

661

663

664

665

666

669

673

674

675

676

678

680

681

682

683

684

685

688

689

690

693

694

695

696

697

700

701

702

703

704

706

707

708

709

711};

712

716

720

721

722

723class StructLayout final : private TrailingObjects<StructLayout, TypeSize> {

724 friend TrailingObjects;

725

727 Align StructAlignment;

728 unsigned IsPadded : 1;

729 unsigned NumElements : 31;

730

731public:

733

735

737

738

739

741

742

743

745

749

753

755 assert(Idx < NumElements && "Invalid element idx!");

757 }

758

762

763private:

764 friend class DataLayout;

765

767};

768

769

770

772 assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!");

773 switch (Ty->getTypeID()) {

783 }

785

801

802

809 uint64_t MinBits = EltCnt.getKnownMinValue() *

811 return TypeSize(MinBits, EltCnt.isScalable());

812 }

816 }

817 default:

818 llvm_unreachable("DataLayout::getTypeSizeInBits(): Unsupported type");

819 }

820}

821

822}

823

824#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file implements a class to represent arbitrary precision integral constant values and operations...

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

This file defines the DenseSet and SmallDenseSet classes.

This file defines the SmallVector class.

This header defines support for implementing classes that have some trailing object (or arrays of obj...

static uint32_t getAlignment(const MCSectionCOFF &Sec)

Class for arbitrary precision integers.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Class to represent array types.

uint64_t getNumElements() const

Type * getElementType() const

A parsed version of the target data layout string in and methods for querying it.

Definition DataLayout.h:64

unsigned getProgramAddressSpace() const

Definition DataLayout.h:263

bool typeSizeEqualsStoreSize(Type *Ty) const

Returns true if no extra padding bits are needed when storing the specified type.

Definition DataLayout.h:592

LLVM_ABI std::optional< unsigned > getNamedAddressSpace(StringRef Name) const

bool hasLinkerPrivateGlobalPrefix() const

Definition DataLayout.h:278

bool hasExternalState(unsigned AddrSpace) const

Returns whether this address space has external state (implies having a non-integral pointer represen...

Definition DataLayout.h:433

StringRef getLinkerPrivateGlobalPrefix() const

Definition DataLayout.h:280

LLVM_ABI StringRef getAddressSpaceName(unsigned AS) const

unsigned getPointerSizeInBits(unsigned AS=0) const

The size in bits of the pointer representation in a given address space.

Definition DataLayout.h:490

bool isNonIntegralPointerType(Type *Ty) const

Definition DataLayout.h:469

FunctionPtrAlignType

Definition DataLayout.h:102

@ MultipleOfFunctionAlign

The function pointer alignment is a multiple of the function alignment.

Definition DataLayout.h:106

@ Independent

The function pointer alignment is independent of the function alignment.

Definition DataLayout.h:104

LLVM_ABI SmallVector< APInt > getGEPIndicesForOffset(Type *&ElemTy, APInt &Offset) const

Get GEP indices to access Offset inside ElemTy.

bool isLittleEndian() const

Layout endianness...

Definition DataLayout.h:214

bool isDefault() const

Test if the DataLayout was constructed from an empty string.

Definition DataLayout.h:227

Type * getAddressType(Type *PtrTy) const

Returns the type of an address in AddressSpace.

Definition DataLayout.h:679

TypeSize getTypeStoreSizeInBits(Type *Ty) const

Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...

Definition DataLayout.h:581

LLVM_ABI unsigned getLargestLegalIntTypeSizeInBits() const

Returns the size of largest legal integer type size, or 0 if none are set.

unsigned getAddressSizeInBits(unsigned AS) const

The size in bits of an address in for the given AS.

Definition DataLayout.h:507

bool isLegalInteger(uint64_t Width) const

Returns true if the specified type is known to be a native integer type supported by the CPU.

Definition DataLayout.h:236

unsigned getDefaultGlobalsAddressSpace() const

Definition DataLayout.h:264

FunctionPtrAlignType getFunctionPtrAlignType() const

Return the type of function pointer alignment.

Definition DataLayout.h:259

Align getABIIntegerTypeAlignment(unsigned BitWidth) const

Returns the minimum ABI-required alignment for an integer type of the specified bitwidth.

Definition DataLayout.h:630

IntegerType * getAddressType(LLVMContext &C, unsigned AddressSpace) const

Returns the type of an address in AddressSpace.

Definition DataLayout.h:670

bool doNotMangleLeadingQuestionMark() const

Returns true if symbols with leading question marks should not receive IR mangling.

Definition DataLayout.h:274

LLVM_ABI unsigned getIndexSize(unsigned AS) const

The index size in bytes used for address calculation, rounded up to a whole number of bytes.

bool mustNotIntroduceIntToPtr(unsigned AddrSpace) const

Returns whether passes must avoid introducing inttoptr instructions for this address space (unless th...

Definition DataLayout.h:450

LLVM_ABI const StructLayout * getStructLayout(StructType *Ty) const

Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...

LLVM_ABI DataLayout()

Constructs a DataLayout with default values.

bool hasUnstableRepresentation(unsigned AddrSpace) const

Returns whether this address space has an "unstable" pointer representation.

Definition DataLayout.h:417

bool mustNotIntroduceIntToPtr(Type *Ty) const

Definition DataLayout.h:479

unsigned getAddressSizeInBits(Type *Ty) const

The size in bits of an address for this type.

Definition DataLayout.h:527

bool mustNotIntroducePtrToInt(Type *Ty) const

Definition DataLayout.h:474

LLVM_ABI IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const

Returns an integer type with size at least as big as that of a pointer in the given address space.

unsigned getPointerTypeSize(Type *Ty) const

Definition DataLayout.h:531

LLVM_ABI Align getABITypeAlign(Type *Ty) const

Returns the minimum ABI-required alignment for the specified type.

bool isNonIntegralAddressSpace(unsigned AddrSpace) const

Returns whether this address space has a non-integral pointer representation, i.e.

Definition DataLayout.h:406

bool isIllegalInteger(uint64_t Width) const

Definition DataLayout.h:240

LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const

The size in bits of the index used in GEP calculation for this type.

PointerType * getAllocaPtrType(LLVMContext &Ctx) const

Definition DataLayout.h:248

LLVM_ABI unsigned getPointerTypeSizeInBits(Type *) const

The pointer representation size in bits for this type.

bool isBigEndian() const

Definition DataLayout.h:215

SmallVector< unsigned, 8 > getNonStandardAddressSpaces() const

Return the address spaces with special pointer semantics (such as being unstable or non-integral).

Definition DataLayout.h:380

MaybeAlign getStackAlignment() const

Returns the natural stack alignment, or MaybeAlign() if one wasn't specified.

Definition DataLayout.h:244

unsigned getAllocaAddrSpace() const

Definition DataLayout.h:246

LLVM_ABI DataLayout & operator=(const DataLayout &Other)

LLVM_ABI IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const

Returns the type of a GEP index in AddressSpace.

LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const

Returns the offset in bytes between successive objects of the specified type, including alignment pad...

bool mustNotIntroducePtrToInt(unsigned AddrSpace) const

Returns whether passes must avoid introducing ptrtoint instructions for this address space (unless th...

Definition DataLayout.h:461

LLVM_ABI std::optional< APInt > getGEPIndexForOffset(Type *&ElemTy, APInt &Offset) const

Get single GEP index to access Offset inside ElemTy.

LLVM_ABI Type * getSmallestLegalIntType(LLVMContext &C, unsigned Width=0) const

Returns the smallest integer type with size at least as big as Width bits.

bool hasExternalState(Type *Ty) const

Definition DataLayout.h:436

LLVM_ABI Align getPreferredAlign(const GlobalVariable *GV) const

Returns the preferred alignment of the specified global.

bool fitsInLegalInteger(unsigned Width) const

Returns true if the specified type fits in a native integer type supported by the CPU.

Definition DataLayout.h:327

bool hasMicrosoftFastStdCallMangling() const

Definition DataLayout.h:268

bool hasUnstableRepresentation(Type *Ty) const

Definition DataLayout.h:420

LLVM_ABI unsigned getPointerSize(unsigned AS=0) const

The pointer representation size in bytes, rounded up to a whole number of bytes.

bool isNonIntegralPointerType(PointerType *PT) const

Definition DataLayout.h:465

LLVM_ABI Align getPointerPrefAlignment(unsigned AS=0) const

Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...

unsigned getIndexSizeInBits(unsigned AS) const

The size in bits of indices used for address calculation in getelementptr and for addresses in the gi...

Definition DataLayout.h:498

Type * getLargestLegalIntType(LLVMContext &C) const

Returns the largest legal integer type, or null if none are set.

Definition DataLayout.h:655

StringRef getPrivateGlobalPrefix() const

Definition DataLayout.h:302

MaybeAlign getFunctionPtrAlign() const

Returns the alignment of function pointers, which may or may not be related to the alignment of funct...

Definition DataLayout.h:255

TypeSize getTypeSizeInBits(Type *Ty) const

Size examples:

Definition DataLayout.h:771

TypeSize getTypeStoreSize(Type *Ty) const

Returns the maximum number of bytes that may be overwritten by storing the specified type.

Definition DataLayout.h:568

bool operator!=(const DataLayout &Other) const

Definition DataLayout.h:207

DataLayout(const DataLayout &DL)

Definition DataLayout.h:200

TypeSize getTypeAllocSizeInBits(Type *Ty) const

Returns the offset in bits between successive objects of the specified type, including alignment padd...

Definition DataLayout.h:614

char getGlobalPrefix() const

Definition DataLayout.h:286

LLVM_ABI bool operator==(const DataLayout &Other) const

LLVM_ABI int64_t getIndexedOffsetInType(Type *ElemTy, ArrayRef< Value * > Indices) const

Returns the offset from the beginning of the type for the specified indices.

const std::string & getStringRepresentation() const

Returns the string representation of the DataLayout.

Definition DataLayout.h:222

unsigned getAddressSize(unsigned AS) const

The integral size of a pointer in a given address space in bytes, which is defined to be the same as ...

Definition DataLayout.h:376

Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const

Helper function to return Alignment if it's set or the result of getABITypeAlign(Ty),...

Definition DataLayout.h:623

LLVM_ABI Align getPointerABIAlignment(unsigned AS) const

Layout pointer alignment.

LLVM_ABI Align getPrefTypeAlign(Type *Ty) const

Returns the preferred stack/global alignment for the specified type.

static LLVM_ABI Expected< DataLayout > parse(StringRef LayoutString)

Parse a data layout string and return the layout.

Tagged union holding either a T or a Error.

Class to represent integer types.

This is an important class for using LLVM in a threaded context.

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

Class to represent pointers.

unsigned getAddressSpace() const

Return the address space of the Pointer type.

static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)

This constructs a pointer to an object of the specified type in a numbered address space.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...

Definition DataLayout.h:723

TypeSize getSizeInBytes() const

Definition DataLayout.h:732

bool hasPadding() const

Returns whether the struct has padding or not between its fields.

Definition DataLayout.h:740

MutableArrayRef< TypeSize > getMemberOffsets()

Definition DataLayout.h:746

LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const

Given a valid byte offset into the structure, returns the structure index that contains it.

TypeSize getElementOffset(unsigned Idx) const

Definition DataLayout.h:754

friend class DataLayout

Definition DataLayout.h:764

ArrayRef< TypeSize > getMemberOffsets() const

Definition DataLayout.h:750

TypeSize getSizeInBits() const

Definition DataLayout.h:734

TypeSize getElementOffsetInBits(unsigned Idx) const

Definition DataLayout.h:759

Align getAlignment() const

Definition DataLayout.h:736

Class to represent struct types.

const T * getTrailingObjects() const

Triple - Helper class for working with autoconf configuration names.

static constexpr TypeSize getFixed(ScalarTy ExactSize)

The instances of the Type class are immutable: once they are created, they are never changed.

@ X86_AMXTyID

AMX vectors (8192 bits, X86 specific)

@ HalfTyID

16-bit floating point type

@ TargetExtTyID

Target extension type.

@ ScalableVectorTyID

Scalable SIMD vector type.

@ FloatTyID

32-bit floating point type

@ IntegerTyID

Arbitrary bit width integers.

@ FixedVectorTyID

Fixed width SIMD vector type.

@ BFloatTyID

16-bit floating point type (7-bit significand)

@ DoubleTyID

64-bit floating point type

@ X86_FP80TyID

80-bit floating point type (X87)

@ PPC_FP128TyID

128-bit floating point type (two 64-bits, PowerPC)

@ FP128TyID

128-bit floating point type (112-bit significand)

static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)

LLVM Value Representation.

Base class of all SIMD vector types.

ElementCount getElementCount() const

Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...

Type * getElementType() const

constexpr ScalarTy getFixedValue() const

constexpr bool isScalable() const

Returns whether the quantity is scaled by a runtime quantity (vscale).

constexpr ScalarTy getKnownMinValue() const

Returns the minimum value this quantity can represent.

struct LLVMOpaqueTargetData * LLVMTargetDataRef

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

constexpr T alignToPowerOf2(U Value, V Align)

Will overflow only if result is not representable in T.

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

Attribute unwrap(LLVMAttributeRef Attr)

constexpr unsigned BitWidth

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

LLVMAttributeRef wrap(Attribute Attr)

bool is_contained(R &&Range, const E &Element)

Returns true if Element is found in Range.

This struct is a compact representation of a valid (non-zero power of two) alignment.

static constexpr Align Constant()

Allow constructions of constexpr Align.

Pointer type specification.

Definition DataLayout.h:76

uint32_t AddrSpace

Definition DataLayout.h:77

bool HasUnstableRepresentation

Pointers in this address space don't have a well-defined bitwise representation (e....

Definition DataLayout.h:90

LLVM_ABI bool operator==(const PointerSpec &Other) const

std::string AddrSpaceName

Definition DataLayout.h:97

bool HasExternalState

Pointers in this address space have additional state bits that are located at a target-defined locati...

Definition DataLayout.h:95

Align ABIAlign

Definition DataLayout.h:79

uint32_t BitWidth

Definition DataLayout.h:78

Align PrefAlign

Definition DataLayout.h:80

uint32_t IndexBitWidth

The index bit width also defines the address size in this address space.

Definition DataLayout.h:86

Primitive type specification.

Definition DataLayout.h:67

Align PrefAlign

Definition DataLayout.h:70

LLVM_ABI bool operator==(const PrimitiveSpec &Other) const

Align ABIAlign

Definition DataLayout.h:69

uint32_t BitWidth

Definition DataLayout.h:68

This struct is a compact representation of a valid (power of two) or undefined (0) alignment.