]> granicus.if.org Git - clang/commitdiff
Start fleshing out construction vtable support.
authorAnders Carlsson <andersca@mac.com>
Sat, 27 Feb 2010 20:39:05 +0000 (20:39 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 27 Feb 2010 20:39:05 +0000 (20:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97342 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVtable.cpp

index af1db88221948f42207c1ad4d1d5b94a30d9ab33..457bfa559cce015f4116ef6a3be5fea9f2745c94 100644 (file)
@@ -1058,6 +1058,15 @@ private:
   /// vtable.
   const CXXRecordDecl *MostDerivedClass;
 
+  /// MostDerivedClassOffset - If we're building a construction vtable, this
+  /// holds the offset from the layout class to the most derived class.
+  const uint64_t MostDerivedClassOffset;
+  
+  /// LayoutClass - The class we're using for layout information. Will be 
+  /// different than the most derived class if we're building a construction
+  /// vtable.
+  const CXXRecordDecl *LayoutClass;
+  
   /// Context - The ASTContext which we will use for layout information.
   ASTContext &Context;
   
@@ -1215,9 +1224,12 @@ private:
                                     VisitedVirtualBasesSetTy &VBases);
 
 public:
-  VtableBuilder(CGVtableInfo &VtableInfo, const CXXRecordDecl *MostDerivedClass)
-    : VtableInfo(VtableInfo), MostDerivedClass(MostDerivedClass), 
-    Context(MostDerivedClass->getASTContext()), Overriders(MostDerivedClass) { 
+  VtableBuilder(CGVtableInfo &VtableInfo, const CXXRecordDecl *MostDerivedClass,
+                uint64_t MostDerivedClassOffset, 
+                const CXXRecordDecl *LayoutClass)
+    : VtableInfo(VtableInfo), MostDerivedClass(MostDerivedClass),
+    MostDerivedClassOffset(MostDerivedClassOffset), LayoutClass(LayoutClass),
+    Context(MostDerivedClass->getASTContext()), Overriders(MostDerivedClass) {
 
     LayoutVtable();
   }
@@ -1808,8 +1820,17 @@ VtableBuilder::LayoutVtablesForVirtualBases(const CXXRecordDecl *RD,
 
 /// dumpLayout - Dump the vtable layout.
 void VtableBuilder::dumpLayout(llvm::raw_ostream& Out) {
-  
-  Out << "Vtable for '" << MostDerivedClass->getQualifiedNameAsString();
+
+  if (MostDerivedClass == LayoutClass) {
+    Out << "Vtable for '";
+    Out << MostDerivedClass->getQualifiedNameAsString();
+  } else {
+    Out << "Construction vtable for ('";
+    Out << MostDerivedClass->getQualifiedNameAsString() << "', ";
+    // FIXME: Don't use / 8 .
+    Out << MostDerivedClassOffset / 8 << ") in '";
+    Out << LayoutClass->getQualifiedNameAsString();
+  }
   Out << "' (" << Components.size() << " entries).\n";
 
   // Iterate through the address points and insert them into a new map where
@@ -1983,7 +2004,8 @@ void VtableBuilder::dumpLayout(llvm::raw_ostream& Out) {
 
     Out << '\n';
   }
-  
+
+  Out << '\n';
 }
   
 }
@@ -3272,11 +3294,17 @@ CGVtableInfo::GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage,
                              const CXXRecordDecl *LayoutClass,
                              const CXXRecordDecl *RD, uint64_t Offset,
                              AddressPointsMapTy& AddressPoints) {
-  if (GenerateDefinition && LayoutClass == RD) {
-    VtableBuilder Builder(*this, RD);
-
-    if (CGM.getLangOptions().DumpVtableLayouts)
+  if (GenerateDefinition) {
+    if (LayoutClass == RD) {
+      VtableBuilder Builder(*this, RD, Offset, LayoutClass);
+
+      if (CGM.getLangOptions().DumpVtableLayouts)
+        Builder.dumpLayout(llvm::errs());
+    } else if (CGM.getLangOptions().DumpVtableLayouts) {
+      // We only build construction vtables when dumping vtable layouts for now.
+      VtableBuilder Builder(*this, RD, Offset, LayoutClass);
       Builder.dumpLayout(llvm::errs());
+    }
   }
 
   llvm::SmallString<256> OutName;