9#ifndef LLVM_CLANG_LIB_CODEGEN_CGRECORDLAYOUT_H
10#define LLVM_CLANG_LIB_CODEGEN_CGRECORDLAYOUT_H
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/IR/DerivedTypes.h"
17#include "llvm/Support/MathExtras.h"
75 LLVM_PREFERRED_TYPE(
bool)
106 assert(llvm::isUInt<16>(
Offset) &&
107 "bit-field offset does not fit in CGBitFieldInfo::Offset");
108 assert(llvm::isUInt<15>(
Size) &&
109 "bit-field size does not fit in CGBitFieldInfo::Size");
111 "bit-field storage does not fit in CGBitFieldInfo::StorageSize");
114 void print(raw_ostream &OS)
const;
122 uint64_t Offset, uint64_t
Size,
131class CGRecordLayout {
134 CGRecordLayout(
const CGRecordLayout &) =
delete;
135 void operator=(
const CGRecordLayout &) =
delete;
140 llvm::StructType *CompleteObjectType;
144 llvm::StructType *BaseSubobjectType;
148 llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo;
152 llvm::DenseMap<const FieldDecl *, CGBitFieldInfo> BitFields;
156 llvm::DenseMap<const CXXRecordDecl *, unsigned> NonVirtualBases;
159 llvm::DenseMap<const CXXRecordDecl *, unsigned> CompleteObjectVirtualBases;
164 bool IsZeroInitializable : 1;
169 bool IsZeroInitializableAsBase : 1;
173 llvm::StructType *BaseSubobjectType,
174 bool IsZeroInitializable,
175 bool IsZeroInitializableAsBase)
176 : CompleteObjectType(CompleteObjectType),
177 BaseSubobjectType(BaseSubobjectType),
178 IsZeroInitializable(IsZeroInitializable),
179 IsZeroInitializableAsBase(IsZeroInitializableAsBase) {}
184 return CompleteObjectType;
190 return BaseSubobjectType;
196 return IsZeroInitializable;
202 return IsZeroInitializableAsBase;
206 return FieldInfo.count(FD) != 0;
213 assert(FieldInfo.count(FD) &&
"Invalid field for record!");
214 return FieldInfo.lookup(FD);
220 return NonVirtualBases.count(RD);
224 assert(NonVirtualBases.count(RD) &&
"Invalid non-virtual base!");
225 return NonVirtualBases.lookup(RD);
231 assert(CompleteObjectVirtualBases.count(base) &&
"Invalid virtual base!");
232 return CompleteObjectVirtualBases.lookup(base);
238 assert(FD->
isBitField() &&
"Invalid call for non-bit-field decl!");
239 llvm::DenseMap<const FieldDecl *, CGBitFieldInfo>::const_iterator
240 it = BitFields.find(FD);
241 assert(it != BitFields.end() &&
"Unable to find bitfield info");
245 void print(raw_ostream &OS)
const;
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Represents a C++ struct/union/class.
This is an opaque type for sizes expressed in character units.
CGRecordLayout(llvm::StructType *CompleteObjectType, llvm::StructType *BaseSubobjectType, bool IsZeroInitializable, bool IsZeroInitializableAsBase)
void print(raw_ostream &OS) const
unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const
llvm::StructType * getLLVMType() const
Return the "complete object" LLVM type associated with this record.
friend class CodeGenTypes
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
bool isZeroInitializableAsBase() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer when considered as a bas...
llvm::StructType * getBaseSubobjectLLVMType() const
Return the "base subobject" LLVM type associated with this record.
bool isZeroInitializable() const
Check whether this struct can be C++ zero-initialized with a zeroinitializer.
unsigned getLLVMFieldNo(const FieldDecl *FD) const
Return llvm::StructType element number that corresponds to the field FD.
bool hasNonVirtualBaseLLVMField(const CXXRecordDecl *RD) const
bool containsFieldDecl(const FieldDecl *FD) const
unsigned getVirtualBaseIndex(const CXXRecordDecl *base) const
Return the LLVM field index corresponding to the given virtual base.
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
Top level wrappers for InstallAPI frontend operations.
Diagnostic wrappers for TextAPI types for error reporting.
Structure with information about how a bitfield should be accessed.
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
CharUnits VolatileStorageOffset
The offset of the bitfield storage from the start of the struct.
unsigned VolatileOffset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned VolatileStorageSize
The storage size in bits which should be used when accessing this bitfield.
void print(raw_ostream &OS) const
unsigned Size
The total size of the bit-field, in bits, not including padding.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
unsigned IsSigned
Whether the bit-field is signed.
CGBitFieldInfo(uint64_t Offset, uint64_t Size, bool IsSigned, uint64_t StorageSize, CharUnits StorageOffset)
static CGBitFieldInfo MakeInfo(class CodeGenTypes &Types, const FieldDecl *FD, uint64_t Offset, uint64_t Size, uint64_t StorageSize, CharUnits StorageOffset)
Given a bit-field decl, build an appropriate helper object for accessing that field (which is expecte...