[cfe-commits] r104013 - in /cfe/trunk/lib/CodeGen: CGRecordLayout.h CGRecordLayoutBuilder.cpp

Anders Carlsson andersca at mac.com
Mon May 17 22:22:06 PDT 2010


Author: andersca
Date: Tue May 18 00:22:06 2010
New Revision: 104013

URL: http://llvm.org/viewvc/llvm-project?rev=104013&view=rev
Log:
Keep track of the LLVM field numbers for non-virtual bases.

Modified:
    cfe/trunk/lib/CodeGen/CGRecordLayout.h
    cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp

Modified: cfe/trunk/lib/CodeGen/CGRecordLayout.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayout.h?rev=104013&r1=104012&r2=104013&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayout.h (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayout.h Tue May 18 00:22:06 2010
@@ -168,6 +168,10 @@
   /// field no. This info is populated by record builder.
   llvm::DenseMap<const FieldDecl *, CGBitFieldInfo> BitFields;
 
+  // FIXME: Maybe we could use a CXXBaseSpecifier as the key and use a single
+  // map for both virtual and non virtual bases.
+  llvm::DenseMap<const CXXRecordDecl *, unsigned> NonVirtualBaseFields;
+
   /// Whether one of the fields in this record layout is a pointer to data
   /// member, or a struct that contains pointer to data member.
   bool ContainsPointerToDataMember : 1;
@@ -194,6 +198,11 @@
     return FieldInfo.lookup(FD);
   }
 
+  unsigned getNonVirtualBaseLLVMFieldNo(const CXXRecordDecl *RD) const {
+    assert(NonVirtualBaseFields.count(RD) && "Invalid non-virtual base!");
+    return NonVirtualBaseFields.lookup(RD);
+  }
+
   /// \brief Return the BitFieldInfo that corresponds to the field FD.
   const CGBitFieldInfo &getBitFieldInfo(const FieldDecl *FD) const {
     assert(FD->isBitField() && "Invalid call for non bit-field decl!");

Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=104013&r1=104012&r2=104013&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Tue May 18 00:22:06 2010
@@ -42,6 +42,9 @@
   typedef std::pair<const FieldDecl *, CGBitFieldInfo> LLVMBitFieldInfo;
   llvm::SmallVector<LLVMBitFieldInfo, 16> LLVMBitFields;
 
+  typedef std::pair<const CXXRecordDecl *, unsigned> LLVMBaseInfo;
+  llvm::SmallVector<LLVMBaseInfo, 16> LLVMNonVirtualBases;
+  
   /// ContainsPointerToDataMember - Whether one of the fields in this record
   /// layout is a pointer to data member, or a struct that contains pointer to
   /// data member.
@@ -148,6 +151,7 @@
   FieldTypes.clear();
   LLVMFields.clear();
   LLVMBitFields.clear();
+  LLVMNonVirtualBases.clear();
 
   LayoutFields(D);
 }
@@ -454,6 +458,10 @@
 
   // FIXME: Actually use a better type than [sizeof(BaseDecl) x i8] when we can.
   AppendPadding(BaseOffset / 8, 1);
+  
+  // Append the base field.
+  LLVMNonVirtualBases.push_back(LLVMBaseInfo(BaseDecl, FieldTypes.size()));
+
   AppendBytes(NonVirtualSize / 8);
 }
 
@@ -633,13 +641,17 @@
   CGRecordLayout *RL =
     new CGRecordLayout(Ty, Builder.ContainsPointerToDataMember);
 
+  // Add all the non-virtual base field numbers.
+  RL->NonVirtualBaseFields.insert(Builder.LLVMNonVirtualBases.begin(),
+                                  Builder.LLVMNonVirtualBases.end());
+
   // Add all the field numbers.
-  for (unsigned i = 0, e = Builder.LLVMFields.size(); i != e; ++i)
-    RL->FieldInfo.insert(Builder.LLVMFields[i]);
+  RL->FieldInfo.insert(Builder.LLVMFields.begin(),
+                       Builder.LLVMFields.end());
 
   // Add bitfield info.
-  for (unsigned i = 0, e = Builder.LLVMBitFields.size(); i != e; ++i)
-    RL->BitFields.insert(Builder.LLVMBitFields[i]);
+  RL->BitFields.insert(Builder.LLVMBitFields.begin(),
+                       Builder.LLVMBitFields.end());
 
   // Dump the layout, if requested.
   if (getContext().getLangOptions().DumpRecordLayouts) {





More information about the cfe-commits mailing list