]> granicus.if.org Git - clang/commitdiff
More record layout builder cleanup.
authorAnders Carlsson <andersca@mac.com>
Thu, 11 Mar 2010 02:41:30 +0000 (02:41 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 11 Mar 2010 02:41:30 +0000 (02:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98229 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/RecordLayoutBuilder.cpp
lib/AST/RecordLayoutBuilder.h

index 12e9f04512632431b807fd9c92499bc119c6f39a..eab4f1113708e417b2b80e131e67bb1929729468 100644 (file)
@@ -221,8 +221,7 @@ void ASTRecordLayoutBuilder::LayoutNonVirtualBase(const CXXRecordDecl *RD) {
 void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *Class,
                                                 const CXXRecordDecl *RD,
                                                 const CXXRecordDecl *PB,
-                                                uint64_t Offset,
-                               llvm::SmallSet<const CXXRecordDecl*, 32> &mark) {
+                                                uint64_t Offset) {
   for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
          e = RD->bases_end(); i != e; ++i) {
     assert(!i->getType()->isDependentType() &&
@@ -233,10 +232,10 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *Class,
     if (i->isVirtual()) {
       if (Base == PB) {
         // Only lay things out once.
-        if (mark.count(Base))
+        if (VisitedVirtualBases.count(Base))
           continue;
         // Mark it so we don't lay it out twice.
-        mark.insert(Base);
+        VisitedVirtualBases.insert(Base);
         assert (IndirectPrimaryBases.count(Base) && "IndirectPrimary was wrong");
         VBases.push_back(std::make_pair(Base, Offset));
       } else if (IndirectPrimaryBases.count(Base)) {
@@ -244,10 +243,10 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *Class,
         ;
       } else {
         // Only lay things out once.
-        if (mark.count(Base))
+        if (VisitedVirtualBases.count(Base))
           continue;
         // Mark it so we don't lay it out twice.
-        mark.insert(Base);
+        VisitedVirtualBases.insert(Base);
         LayoutVirtualBase(Base);
         BaseOffset = VBases.back().second;
       }
@@ -263,7 +262,7 @@ void ASTRecordLayoutBuilder::LayoutVirtualBases(const CXXRecordDecl *Class,
     if (Base->getNumVBases()) {
       const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Base);
       const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBaseInfo().getBase();
-      LayoutVirtualBases(Class, Base, PrimaryBase, BaseOffset, mark);
+      LayoutVirtualBases(Class, Base, PrimaryBase, BaseOffset);
     }
   }
 }
@@ -486,8 +485,7 @@ void ASTRecordLayoutBuilder::Layout(const RecordDecl *D) {
   NonVirtualAlignment = Alignment;
 
   if (RD) {
-    llvm::SmallSet<const CXXRecordDecl*, 32> mark;
-    LayoutVirtualBases(RD, RD, PrimaryBase.getBase(), 0, mark);
+    LayoutVirtualBases(RD, RD, PrimaryBase.getBase(), 0);
   }
 
   // Finally, round the size of the total struct up to the alignment of the
index 80bf49d05169d77832cff7b95faa1f43e9bd4b3e..ae3182a6a6203f620987512c723a81f3200a0ff6 100644 (file)
@@ -77,6 +77,10 @@ class ASTRecordLayoutBuilder {
   /// inheritance graph order. Used for determining the primary base class.
   const CXXRecordDecl *FirstNearlyEmptyVBase;
 
+  /// VisitedVirtualBases - A set of all the visited virtual bases, used to
+  /// avoid visiting virtual bases more than once.
+  llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBases;
+  
   /// EmptyClassOffsets - A map from offsets to empty record decls.
   typedef std::multimap<uint64_t, const CXXRecordDecl *> EmptyClassOffsetsTy;
   EmptyClassOffsetsTy EmptyClassOffsets;
@@ -113,8 +117,7 @@ class ASTRecordLayoutBuilder {
 
   /// LayoutVirtualBases - Lays out all the virtual bases.
   void LayoutVirtualBases(const CXXRecordDecl *Class, const CXXRecordDecl *RD,
-                          const CXXRecordDecl *PB, uint64_t Offset, 
-                          llvm::SmallSet<const CXXRecordDecl*, 32> &mark);
+                          const CXXRecordDecl *PB, uint64_t Offset); 
 
   /// LayoutVirtualBase - Lays out a single virtual base.
   void LayoutVirtualBase(const CXXRecordDecl *RD);