[cfe-commits] r126034 - /cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Ken Dyck kd at kendyck.com
Sat Feb 19 10:58:07 PST 2011


Author: kjdyck
Date: Sat Feb 19 12:58:07 2011
New Revision: 126034

URL: http://llvm.org/viewvc/llvm-project?rev=126034&view=rev
Log:
Expand use of CharUnits for alignments further. No change in functionality
intended.

Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=126034&r1=126033&r2=126034&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sat Feb 19 12:58:07 2011
@@ -687,8 +687,8 @@
   /// 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 @@
   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 @@
     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 @@
       MaxFieldAlignment = Context.toCharUnitsFromBits(MFAA->getAlignment());
 
     if (unsigned MaxAlign = D->getMaxAlignment())
-      UpdateAlignment(MaxAlign);
+      UpdateAlignment(Context.toCharUnitsFromBits(MaxAlign));
   }
 }
 
@@ -1207,7 +1207,7 @@
   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 @@
   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 @@
   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 @@
   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::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;
   }
 }
 





More information about the cfe-commits mailing list