[cfe-commits] r125156 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/ASTContext.cpp lib/AST/RecordLayout.cpp lib/AST/RecordLayoutBuilder.cpp lib/CodeGen/CGExprConstant.cpp lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CGRecordLayoutBuilder.cpp

Ken Dyck kd at kendyck.com
Tue Feb 8 17:59:35 PST 2011


Author: kjdyck
Date: Tue Feb  8 19:59:34 2011
New Revision: 125156

URL: http://llvm.org/viewvc/llvm-project?rev=125156&view=rev
Log:
Convert RecordLayout::Size to CharUnits from bits. No changes to
functionality intended.

Modified:
    cfe/trunk/include/clang/AST/RecordLayout.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/RecordLayout.cpp
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp

Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Tue Feb  8 19:59:34 2011
@@ -34,7 +34,7 @@
 /// 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 @@
 
   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 @@
   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; }

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Feb  8 19:59:34 2011
@@ -846,7 +846,7 @@
   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 @@
 
     const RecordType *RT = cast<RecordType>(TT);
     const ASTRecordLayout &Layout = getASTRecordLayout(RT->getDecl());
-    Width = Layout.getSize();
+    Width = Layout.getSize().getQuantity() * getCharWidth();
     Align = Layout.getAlignment();
     break;
   }

Modified: cfe/trunk/lib/AST/RecordLayout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayout.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayout.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayout.cpp Tue Feb  8 19:59:34 2011
@@ -27,7 +27,7 @@
   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 @@
 
 // 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,

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue Feb  8 19:59:34 2011
@@ -148,7 +148,7 @@
     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 @@
     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 @@
       if (!CanPlaceFieldSubobjectAtOffset(RD, RD, ElementOffset))
         return false;
 
-      ElementOffset += Context.toCharUnitsFromBits(Layout.getSize());
+      ElementOffset += Layout.getSize();
     }
   }
 
@@ -533,7 +533,7 @@
         return;
 
       UpdateEmptyFieldSubobjects(RD, RD, ElementOffset);
-      ElementOffset += Context.toCharUnitsFromBits(Layout.getSize());
+      ElementOffset += Layout.getSize();
     }
   }
 }
@@ -1091,7 +1091,8 @@
   // 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 @@
 
     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 @@
       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 @@
     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 @@
   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 @@
                         /*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 @@
   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: [";

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Tue Feb  8 19:59:34 2011
@@ -368,7 +368,7 @@
     }
   }
 
-  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 @@
   }
 
   // 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;

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue Feb  8 19:59:34 2011
@@ -1437,7 +1437,8 @@
   }
 
   // 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 @@
   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) {

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Feb  8 19:59:34 2011
@@ -131,7 +131,8 @@
   // 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 @@
   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)

Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=125156&r1=125155&r2=125156&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Tue Feb  8 19:59:34 2011
@@ -300,7 +300,8 @@
                                         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 @@
   }
 
   // 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 @@
   
   
   // 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 @@
   }
   
   // Append tail padding if necessary.
-  AppendTailPadding(Layout.getSize());
+  AppendTailPadding(
+    Layout.getSize().getQuantity() * Types.getContext().getCharWidth());
 
   return true;
 }
@@ -851,7 +853,8 @@
   // 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!");
 





More information about the cfe-commits mailing list