[cfe-commits] r99461 - in /cfe/trunk/lib/CodeGen: CGVTT.cpp CGVtable.cpp CGVtable.h

Anders Carlsson andersca at mac.com
Wed Mar 24 17:35:49 PDT 2010


Author: andersca
Date: Wed Mar 24 19:35:49 2010
New Revision: 99461

URL: http://llvm.org/viewvc/llvm-project?rev=99461&view=rev
Log:
Shuffle some code around; this will make it easier to use the new layout code for address points.

Modified:
    cfe/trunk/lib/CodeGen/CGVTT.cpp
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/lib/CodeGen/CGVtable.h

Modified: cfe/trunk/lib/CodeGen/CGVTT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTT.cpp?rev=99461&r1=99460&r2=99461&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTT.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTT.cpp Wed Mar 24 19:35:49 2010
@@ -53,26 +53,10 @@
 
     llvm::Constant *&CtorVtable = CtorVtables[Base];
     if (!CtorVtable) {
-      // Build the vtable.
-      CodeGenVTables::CtorVtableInfo Info
-        = CGM.getVTables().getCtorVtable(Class, Base, BaseIsVirtual);
-      
-      CtorVtable = Info.Vtable;
-      
-      // Add the address points for this base.
-      for (CodeGenVTables::AddressPointsMapTy::const_iterator I =
-           Info.AddressPoints.begin(), E = Info.AddressPoints.end(); 
-           I != E; ++I) {
-        uint64_t &AddressPoint = 
-          CtorVtableAddressPoints[std::make_pair(Base.getBase(), I->first)];
-        
-        // Check if we already have the address points for this base.
-        if (AddressPoint)
-          break;
-
-        // Otherwise, insert it.
-        AddressPoint = I->second;
-      }      
+      // Get the vtable.
+      CtorVtable = 
+        CGM.getVTables().GenerateConstructionVTable(Class, Base, BaseIsVirtual, 
+                                                    CtorVtableAddressPoints);
     }
     
     return CtorVtable;
@@ -336,18 +320,6 @@
   return GV;
 }
 
-CodeGenVTables::CtorVtableInfo 
-CodeGenVTables::getCtorVtable(const CXXRecordDecl *RD, 
-                            const BaseSubobject &Base, bool BaseIsVirtual) {
-  CtorVtableInfo Info;
-  
-  Info.Vtable = GenerateVtable(llvm::GlobalValue::InternalLinkage,
-                               /*GenerateDefinition=*/true,
-                               RD, Base.getBase(), Base.getBaseOffset(),
-                               BaseIsVirtual, Info.AddressPoints);
-  return Info;
-}
-
 llvm::GlobalVariable *CodeGenVTables::getVTT(const CXXRecordDecl *RD) {
   return GenerateVTT(llvm::GlobalValue::ExternalLinkage, 
                      /*GenerateDefinition=*/false, RD);

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=99461&r1=99460&r2=99461&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Wed Mar 24 19:35:49 2010
@@ -1132,8 +1132,10 @@
   /// Components - The components of the vtable being built.
   llvm::SmallVector<VtableComponent, 64> Components;
 
+  typedef llvm::DenseMap<BaseSubobject, uint64_t> AddressPointsMapTy;
+
   /// AddressPoints - Address points for the vtable being built.
-  CodeGenVTables::AddressPointsMapTy AddressPoints;
+  AddressPointsMapTy AddressPoints;
 
   /// MethodInfo - Contains information about a method in a vtable.
   /// (Used for computing 'this' pointer adjustment thunks.
@@ -2070,8 +2072,8 @@
   // Since an address point can be shared by multiple subobjects, we use an
   // STL multimap.
   std::multimap<uint64_t, BaseSubobject> AddressPointsByIndex;
-  for (CodeGenVTables::AddressPointsMapTy::const_iterator I = 
-       AddressPoints.begin(), E = AddressPoints.end(); I != E; ++I) {
+  for (AddressPointsMapTy::const_iterator I = AddressPoints.begin(), 
+       E = AddressPoints.end(); I != E; ++I) {
     const BaseSubobject& Base = I->first;
     uint64_t Index = I->second;
     
@@ -2335,6 +2337,8 @@
   typedef std::vector<std::pair<GlobalDecl,
                                 std::pair<GlobalDecl, ThunkAdjustment> > >
       SavedAdjustmentsVectorTy;
+  typedef llvm::DenseMap<BaseSubobject, uint64_t> AddressPointsMapTy;
+  
 private:
   
   // VtableComponents - The components of the vtable being built.
@@ -2468,7 +2472,7 @@
   llvm::DenseMap<CtorVtable_t, int64_t> &subAddressPoints;
 
   /// AddressPoints - Address points for this vtable.
-  CodeGenVTables::AddressPointsMapTy& AddressPoints;
+  AddressPointsMapTy& AddressPoints;
   
   typedef CXXRecordDecl::method_iterator method_iter;
   const uint32_t LLVMPointerWidth;
@@ -2692,7 +2696,7 @@
 public:
   OldVtableBuilder(const CXXRecordDecl *MostDerivedClass,
                 const CXXRecordDecl *l, uint64_t lo, CodeGenModule &cgm,
-                  bool build, CodeGenVTables::AddressPointsMapTy& AddressPoints)
+                  bool build, AddressPointsMapTy& AddressPoints)
     : BuildVtable(build), MostDerivedClass(MostDerivedClass), LayoutClass(l),
       LayoutOffset(lo), BLayout(cgm.getContext().getASTRecordLayout(l)),
       rtti(0), VMContext(cgm.getModule().getContext()),CGM(cgm),
@@ -3572,7 +3576,7 @@
 const CodeGenVTables::AddrSubMap_t &
 CodeGenVTables::getAddressPoints(const CXXRecordDecl *RD) {
   if (!AddressPoints[RD]) {
-    AddressPointsMapTy AddressPoints;
+    OldVtableBuilder::AddressPointsMapTy AddressPoints;
     OldVtableBuilder b(RD, RD, 0, CGM, false, AddressPoints);
     
     b.GenerateVtableForBase(RD, 0);
@@ -3588,7 +3592,7 @@
                                const CXXRecordDecl *LayoutClass,
                                const CXXRecordDecl *RD, uint64_t Offset,
                                bool IsVirtual,
-                               AddressPointsMapTy& AddressPoints) {
+                       llvm::DenseMap<BaseSubobject, uint64_t> &AddressPoints) {
   if (GenerateDefinition) {
     if (LayoutClass == RD) {
       assert(!IsVirtual && 
@@ -3962,7 +3966,7 @@
     return;
   }
   
-  AddressPointsMapTy AddressPoints;
+  llvm::DenseMap<BaseSubobject, uint64_t> AddressPoints;
   Vtable = GenerateVtable(Linkage, /*GenerateDefinition=*/true, RD, RD, 0,
                           /*IsVirtual=*/false,
                           AddressPoints);
@@ -3994,6 +3998,37 @@
   return GV;
 }
 
+llvm::GlobalVariable *
+CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD, 
+                                           const BaseSubobject &Base, 
+                                           bool BaseIsVirtual, 
+                                           AddressPointsMapTy& AddressPoints) {
+  
+  llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPoints;
+  
+  llvm::GlobalVariable *VTable =
+    GenerateVtable(llvm::GlobalValue::InternalLinkage,
+                   /*GenerateDefinition=*/true,
+                   RD, Base.getBase(), Base.getBaseOffset(),
+                   BaseIsVirtual, VTableAddressPoints);
+  
+  // Add the address points for this base.
+  for (llvm::DenseMap<BaseSubobject, uint64_t>::const_iterator I =
+       VTableAddressPoints.begin(), E = VTableAddressPoints.end();
+       I != E; ++I) {
+    
+    uint64_t &AddressPoint = 
+      AddressPoints[std::make_pair(Base.getBase(), I->first)];
+    
+    // Check if we already have the address points for this base.
+    assert(!AddressPoint && "Address point already exists for this base!");
+    
+    AddressPoint = I->second;
+  }
+  
+  return VTable;
+}
+
 void CodeGenVTables::EmitVTableRelatedData(GlobalDecl GD) {
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   const CXXRecordDecl *RD = MD->getParent();

Modified: cfe/trunk/lib/CodeGen/CGVtable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.h?rev=99461&r1=99460&r2=99461&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.h (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.h Wed Mar 24 19:35:49 2010
@@ -223,8 +223,6 @@
   typedef llvm::DenseMap<CtorVtable_t, int64_t> AddrSubMap_t;
   typedef llvm::DenseMap<const CXXRecordDecl *, AddrSubMap_t *> AddrMap_t;
 
-  typedef llvm::DenseMap<BaseSubobject, uint64_t> AddressPointsMapTy;
-
   const CodeGenVTables::AddrSubMap_t& getAddressPoints(const CXXRecordDecl *RD);
 
   llvm::DenseMap<const CXXRecordDecl *, AddrMap_t*> AddressPoints;
@@ -269,6 +267,9 @@
   /// integers are the vtable components.
   VTableLayoutMapTy VTableLayoutMap;
 
+  typedef llvm::DenseMap<std::pair<const CXXRecordDecl *, 
+                                   BaseSubobject>, uint64_t> AddressPointsMapTy;
+
   uint64_t getNumVTableComponents(const CXXRecordDecl *RD) const {
     assert(VTableLayoutMap.count(RD) && "No vtable layout for this class!");
     
@@ -288,7 +289,7 @@
   GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage,
                  bool GenerateDefinition, const CXXRecordDecl *LayoutClass, 
                  const CXXRecordDecl *RD, uint64_t Offset, bool IsVirtual,
-                 AddressPointsMapTy& AddressPoints);
+                 llvm::DenseMap<BaseSubobject, uint64_t> &AddressPoints);
 
   llvm::GlobalVariable *GenerateVTT(llvm::GlobalVariable::LinkageTypes Linkage,
                                     bool GenerateDefinition,
@@ -334,20 +335,12 @@
   /// GetAddrOfVTable - Get the address of the vtable for the given record decl.
   llvm::Constant *GetAddrOfVTable(const CXXRecordDecl *RD);
 
-  /// CtorVtableInfo - Information about a constructor vtable.
-  struct CtorVtableInfo {
-    /// Vtable - The vtable itself.
-    llvm::GlobalVariable *Vtable;
-  
-    /// AddressPoints - The address points in this constructor vtable.
-    AddressPointsMapTy AddressPoints;
-    
-    CtorVtableInfo() : Vtable(0) { }
-  };
-  
-  CtorVtableInfo getCtorVtable(const CXXRecordDecl *RD, 
-                               const BaseSubobject &Base,
-                               bool BaseIsVirtual);
+  /// GenerateConstructionVTable - Generate a construction vtable for the given 
+  /// base subobject.
+  llvm::GlobalVariable *
+  GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, 
+                             bool BaseIsVirtual, 
+                             AddressPointsMapTy& AddressPoints);
   
   llvm::GlobalVariable *getVTT(const CXXRecordDecl *RD);
   





More information about the cfe-commits mailing list