From 5f022d82696c84e4d127c558871d68ac6273274e Mon Sep 17 00:00:00 2001 From: Ken Dyck <kd@kendyck.com> Date: Wed, 9 Feb 2011 01:59:34 +0000 Subject: [PATCH] Convert RecordLayout::Size to CharUnits from bits. No changes to functionality intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125156 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/RecordLayout.h | 8 ++++---- lib/AST/ASTContext.cpp | 4 ++-- lib/AST/RecordLayout.cpp | 4 ++-- lib/AST/RecordLayoutBuilder.cpp | 29 +++++++++++++++++---------- lib/CodeGen/CGExprConstant.cpp | 7 ++++--- lib/CodeGen/CGObjCGNU.cpp | 5 +++-- lib/CodeGen/CGObjCMac.cpp | 5 +++-- lib/CodeGen/CGRecordLayoutBuilder.cpp | 15 ++++++++------ 8 files changed, 45 insertions(+), 32 deletions(-) diff --git a/include/clang/AST/RecordLayout.h b/include/clang/AST/RecordLayout.h index d442320042..557e790fb7 100644 --- a/include/clang/AST/RecordLayout.h +++ b/include/clang/AST/RecordLayout.h @@ -34,7 +34,7 @@ namespace clang { /// These objects are managed by ASTContext. class ASTRecordLayout { /// Size - Size of record in bits. - uint64_t Size; + CharUnits Size; /// DataSize - Size of record in bits without tail padding. uint64_t DataSize; @@ -82,14 +82,14 @@ class ASTRecordLayout { friend class ASTContext; - ASTRecordLayout(const ASTContext &Ctx, uint64_t size, unsigned alignment, + ASTRecordLayout(const ASTContext &Ctx, CharUnits size, unsigned alignment, unsigned datasize, const uint64_t *fieldoffsets, unsigned fieldcount); // Constructor for C++ records. typedef CXXRecordLayoutInfo::BaseOffsetsMapTy BaseOffsetsMapTy; ASTRecordLayout(const ASTContext &Ctx, - uint64_t size, unsigned alignment, uint64_t datasize, + CharUnits size, unsigned alignment, uint64_t datasize, const uint64_t *fieldoffsets, unsigned fieldcount, CharUnits nonvirtualsize, CharUnits nonvirtualalign, CharUnits SizeOfLargestEmptySubobject, @@ -110,7 +110,7 @@ public: unsigned getAlignment() const { return Alignment; } /// getSize - Get the record size in bits. - uint64_t getSize() const { return Size; } + CharUnits getSize() const { return Size; } /// getFieldCount - Get the number of fields in the layout. unsigned getFieldCount() const { return FieldCount; } diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 63e84d4131..30fe791e6d 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -846,7 +846,7 @@ ASTContext::getTypeInfo(const Type *T) const { case Type::ObjCInterface: { const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T); const ASTRecordLayout &Layout = getASTObjCInterfaceLayout(ObjCI->getDecl()); - Width = Layout.getSize(); + Width = Layout.getSize().getQuantity() * getCharWidth(); Align = Layout.getAlignment(); break; } @@ -865,7 +865,7 @@ ASTContext::getTypeInfo(const Type *T) const { const RecordType *RT = cast<RecordType>(TT); const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl()); - Width = Layout.getSize(); + Width = Layout.getSize().getQuantity() * getCharWidth(); Align = Layout.getAlignment(); break; } diff --git a/lib/AST/RecordLayout.cpp b/lib/AST/RecordLayout.cpp index 32e3821ca2..2acf97523c 100644 --- a/lib/AST/RecordLayout.cpp +++ b/lib/AST/RecordLayout.cpp @@ -27,7 +27,7 @@ void ASTRecordLayout::Destroy(ASTContext &Ctx) { Ctx.Deallocate(this); } -ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, uint64_t size, +ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, CharUnits size, unsigned alignment, unsigned datasize, const uint64_t *fieldoffsets, unsigned fieldcount) @@ -41,7 +41,7 @@ ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, uint64_t size, // Constructor for C++ records. ASTRecordLayout::ASTRecordLayout(const ASTContext &Ctx, - uint64_t size, unsigned alignment, + CharUnits size, unsigned alignment, uint64_t datasize, const uint64_t *fieldoffsets, unsigned fieldcount, diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index 6b98ecd87d..62306894ab 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -148,7 +148,7 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() { const ASTRecordLayout &Layout = Context.getASTRecordLayout(BaseDecl); if (BaseDecl->isEmpty()) { // If the class decl is empty, get its size. - EmptySize = Context.toCharUnitsFromBits(Layout.getSize()); + EmptySize = Layout.getSize(); } else { // Otherwise, we get the largest empty subobject for the decl. EmptySize = Layout.getSizeOfLargestEmptySubobject(); @@ -175,7 +175,7 @@ void EmptySubobjectMap::ComputeEmptySubobjectSizes() { const ASTRecordLayout &Layout = Context.getASTRecordLayout(MemberDecl); if (MemberDecl->isEmpty()) { // If the class decl is empty, get its size. - EmptySize = Context.toCharUnitsFromBits(Layout.getSize()); + EmptySize = Layout.getSize(); } else { // Otherwise, we get the largest empty subobject for the decl. EmptySize = Layout.getSizeOfLargestEmptySubobject(); @@ -428,7 +428,7 @@ EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD, if (!CanPlaceFieldSubobjectAtOffset(RD, RD, ElementOffset)) return false; - ElementOffset += Context.toCharUnitsFromBits(Layout.getSize()); + ElementOffset += Layout.getSize(); } } @@ -533,7 +533,7 @@ void EmptySubobjectMap::UpdateEmptyFieldSubobjects(const FieldDecl *FD, return; UpdateEmptyFieldSubobjects(RD, RD, ElementOffset); - ElementOffset += Context.toCharUnitsFromBits(Layout.getSize()); + ElementOffset += Layout.getSize(); } } } @@ -1091,7 +1091,8 @@ CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) { // If we have an empty base class, try to place it at offset 0. if (Base->Class->isEmpty() && EmptySubobjects->CanPlaceBaseAtOffset(Base, CharUnits::Zero())) { - Size = std::max(Size, Layout.getSize()); + Size = std::max(Size, + Layout.getSize().getQuantity() * Context.getCharWidth()); return CharUnits::Zero(); } @@ -1121,7 +1122,8 @@ CharUnits RecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) { Size = std::max(Size, DataSize); } else - Size = std::max(Size, Offset + Layout.getSize()); + Size = std::max(Size, + Offset + (Layout.getSize().getQuantity() * Context.getCharWidth())); // Remember max struct/class alignment. UpdateAlignment(BaseAlign, UnpackedBaseAlign); @@ -1687,8 +1689,9 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const { IsPODForThePurposeOfLayout ? DataSize : Builder->NonVirtualSize; uint64_t NonVirtualAlign = Builder->NonVirtualAlignment; + CharUnits RecordSize = toCharUnitsFromBits(Builder->Size); NewEntry = - new (*this) ASTRecordLayout(*this, Builder->Size, Builder->Alignment, + new (*this) ASTRecordLayout(*this, RecordSize, Builder->Alignment, DataSize, Builder->FieldOffsets.data(), Builder->FieldOffsets.size(), toCharUnitsFromBits(NonVirtualSize), @@ -1701,8 +1704,10 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const { RecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/0); Builder.Layout(D); + CharUnits RecordSize = toCharUnitsFromBits(Builder.Size); + NewEntry = - new (*this) ASTRecordLayout(*this, Builder.Size, Builder.Alignment, + new (*this) ASTRecordLayout(*this, RecordSize, Builder.Alignment, Builder.Size, Builder.FieldOffsets.data(), Builder.FieldOffsets.size()); @@ -1759,8 +1764,10 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D, RecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/0); Builder.Layout(D); + CharUnits RecordSize = toCharUnitsFromBits(Builder.Size); + const ASTRecordLayout *NewEntry = - new (*this) ASTRecordLayout(*this, Builder.Size, Builder.Alignment, + new (*this) ASTRecordLayout(*this, RecordSize, Builder.Alignment, Builder.DataSize, Builder.FieldOffsets.data(), Builder.FieldOffsets.size()); @@ -1857,7 +1864,7 @@ static void DumpCXXRecordLayout(llvm::raw_ostream &OS, /*IncludeVirtualBases=*/false); } - OS << " sizeof=" << Layout.getSize() / 8; + OS << " sizeof=" << Layout.getSize().getQuantity(); OS << ", dsize=" << Layout.getDataSize() / 8; OS << ", align=" << Layout.getAlignment() / 8 << '\n'; OS << " nvsize=" << Layout.getNonVirtualSize().getQuantity(); @@ -1878,7 +1885,7 @@ void ASTContext::DumpRecordLayout(const RecordDecl *RD, RD->dump(); OS << "\nLayout: "; OS << "<ASTRecordLayout\n"; - OS << " Size:" << Info.getSize() << "\n"; + OS << " Size:" << Info.getSize().getQuantity() * getCharWidth() << "\n"; OS << " DataSize:" << Info.getDataSize() << "\n"; OS << " Alignment:" << Info.getAlignment() << "\n"; OS << " FieldOffsets: ["; diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 4d8a60e1e8..dc84b367cf 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -368,7 +368,7 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) { } } - uint64_t LayoutSizeInBytes = Layout.getSize() / 8; + uint64_t LayoutSizeInBytes = Layout.getSize().getQuantity(); if (NextFieldOffsetInBytes > LayoutSizeInBytes) { // If the struct is bigger than the size of the record type, @@ -394,9 +394,10 @@ bool ConstStructBuilder::Build(InitListExpr *ILE) { } // Append tail padding if necessary. - AppendTailPadding(Layout.getSize()); + AppendTailPadding( + Layout.getSize().getQuantity() * CGM.getContext().getCharWidth()); - assert(Layout.getSize() / 8 == NextFieldOffsetInBytes && + assert(Layout.getSize().getQuantity() == NextFieldOffsetInBytes && "Tail padding mismatch!"); return true; diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 4f65dddfdd..d481e77926 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -1437,7 +1437,8 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) { } // Get the size of instances. - int instanceSize = Context.getASTObjCImplementationLayout(OID).getSize() / 8; + int instanceSize = + Context.getASTObjCImplementationLayout(OID).getSize().getQuantity(); // Collect information about instance variables. llvm::SmallVector<llvm::Constant*, 16> IvarNames; @@ -1447,7 +1448,7 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) { std::vector<llvm::Constant*> IvarOffsetValues; int superInstanceSize = !SuperClassDecl ? 0 : - Context.getASTObjCInterfaceLayout(SuperClassDecl).getSize() / 8; + Context.getASTObjCInterfaceLayout(SuperClassDecl).getSize().getQuantity(); // For non-fragile ivars, set the instance size to 0 - {the size of just this // class}. The runtime will then set this to the correct value on load. if (CGM.getContext().getLangOptions().ObjCNonFragileABI) { diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index be7c79cbb5..3cbb296b0b 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -131,7 +131,8 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, // a synthesized ivar can never be a bit-field, so this is safe. const ASTRecordLayout &RL = CGF.CGM.getContext().getASTObjCInterfaceLayout(OID); - uint64_t TypeSizeInBits = RL.getSize(); + uint64_t TypeSizeInBits = + RL.getSize().getQuantity() * CGF.CGM.getContext().getCharWidth(); uint64_t FieldBitOffset = LookupFieldBitOffset(CGF.CGM, OID, 0, Ivar); uint64_t BitOffset = FieldBitOffset % 8; uint64_t ContainingTypeAlign = 8; @@ -2214,7 +2215,7 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) { if (ID->getNumIvarInitializers()) Flags |= eClassFlags_HasCXXStructors; unsigned Size = - CGM.getContext().getASTObjCImplementationLayout(ID).getSize() / 8; + CGM.getContext().getASTObjCImplementationLayout(ID).getSize().getQuantity(); // FIXME: Set CXX-structors flag. if (ID->getClassInterface()->getVisibility() == HiddenVisibility) diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index e158eed987..e16173b6dc 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -300,7 +300,8 @@ CGBitFieldInfo CGBitFieldInfo::MakeInfo(CodeGenTypes &Types, uint64_t FieldSize) { const RecordDecl *RD = FD->getParent(); const ASTRecordLayout &RL = Types.getContext().getASTRecordLayout(RD); - uint64_t ContainingTypeSizeInBits = RL.getSize(); + uint64_t ContainingTypeSizeInBits = + RL.getSize().getQuantity() * Types.getContext().getCharWidth(); unsigned ContainingTypeAlign = RL.getAlignment(); return MakeInfo(Types, FD, FieldOffset, FieldSize, ContainingTypeSizeInBits, @@ -489,8 +490,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { } // Append tail padding. - if (Layout.getSize() / 8 > Size) - AppendPadding(Layout.getSize() / 8, Align); + if (Layout.getSize().getQuantity() > Size) + AppendPadding(Layout.getSize().getQuantity(), Align); } void CGRecordLayoutBuilder::LayoutBase(const CXXRecordDecl *BaseDecl, @@ -624,7 +625,7 @@ CGRecordLayoutBuilder::ComputeNonVirtualBaseType(const CXXRecordDecl *RD) { // First check if we can use the same fields as for the complete class. - if (AlignedNonVirtualTypeSize == Layout.getSize() / 8) { + if (AlignedNonVirtualTypeSize == Layout.getSize().getQuantity()) { NonVirtualBaseTypeIsSameAsCompleteType = true; return true; } @@ -686,7 +687,8 @@ bool CGRecordLayoutBuilder::LayoutFields(const RecordDecl *D) { } // Append tail padding if necessary. - AppendTailPadding(Layout.getSize()); + AppendTailPadding( + Layout.getSize().getQuantity() * Types.getContext().getCharWidth()); return true; } @@ -851,7 +853,8 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) { // Verify that the computed LLVM struct size matches the AST layout size. const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D); - uint64_t TypeSizeInBits = Layout.getSize(); + uint64_t TypeSizeInBits = + Layout.getSize().getQuantity() * getContext().getCharWidth(); assert(TypeSizeInBits == getTargetData().getTypeAllocSizeInBits(Ty) && "Type size mismatch!"); -- 2.40.0