parent
a3242e93b7
commit
d5d6413aa5
|
@ -41,8 +41,8 @@ void CGRecordLayoutBuilder::Layout(const RecordDecl *D) {
|
||||||
// We weren't able to layout the struct. Try again with a packed struct
|
// We weren't able to layout the struct. Try again with a packed struct
|
||||||
Packed = true;
|
Packed = true;
|
||||||
AlignmentAsLLVMStruct = 1;
|
AlignmentAsLLVMStruct = 1;
|
||||||
|
NextFieldOffsetInBytes = 0;
|
||||||
FieldTypes.clear();
|
FieldTypes.clear();
|
||||||
FieldInfos.clear();
|
|
||||||
LLVMFields.clear();
|
LLVMFields.clear();
|
||||||
LLVMBitFields.clear();
|
LLVMBitFields.clear();
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
|
||||||
if (FieldSize == 0)
|
if (FieldSize == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint64_t NextFieldOffset = getNextFieldOffsetInBytes() * 8;
|
uint64_t NextFieldOffset = NextFieldOffsetInBytes * 8;
|
||||||
unsigned NumBytesToAppend;
|
unsigned NumBytesToAppend;
|
||||||
|
|
||||||
if (FieldOffset < NextFieldOffset) {
|
if (FieldOffset < NextFieldOffset) {
|
||||||
assert(BitsAvailableInLastField && "Bitfield size mismatch!");
|
assert(BitsAvailableInLastField && "Bitfield size mismatch!");
|
||||||
assert(!FieldInfos.empty() && "Field infos can't be empty!");
|
assert(NextFieldOffsetInBytes && "Must have laid out at least one byte!");
|
||||||
|
|
||||||
// The bitfield begins in the previous bit-field.
|
// The bitfield begins in the previous bit-field.
|
||||||
NumBytesToAppend =
|
NumBytesToAppend =
|
||||||
|
@ -91,7 +91,7 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D,
|
||||||
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty));
|
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty));
|
||||||
|
|
||||||
BitsAvailableInLastField =
|
BitsAvailableInLastField =
|
||||||
getNextFieldOffsetInBytes() * 8 - (FieldOffset + FieldSize);
|
NextFieldOffsetInBytes * 8 - (FieldOffset + FieldSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D,
|
bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D,
|
||||||
|
@ -222,13 +222,12 @@ void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) {
|
||||||
assert(RecordSize % 8 == 0 && "Invalid record size!");
|
assert(RecordSize % 8 == 0 && "Invalid record size!");
|
||||||
|
|
||||||
uint64_t RecordSizeInBytes = RecordSize / 8;
|
uint64_t RecordSizeInBytes = RecordSize / 8;
|
||||||
assert(getNextFieldOffsetInBytes() <= RecordSizeInBytes && "Size mismatch!");
|
assert(NextFieldOffsetInBytes <= RecordSizeInBytes && "Size mismatch!");
|
||||||
|
|
||||||
unsigned NumPadBytes = RecordSizeInBytes - getNextFieldOffsetInBytes();
|
unsigned NumPadBytes = RecordSizeInBytes - NextFieldOffsetInBytes;
|
||||||
AppendBytes(NumPadBytes);
|
AppendBytes(NumPadBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
|
void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
|
||||||
const llvm::Type *FieldTy) {
|
const llvm::Type *FieldTy) {
|
||||||
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
|
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
|
||||||
|
@ -237,8 +236,8 @@ void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
|
||||||
uint64_t FieldSizeInBytes = getTypeSizeInBytes(FieldTy);
|
uint64_t FieldSizeInBytes = getTypeSizeInBytes(FieldTy);
|
||||||
|
|
||||||
FieldTypes.push_back(FieldTy);
|
FieldTypes.push_back(FieldTy);
|
||||||
FieldInfos.push_back(FieldInfo(FieldOffsetInBytes, FieldSizeInBytes));
|
|
||||||
|
|
||||||
|
NextFieldOffsetInBytes = FieldOffsetInBytes + FieldSizeInBytes;
|
||||||
BitsAvailableInLastField = 0;
|
BitsAvailableInLastField = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +249,6 @@ CGRecordLayoutBuilder::AppendPadding(uint64_t FieldOffsetInBytes,
|
||||||
|
|
||||||
void CGRecordLayoutBuilder::AppendPadding(uint64_t FieldOffsetInBytes,
|
void CGRecordLayoutBuilder::AppendPadding(uint64_t FieldOffsetInBytes,
|
||||||
unsigned FieldAlignment) {
|
unsigned FieldAlignment) {
|
||||||
uint64_t NextFieldOffsetInBytes = getNextFieldOffsetInBytes();
|
|
||||||
assert(NextFieldOffsetInBytes <= FieldOffsetInBytes &&
|
assert(NextFieldOffsetInBytes <= FieldOffsetInBytes &&
|
||||||
"Incorrect field layout!");
|
"Incorrect field layout!");
|
||||||
|
|
||||||
|
@ -276,15 +274,7 @@ void CGRecordLayoutBuilder::AppendBytes(uint64_t NumBytes) {
|
||||||
Ty = llvm::ArrayType::get(Ty, NumBytes);
|
Ty = llvm::ArrayType::get(Ty, NumBytes);
|
||||||
|
|
||||||
// Append the padding field
|
// Append the padding field
|
||||||
AppendField(getNextFieldOffsetInBytes(), Ty);
|
AppendField(NextFieldOffsetInBytes, Ty);
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t CGRecordLayoutBuilder::getNextFieldOffsetInBytes() const {
|
|
||||||
if (FieldInfos.empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
const FieldInfo &LastInfo = FieldInfos.back();
|
|
||||||
return LastInfo.OffsetInBytes + LastInfo.SizeInBytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CGRecordLayoutBuilder::getTypeAlignment(const llvm::Type *Ty) const {
|
unsigned CGRecordLayoutBuilder::getTypeAlignment(const llvm::Type *Ty) const {
|
||||||
|
|
|
@ -43,21 +43,13 @@ class CGRecordLayoutBuilder {
|
||||||
/// BitsAvailableInLastField - If a bit field spans only part of a LLVM field,
|
/// BitsAvailableInLastField - If a bit field spans only part of a LLVM field,
|
||||||
/// this will have the number of bits still available in the field.
|
/// this will have the number of bits still available in the field.
|
||||||
char BitsAvailableInLastField;
|
char BitsAvailableInLastField;
|
||||||
|
|
||||||
|
/// NextFieldOffsetInBytes - Holds the next field offset in bytes.
|
||||||
|
uint64_t NextFieldOffsetInBytes;
|
||||||
|
|
||||||
/// FieldTypes - Holds the LLVM types that the struct is created from.
|
/// FieldTypes - Holds the LLVM types that the struct is created from.
|
||||||
std::vector<const llvm::Type *> FieldTypes;
|
std::vector<const llvm::Type *> FieldTypes;
|
||||||
|
|
||||||
/// FieldInfo - Holds size and offset information about a field.
|
|
||||||
/// FIXME: I think we can get rid of this.
|
|
||||||
struct FieldInfo {
|
|
||||||
FieldInfo(uint64_t OffsetInBytes, uint64_t SizeInBytes)
|
|
||||||
: OffsetInBytes(OffsetInBytes), SizeInBytes(SizeInBytes) { }
|
|
||||||
|
|
||||||
const uint64_t OffsetInBytes;
|
|
||||||
const uint64_t SizeInBytes;
|
|
||||||
};
|
|
||||||
llvm::SmallVector<FieldInfo, 16> FieldInfos;
|
|
||||||
|
|
||||||
/// LLVMFieldInfo - Holds a field and its corresponding LLVM field number.
|
/// LLVMFieldInfo - Holds a field and its corresponding LLVM field number.
|
||||||
typedef std::pair<const FieldDecl *, unsigned> LLVMFieldInfo;
|
typedef std::pair<const FieldDecl *, unsigned> LLVMFieldInfo;
|
||||||
llvm::SmallVector<LLVMFieldInfo, 16> LLVMFields;
|
llvm::SmallVector<LLVMFieldInfo, 16> LLVMFields;
|
||||||
|
@ -78,7 +70,7 @@ class CGRecordLayoutBuilder {
|
||||||
|
|
||||||
CGRecordLayoutBuilder(CodeGenTypes &Types)
|
CGRecordLayoutBuilder(CodeGenTypes &Types)
|
||||||
: Types(Types), Packed(false), AlignmentAsLLVMStruct(1)
|
: Types(Types), Packed(false), AlignmentAsLLVMStruct(1)
|
||||||
, BitsAvailableInLastField(0) { }
|
, BitsAvailableInLastField(0), NextFieldOffsetInBytes(0) { }
|
||||||
|
|
||||||
/// Layout - Will layout a RecordDecl.
|
/// Layout - Will layout a RecordDecl.
|
||||||
void Layout(const RecordDecl *D);
|
void Layout(const RecordDecl *D);
|
||||||
|
@ -115,9 +107,6 @@ class CGRecordLayoutBuilder {
|
||||||
/// the passed size.
|
/// the passed size.
|
||||||
void AppendTailPadding(uint64_t RecordSize);
|
void AppendTailPadding(uint64_t RecordSize);
|
||||||
|
|
||||||
/// getNextFieldOffsetInBytes - returns where the next field offset is.
|
|
||||||
uint64_t getNextFieldOffsetInBytes() const;
|
|
||||||
|
|
||||||
unsigned getTypeAlignment(const llvm::Type *Ty) const;
|
unsigned getTypeAlignment(const llvm::Type *Ty) const;
|
||||||
uint64_t getTypeSizeInBytes(const llvm::Type *Ty) const;
|
uint64_t getTypeSizeInBytes(const llvm::Type *Ty) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue