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

Anders Carlsson andersca at mac.com
Tue Jun 8 08:56:03 PDT 2010


Author: andersca
Date: Tue Jun  8 10:56:03 2010
New Revision: 105608

URL: http://llvm.org/viewvc/llvm-project?rev=105608&view=rev
Log:
Minor cleanups to the empty subobject map.

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=105608&r1=105607&r2=105608&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue Jun  8 10:56:03 2010
@@ -65,11 +65,17 @@
   typedef llvm::DenseMap<uint64_t, ClassVectorTy> EmptyClassOffsetsMapTy;
   EmptyClassOffsetsMapTy EmptyClassOffsets;
   
+  /// MaxEmptyClassOffset - The highest offset known to contain an empty
+  /// base subobject.
+  uint64_t MaxEmptyClassOffset;
+  
   /// ComputeEmptySubobjectSizes - Compute the size of the largest base or
   /// member subobject that is empty.
   void ComputeEmptySubobjectSizes();
   
-  bool CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD, uint64_t Offset);
+  bool CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD, 
+                                 uint64_t Offset) const;
+
   void AddSubobjectAtOffset(const CXXRecordDecl *RD, uint64_t Offset);
   
   bool CanPlaceBaseSubobjectAtOffset(const BaseSubobjectInfo *Info,
@@ -79,15 +85,21 @@
   
   bool CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD, 
                                       const CXXRecordDecl *Class,
-                                      uint64_t Offset);
+                                      uint64_t Offset) const;
   bool CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-                                      uint64_t Offset);
+                                      uint64_t Offset) const;
   
   void UpdateEmptyFieldSubobjects(const CXXRecordDecl *RD, 
                                   const CXXRecordDecl *Class,
                                   uint64_t Offset);
   void UpdateEmptyFieldSubobjects(const FieldDecl *FD, uint64_t Offset);
   
+  /// AnyEmptySubobjectsBeyondOffset - Returns whether there are any empty
+  /// subobjects beyond the given offset.
+  bool AnyEmptySubobjectsBeyondOffset(uint64_t Offset) const {
+    return Offset <= MaxEmptyClassOffset;
+  }
+
 public:
   /// This holds the size of the largest empty subobject (either a base
   /// or a member). Will be zero if the record being built doesn't contain
@@ -103,7 +115,8 @@
   /// at the given offset.
   /// Returns false if placing the record will result in two components
   /// (direct or indirect) of the same type having the same offset.
-  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info, uint64_t Offset);
+  bool CanPlaceBaseAtOffset(const BaseSubobjectInfo *Info,
+                            uint64_t Offset);
 
   /// CanPlaceFieldAtOffset - Return whether a field can be placed at the given
   /// offset.
@@ -161,7 +174,7 @@
 
 bool
 EmptySubobjectMap::CanPlaceSubobjectAtOffset(const CXXRecordDecl *RD, 
-                                             uint64_t Offset) {
+                                             uint64_t Offset) const {
   // We only need to check empty bases.
   if (!RD->isEmpty())
     return true;
@@ -189,6 +202,9 @@
          "Duplicate empty class detected!");
     
   Classes.push_back(RD);
+  
+  // Update the empty class offset.
+  MaxEmptyClassOffset = std::max(MaxEmptyClassOffset, Offset);
 }
 
 bool
@@ -273,7 +289,6 @@
   if (!SizeOfLargestEmptySubobject)
     return true;
 
-  // FIXME: Re-enable this.
   if (!CanPlaceBaseSubobjectAtOffset(Info, Offset))
     return false;
 
@@ -286,7 +301,7 @@
 bool
 EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const CXXRecordDecl *RD, 
                                                   const CXXRecordDecl *Class,
-                                                  uint64_t Offset) {
+                                                  uint64_t Offset) const {
   if (!CanPlaceSubobjectAtOffset(RD, Offset))
     return false;
   
@@ -322,7 +337,7 @@
 }
 
 bool EmptySubobjectMap::CanPlaceFieldSubobjectAtOffset(const FieldDecl *FD,
-                                                       uint64_t Offset) {
+                                                       uint64_t Offset) const {
   QualType T = FD->getType();
   if (const RecordType *RT = T->getAs<RecordType>()) {
     const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());





More information about the cfe-commits mailing list