Expand use of CharUnits for alignments further. No change in functionality

intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126034 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ken Dyck 2011-02-19 18:58:07 +00:00
Родитель da2142f2e2
Коммит 3263e09c8e
1 изменённых файлов: 30 добавлений и 30 удалений

Просмотреть файл

@ -687,8 +687,8 @@ protected:
/// alignment.
void FinishLayout(const NamedDecl *D);
void UpdateAlignment(unsigned NewAlignment, unsigned UnpackedNewAlignment);
void UpdateAlignment(unsigned NewAlignment) {
void UpdateAlignment(CharUnits NewAlignment, CharUnits UnpackedNewAlignment);
void UpdateAlignment(CharUnits NewAlignment) {
UpdateAlignment(NewAlignment, NewAlignment);
}
@ -799,14 +799,14 @@ void RecordLayoutBuilder::DeterminePrimaryBase(const CXXRecordDecl *RD) {
Size += GetVirtualPointersSize(RD);
DataSize = Size;
unsigned UnpackedBaseAlign = Context.Target.getPointerAlign(0);
unsigned BaseAlign = (Packed) ? 8 : UnpackedBaseAlign;
CharUnits UnpackedBaseAlign =
Context.toCharUnitsFromBits(Context.Target.getPointerAlign(0));
CharUnits BaseAlign = (Packed) ? CharUnits::One() : UnpackedBaseAlign;
// The maximum field alignment overrides base align.
if (!MaxFieldAlignment.isZero()) {
unsigned MaxFieldAlignmentInBits = Context.toBits(MaxFieldAlignment);
BaseAlign = std::min(BaseAlign, MaxFieldAlignmentInBits);
UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignmentInBits);
BaseAlign = std::min(BaseAlign, MaxFieldAlignment);
UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignment);
}
// Update the alignment.
@ -1095,23 +1095,23 @@ CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
return CharUnits::Zero();
}
unsigned UnpackedBaseAlign = Context.toBits(Layout.getNonVirtualAlign());
unsigned BaseAlign = (Packed) ? 8 : UnpackedBaseAlign;
CharUnits UnpackedBaseAlign = Layout.getNonVirtualAlign();
CharUnits BaseAlign = (Packed) ? CharUnits::One() : UnpackedBaseAlign;
// The maximum field alignment overrides base align.
if (!MaxFieldAlignment.isZero()) {
unsigned MaxFieldAlignmentInBits = Context.toBits(MaxFieldAlignment);
BaseAlign = std::min(BaseAlign, MaxFieldAlignmentInBits);
UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignmentInBits);
BaseAlign = std::min(BaseAlign, MaxFieldAlignment);
UnpackedBaseAlign = std::min(UnpackedBaseAlign, MaxFieldAlignment);
}
// Round up the current record size to the base's alignment boundary.
uint64_t Offset = llvm::RoundUpToAlignment(DataSize, BaseAlign);
uint64_t Offset =
llvm::RoundUpToAlignment(DataSize, Context.toBits(BaseAlign));
// Try to place the base.
while (!EmptySubobjects->CanPlaceBaseAtOffset(Base,
Context.toCharUnitsFromBits(Offset)))
Offset += BaseAlign;
Offset += Context.toBits(BaseAlign);
if (!Base->Class->isEmpty()) {
// Update the data size.
@ -1146,7 +1146,7 @@ void RecordLayoutBuilder::InitializeLayout(const Decl *D) {
MaxFieldAlignment = Context.toCharUnitsFromBits(MFAA->getAlignment());
if (unsigned MaxAlign = D->getMaxAlignment())
UpdateAlignment(MaxAlign);
UpdateAlignment(Context.toCharUnitsFromBits(MaxAlign));
}
}
@ -1207,7 +1207,7 @@ void RecordLayoutBuilder::Layout(const ObjCInterfaceDecl *D) {
if (ObjCInterfaceDecl *SD = D->getSuperClass()) {
const ASTRecordLayout &SL = Context.getASTObjCInterfaceLayout(SD);
UpdateAlignment(Context.toBits(SL.getAlignment()));
UpdateAlignment(SL.getAlignment());
// We start laying out ivars not at the end of the superclass
// structure, but at the next byte following the last field.
@ -1296,7 +1296,7 @@ void RecordLayoutBuilder::LayoutWideBitField(uint64_t FieldSize,
Size = std::max(Size, DataSize);
// Remember max struct/class alignment.
UpdateAlignment(TypeAlign);
UpdateAlignment(Context.toCharUnitsFromBits(TypeAlign));
}
void RecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
@ -1367,7 +1367,8 @@ void RecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
Size = std::max(Size, DataSize);
// Remember max struct/class alignment.
UpdateAlignment(FieldAlign, UnpackedFieldAlign);
UpdateAlignment(Context.toCharUnitsFromBits(FieldAlign),
Context.toCharUnitsFromBits(UnpackedFieldAlign));
}
void RecordLayoutBuilder::LayoutField(const FieldDecl *D) {
@ -1465,7 +1466,8 @@ void RecordLayoutBuilder::LayoutField(const FieldDecl *D) {
DataSize = Size;
// Remember max struct/class alignment.
UpdateAlignment(FieldAlign, UnpackedFieldAlign);
UpdateAlignment(Context.toCharUnitsFromBits(FieldAlign),
Context.toCharUnitsFromBits(UnpackedFieldAlign));
}
void RecordLayoutBuilder::FinishLayout(const NamedDecl *D) {
@ -1512,24 +1514,22 @@ void RecordLayoutBuilder::FinishLayout(const NamedDecl *D) {
}
}
void RecordLayoutBuilder::UpdateAlignment(unsigned NewAlignment,
unsigned UnpackedNewAlignment) {
void RecordLayoutBuilder::UpdateAlignment(CharUnits NewAlignment,
CharUnits UnpackedNewAlignment) {
// The alignment is not modified when using 'mac68k' alignment.
if (IsMac68kAlign)
return;
CharUnits NewAlignmentInChars = Context.toCharUnitsFromBits(NewAlignment);
if (NewAlignmentInChars > Alignment) {
assert(llvm::isPowerOf2_32(NewAlignment && "Alignment not a power of 2"));
Alignment = NewAlignmentInChars;
if (NewAlignment > Alignment) {
assert(llvm::isPowerOf2_32(NewAlignment.getQuantity() &&
"Alignment not a power of 2"));
Alignment = NewAlignment;
}
CharUnits UnpackedNewAlignmentInChars =
Context.toCharUnitsFromBits(UnpackedNewAlignment);
if (UnpackedNewAlignmentInChars > UnpackedAlignment) {
assert(llvm::isPowerOf2_32(UnpackedNewAlignment &&
if (UnpackedNewAlignment > UnpackedAlignment) {
assert(llvm::isPowerOf2_32(UnpackedNewAlignment.getQuantity() &&
"Alignment not a power of 2"));
UnpackedAlignment = UnpackedNewAlignmentInChars;
UnpackedAlignment = UnpackedNewAlignment;
}
}