]> granicus.if.org Git - clang/commitdiff
Use construction vtables when needed. This is currently guarded by -fdump-vtable...
authorAnders Carlsson <andersca@mac.com>
Mon, 29 Mar 2010 01:08:49 +0000 (01:08 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 29 Mar 2010 01:08:49 +0000 (01:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99787 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGClass.cpp

index 17802fc20100f15ac707e04c536f33198cdb8c4d..4b5cffae853c5197a390b06270437f423d0ae979 100644 (file)
@@ -1561,14 +1561,38 @@ CodeGenFunction::InitializeVTablePointer(BaseSubobject Base,
                                          bool BaseIsMorallyVirtual,
                                          llvm::Constant *VTable,
                                          const CXXRecordDecl *VTableClass) {
+  const CXXRecordDecl *RD = Base.getBase();
+
   // Compute the address point.
-  const CodeGenVTables::AddrSubMap_t& AddressPoints =
-    CGM.getVTables().getAddressPoints(VTableClass);
+  llvm::Value *VTableAddressPoint;
+  
+  // FIXME: Always use the new vtable code once we know it works.
+  bool UseNewVTableCode = CGM.getLangOptions().DumpVtableLayouts;
+  
+  // Check if we need to use a vtable from the VTT.
+  if (UseNewVTableCode && CodeGenVTables::needsVTTParameter(CurGD) &&
+      (RD->getNumVBases() || BaseIsMorallyVirtual)) {
+    // Get the secondary vpointer index.
+    uint64_t VirtualPointerIndex = 
+     CGM.getVTables().getSecondaryVirtualPointerIndex(VTableClass, Base);
+    
+    /// Load the VTT.
+    llvm::Value *VTT = LoadCXXVTT();
+    if (VirtualPointerIndex)
+      VTT = Builder.CreateConstInBoundsGEP1_64(VTT, VirtualPointerIndex);
+
+    // And load the address point from the VTT.
+    VTableAddressPoint = Builder.CreateLoad(VTT);
+  } else {
+    const CodeGenVTables::AddrSubMap_t& AddressPoints =
+      CGM.getVTables().getAddressPoints(VTableClass);
   
-  uint64_t AddressPoint = 
-    AddressPoints.lookup(std::make_pair(Base.getBase(), Base.getBaseOffset()));
-  llvm::Value *VTableAddressPoint =
+    uint64_t AddressPoint = 
+      AddressPoints.lookup(std::make_pair(Base.getBase(),
+                                          Base.getBaseOffset()));
+    VTableAddressPoint =
       Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint);
+  }
 
   // Compute where to store the address point.
   const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext());