Convert RecordLayout::Alignment to CharUnits from bit units. No change in

functionality intended. 

llvm-svn: 125549
This commit is contained in:
Ken Dyck 2011-02-15 02:32:40 +00:00
parent 4ea9004fe8
commit 7ad11e70b6
5 changed files with 24 additions and 20 deletions

View File

@ -42,8 +42,8 @@ class ASTRecordLayout {
/// FieldOffsets - Array of field offsets in bits.
uint64_t *FieldOffsets;
// Alignment - Alignment of record in bits.
unsigned Alignment;
// Alignment - Alignment of record in characters.
CharUnits Alignment;
// FieldCount - Number of fields.
unsigned FieldCount;
@ -82,14 +82,14 @@ class ASTRecordLayout {
friend class ASTContext;
ASTRecordLayout(const ASTContext &Ctx, CharUnits size, unsigned alignment,
ASTRecordLayout(const ASTContext &Ctx, CharUnits size, CharUnits alignment,
CharUnits datasize, const uint64_t *fieldoffsets,
unsigned fieldcount);
// Constructor for C++ records.
typedef CXXRecordLayoutInfo::BaseOffsetsMapTy BaseOffsetsMapTy;
ASTRecordLayout(const ASTContext &Ctx,
CharUnits size, unsigned alignment, CharUnits datasize,
CharUnits size, CharUnits alignment, CharUnits datasize,
const uint64_t *fieldoffsets, unsigned fieldcount,
CharUnits nonvirtualsize, CharUnits nonvirtualalign,
CharUnits SizeOfLargestEmptySubobject,
@ -106,8 +106,8 @@ class ASTRecordLayout {
void operator=(const ASTRecordLayout&); // DO NOT IMPLEMENT
public:
/// getAlignment - Get the record alignment in bits.
unsigned getAlignment() const { return Alignment; }
/// getAlignment - Get the record alignment in characters.
CharUnits getAlignment() const { return Alignment; }
/// getSize - Get the record size in characters.
CharUnits getSize() const { return Size; }

View File

@ -632,7 +632,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) const {
const ASTRecordLayout &layout = getASTRecordLayout(field->getParent());
// Start with the record's overall alignment.
unsigned fieldAlign = layout.getAlignment();
unsigned fieldAlign = toBits(layout.getAlignment());
// Use the GCD of that and the offset within the record.
uint64_t offset = layout.getFieldOffset(field->getFieldIndex());
@ -848,7 +848,7 @@ ASTContext::getTypeInfo(const Type *T) const {
const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T);
const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl());
Width = toBits(Layout.getSize());
Align = Layout.getAlignment();
Align = toBits(Layout.getAlignment());
break;
}
case Type::Record:
@ -867,7 +867,7 @@ ASTContext::getTypeInfo(const Type *T) const {
const RecordType *RT = cast<RecordType>(TT);
const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
Width = toBits(Layout.getSize());
Align = Layout.getAlignment();
Align = toBits(Layout.getAlignment());
break;
}

View File

@ -28,7 +28,7 @@ void ASTRecordLayout::Destroy(ASTContext &Ctx) {
}
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
unsigned alignment, CharUnits datasize,
CharUnits alignment, CharUnits datasize,
const uint64_t *fieldoffsets,
unsigned fieldcount)
: Size(size), DataSize(datasize), FieldOffsets(0), Alignment(alignment),
@ -41,7 +41,7 @@ ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size,
// Constructor for C++ records.
ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx,
CharUnits size, unsigned alignment,
CharUnits size, CharUnits alignment,
CharUnits datasize,
const uint64_t *fieldoffsets,
unsigned fieldcount,

View File

@ -1203,7 +1203,7 @@ void RecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D) {
if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
const ASTRecordLayout &SL = Context.getASTObjCInterfaceLayout(SD);
UpdateAlignment(SL.getAlignment());
UpdateAlignment(Context.toBits(SL.getAlignment()));
// We start laying out ivars not at the end of the superclass
// structure, but at the next byte following the last field.
@ -1683,7 +1683,8 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
CharUnits RecordSize = toCharUnitsFromBits(Builder->Size);
NewEntry =
new (*this) ASTRecordLayout(*this, RecordSize, Builder->Alignment,
new (*this) ASTRecordLayout(*this, RecordSize,
toCharUnitsFromBits(Builder->Alignment),
toCharUnitsFromBits(DataSize),
Builder->FieldOffsets.data(),
Builder->FieldOffsets.size(),
@ -1700,7 +1701,8 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
CharUnits RecordSize = toCharUnitsFromBits(Builder.Size);
NewEntry =
new (*this) ASTRecordLayout(*this, RecordSize, Builder.Alignment,
new (*this) ASTRecordLayout(*this, RecordSize,
toCharUnitsFromBits(Builder.Alignment),
toCharUnitsFromBits(Builder.Size),
Builder.FieldOffsets.data(),
Builder.FieldOffsets.size());
@ -1760,7 +1762,8 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
CharUnits RecordSize = toCharUnitsFromBits(Builder.Size);
const ASTRecordLayout *NewEntry =
new (*this) ASTRecordLayout(*this, RecordSize, Builder.Alignment,
new (*this) ASTRecordLayout(*this, RecordSize,
toCharUnitsFromBits(Builder.Alignment),
toCharUnitsFromBits(Builder.DataSize),
Builder.FieldOffsets.data(),
Builder.FieldOffsets.size());
@ -1859,7 +1862,7 @@ static void DumpCXXRecordLayout(llvm::raw_ostream &OS,
OS << " sizeof=" << Layout.getSize().getQuantity();
OS << ", dsize=" << Layout.getDataSize().getQuantity();
OS << ", align=" << Layout.getAlignment() / 8 << '\n';
OS << ", align=" << Layout.getAlignment().getQuantity() << '\n';
OS << " nvsize=" << Layout.getNonVirtualSize().getQuantity();
OS << ", nvalign=" << Layout.getNonVirtualAlign().getQuantity() << '\n';
OS << '\n';
@ -1880,7 +1883,7 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD,
OS << "<ASTRecordLayout\n";
OS << " Size:" << toBits(Info.getSize()) << "\n";
OS << " DataSize:" << toBits(Info.getDataSize()) << "\n";
OS << " Alignment:" << Info.getAlignment() << "\n";
OS << " Alignment:" << toBits(Info.getAlignment()) << "\n";
OS << " FieldOffsets: [";
for (unsigned i = 0, e = Info.getFieldCount(); i != e; ++i) {
if (i) OS << ", ";

View File

@ -177,7 +177,8 @@ public:
}
void CGRecordLayoutBuilder::Layout(const RecordDecl *D) {
Alignment = Types.getContext().getASTRecordLayout(D).getAlignment() / 8;
Alignment =
Types.getContext().getASTRecordLayout(D).getAlignment().getQuantity();
Packed = D->hasAttr<PackedAttr>();
if (D->isUnion()) {
@ -301,7 +302,7 @@ CGBitFieldInfo CGBitFieldInfo::MakeInfo(CodeGenTypes &Types,
const RecordDecl *RD = FD->getParent();
const ASTRecordLayout &RL = Types.getContext().getASTRecordLayout(RD);
uint64_t ContainingTypeSizeInBits = Types.getContext().toBits(RL.getSize());
unsigned ContainingTypeAlign = RL.getAlignment();
unsigned ContainingTypeAlign = Types.getContext().toBits(RL.getAlignment());
return MakeInfo(Types, FD, FieldOffset, FieldSize, ContainingTypeSizeInBits,
ContainingTypeAlign);
@ -476,7 +477,7 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
if (Ty) {
AppendField(0, Ty);
if (getTypeAlignment(Ty) > Layout.getAlignment() / 8) {
if (getTypeAlignment(Ty) > Layout.getAlignment().getQuantity()) {
// We need a packed struct.
Packed = true;
Align = 1;