[cfe-commits] r90020 - in /cfe/trunk: include/clang/AST/RecordLayout.h lib/AST/RecordLayoutBuilder.cpp

Anders Carlsson andersca at mac.com
Fri Nov 27 14:14:41 PST 2009


Author: andersca
Date: Fri Nov 27 16:14:40 2009
New Revision: 90020

URL: http://llvm.org/viewvc/llvm-project?rev=90020&view=rev
Log:
Use a PointerIntPair for the PrimaryBaseInfo. Yay for clever LLVM data structures!

Modified:
    cfe/trunk/include/clang/AST/RecordLayout.h
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Modified: cfe/trunk/include/clang/AST/RecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecordLayout.h?rev=90020&r1=90019&r2=90020&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/RecordLayout.h (original)
+++ cfe/trunk/include/clang/AST/RecordLayout.h Fri Nov 27 16:14:40 2009
@@ -50,16 +50,20 @@
 public:
   /// PrimaryBaseInfo - Contains info about a primary base.
   struct PrimaryBaseInfo {
-    PrimaryBaseInfo() : Base(0), IsVirtual(false) {}
+    PrimaryBaseInfo() {}
 
     PrimaryBaseInfo(const CXXRecordDecl *Base, bool IsVirtual)
-      : Base(Base), IsVirtual(IsVirtual) {}
+      : Value(Base, IsVirtual) {}
 
-    /// Base - The primary base.
-    const CXXRecordDecl *Base;
+    /// Value - Points to the primary base. The single-bit value
+    /// will be non-zero when the primary base is virtual.
+    llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> Value;
+    
+    /// getBase - Returns the primary base.
+    const CXXRecordDecl *getBase() const { return Value.getPointer(); }
   
-    /// IsVirtual - Whether the primary base is virtual or not.
-    bool IsVirtual;
+    /// isVirtual - Returns whether the primary base is virtual or not.
+    bool isVirtual() const { return Value.getInt(); }
   }; 
   
 private:
@@ -185,12 +189,12 @@
 
   // FIXME: Migrate off of this function and use getPrimaryBaseInfo directly.
   const CXXRecordDecl *getPrimaryBase() const {
-    return getPrimaryBaseInfo().Base;
+    return getPrimaryBaseInfo().getBase();
   }
 
   // FIXME: Migrate off of this function and use getPrimaryBaseInfo directly.
   bool getPrimaryBaseWasVirtual() const {
-    return getPrimaryBaseInfo().IsVirtual;
+    return getPrimaryBaseInfo().isVirtual();
   }
 
   /// getBaseClassOffset - Get the offset, in bits, for the given base class.

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=90020&r1=90019&r2=90020&view=diff

==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Fri Nov 27 16:14:40 2009
@@ -33,7 +33,7 @@
   }
 
   SelectPrimaryBase(RD);
-  if (!PrimaryBase.Base) {
+  if (!PrimaryBase.getBase()) {
     int AS = 0;
     UpdateAlignment(Ctx.Target.getPointerAlign(AS));
     Size += Ctx.Target.getPointerWidth(AS);
@@ -51,7 +51,7 @@
       const CXXRecordDecl *Base =
         cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
       // Skip the PrimaryBase here, as it is laid down first.
-      if (Base != PrimaryBase.Base || PrimaryBase.IsVirtual)
+      if (Base != PrimaryBase.getBase() || PrimaryBase.isVirtual())
         LayoutBaseNonVirtually(Base, false);
     }
   }
@@ -78,8 +78,8 @@
   
   // If the record has a primary base class that is virtual, add it to the set
   // of primary bases.
-  if (BaseInfo.IsVirtual)
-    IndirectPrimaryBases.insert(BaseInfo.Base);
+  if (BaseInfo.isVirtual())
+    IndirectPrimaryBases.insert(BaseInfo.getBase());
   
   // Now traverse all bases and find primary bases for them.
   for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(),
@@ -107,7 +107,7 @@
       cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
     if (!i->isVirtual()) {
       SelectPrimaryVBase(Base, FirstPrimary);
-      if (PrimaryBase.Base)
+      if (PrimaryBase.getBase())
         return;
       continue;
     }
@@ -169,7 +169,7 @@
 
   // Otherwise if is the first nearly empty virtual base, if one exists,
   // otherwise there is no primary base class.
-  if (!PrimaryBase.Base)
+  if (!PrimaryBase.getBase())
     setPrimaryBase(FirstPrimary, /*IsVirtual=*/true);
 }
 
@@ -236,7 +236,7 @@
     
     if (Base->getNumVBases()) {
       const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Base);
-      const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBaseInfo().Base;
+      const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBaseInfo().getBase();
       LayoutVirtualBases(Class, Base, PrimaryBase, BaseOffset, mark, 
                          IndirectPrimary);
     }
@@ -459,10 +459,10 @@
   if (RD) {
     LayoutVtable(RD);
     // PrimaryBase goes first.
-    if (PrimaryBase.Base) {
-      if (PrimaryBase.IsVirtual)
-        IndirectPrimaryBases.insert(PrimaryBase.Base);
-      LayoutBaseNonVirtually(PrimaryBase.Base, PrimaryBase.IsVirtual);
+    if (PrimaryBase.getBase()) {
+      if (PrimaryBase.isVirtual())
+        IndirectPrimaryBases.insert(PrimaryBase.getBase());
+      LayoutBaseNonVirtually(PrimaryBase.getBase(), PrimaryBase.isVirtual());
     }
     LayoutNonVirtualBases(RD);
   }
@@ -474,7 +474,8 @@
 
   if (RD) {
     llvm::SmallSet<const CXXRecordDecl*, 32> mark;
-    LayoutVirtualBases(RD, RD, PrimaryBase.Base, 0, mark, IndirectPrimaryBases);
+    LayoutVirtualBases(RD, RD, PrimaryBase.getBase(), 
+                       0, mark, IndirectPrimaryBases);
   }
 
   // Finally, round the size of the total struct up to the alignment of the





More information about the cfe-commits mailing list