]> granicus.if.org Git - clang/commitdiff
Always emit associated thunks when emitting the function itself. Remove getVtableAddr...
authorAnders Carlsson <andersca@mac.com>
Tue, 23 Mar 2010 04:31:31 +0000 (04:31 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 23 Mar 2010 04:31:31 +0000 (04:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99252 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCXX.cpp
lib/CodeGen/CGVtable.cpp
lib/CodeGen/CGVtable.h
lib/CodeGen/CodeGenModule.cpp

index f788f62f6f7935dfa27aaa9540fcc9d537419eb7..3895e75b8ece6d41f527162a12129a87f22c3b61 100644 (file)
@@ -489,11 +489,17 @@ CodeGenModule::GetAddrOfCovariantThunk(GlobalDecl GD,
 }
 
 void CodeGenModule::BuildThunksForVirtual(GlobalDecl GD) {
+  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
+
+  if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) 
+    GD = GlobalDecl(DD, GD.getDtorType());
+  else
+    GD = MD->getCanonicalDecl();
+  
   CodeGenVTables::AdjustmentVectorTy *AdjPtr = getVTables().getAdjustments(GD);
   if (!AdjPtr)
     return;
   CodeGenVTables::AdjustmentVectorTy &Adj = *AdjPtr;
-  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   for (unsigned i = 0; i < Adj.size(); i++) {
     GlobalDecl OGD = Adj[i].first;
     const CXXMethodDecl *OMD = cast<CXXMethodDecl>(OGD.getDecl());
index 49eea982434d0b966ab059cd5cfe58bd0c415da3..56bea52f28b9154c5713947117a2c2d1d94022b5 100644 (file)
@@ -3662,13 +3662,6 @@ int64_t CodeGenVTables::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
   return I->second;
 }
 
-uint64_t CodeGenVTables::getVtableAddressPoint(const CXXRecordDecl *RD) {
-  uint64_t AddressPoint = 
-    (*(*(CGM.getVTables().AddressPoints[RD]))[RD])[std::make_pair(RD, 0)];
-  
-  return AddressPoint;
-}
-
 llvm::GlobalVariable *
 CodeGenVTables::GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage,
                                bool GenerateDefinition,
@@ -3754,21 +3747,6 @@ CodeGenVTables::GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage,
                           /*IsVirtual=*/false,
                           AddressPoints);
   GenerateVTT(Linkage, /*GenerateDefinition=*/true, RD);
-
-  for (CXXRecordDecl::method_iterator i = RD->method_begin(),
-        e = RD->method_end(); i != e; ++i) {
-    if (!(*i)->isVirtual())
-      continue;
-    if(!(*i)->hasInlineBody() && !(*i)->isImplicit())
-      continue;
-
-    if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(*i)) {
-      CGM.BuildThunksForVirtual(GlobalDecl(DD, Dtor_Complete));
-      CGM.BuildThunksForVirtual(GlobalDecl(DD, Dtor_Deleting));
-    } else {
-      CGM.BuildThunksForVirtual(GlobalDecl(*i));
-    }
-  }
 }
 
 llvm::GlobalVariable *CodeGenVTables::getVtable(const CXXRecordDecl *RD) {
@@ -3792,6 +3770,10 @@ void CodeGenVTables::EmitVTableRelatedData(GlobalDecl GD) {
   if (!RD->isDynamicClass())
     return;
   
+  // Check if we need to emit thunks for this function.
+  if (MD->isVirtual())
+    CGM.BuildThunksForVirtual(GD);
+
   // Get the key function.
   const CXXMethodDecl *KeyFunction = CGM.getContext().getKeyFunction(RD);
   
index f3574987fa20786a617a4eb7d65a2ed269e60e1c..ae2263e2f33d3404af0856312d88c0229752f0db 100644 (file)
@@ -214,11 +214,6 @@ public:
 
   AdjustmentVectorTy *getAdjustments(GlobalDecl GD);
 
-  /// getVtableAddressPoint - returns the address point of the vtable for the
-  /// given record decl.
-  /// FIXME: This should return a list of address points.
-  uint64_t getVtableAddressPoint(const CXXRecordDecl *RD);
-  
   llvm::GlobalVariable *getVtable(const CXXRecordDecl *RD);
   
   /// CtorVtableInfo - Information about a constructor vtable.
index 50ac7a31fca7aa5cc3548fc59099a6268d6e0375..1606710bc5cd66e7ff83c92679d17d0b4736e34f 100644 (file)
@@ -714,20 +714,9 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {
                                  Context.getSourceManager(),
                                  "Generating code for declaration");
   
-  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
+  if (isa<CXXMethodDecl>(D))
     getVTables().EmitVTableRelatedData(GD);
-    if (MD->isVirtual() && MD->isOutOfLine() &&
-        (!isa<CXXDestructorDecl>(D) || GD.getDtorType() != Dtor_Base)) {
-      if (isa<CXXDestructorDecl>(D)) {
-        GlobalDecl CanonGD(cast<CXXDestructorDecl>(D->getCanonicalDecl()),
-                           GD.getDtorType());
-        BuildThunksForVirtual(CanonGD);
-      } else {
-        BuildThunksForVirtual(MD->getCanonicalDecl());
-      }
-    }
-  }
-  
+
   if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D))
     EmitCXXConstructor(CD, GD.getCtorType());
   else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D))
@@ -758,7 +747,7 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName,
     if (WeakRefReferences.count(Entry)) {
       const FunctionDecl *FD = cast_or_null<FunctionDecl>(D.getDecl());
       if (FD && !FD->hasAttr<WeakAttr>())
-       Entry->setLinkage(llvm::Function::ExternalLinkage);
+        Entry->setLinkage(llvm::Function::ExternalLinkage);
 
       WeakRefReferences.erase(Entry);
     }
@@ -873,7 +862,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(llvm::StringRef MangledName,
   if (Entry) {
     if (WeakRefReferences.count(Entry)) {
       if (D && !D->hasAttr<WeakAttr>())
-       Entry->setLinkage(llvm::Function::ExternalLinkage);
+        Entry->setLinkage(llvm::Function::ExternalLinkage);
 
       WeakRefReferences.erase(Entry);
     }