From: Anders Carlsson Date: Tue, 23 Mar 2010 04:31:31 +0000 (+0000) Subject: Always emit associated thunks when emitting the function itself. Remove getVtableAddr... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7270ee4cd4794281c09dfb6931a98bbb2581ef02;p=clang Always emit associated thunks when emitting the function itself. Remove getVtableAddressPoint, it's not used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99252 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index f788f62f6f..3895e75b8e 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -489,11 +489,17 @@ CodeGenModule::GetAddrOfCovariantThunk(GlobalDecl GD, } void CodeGenModule::BuildThunksForVirtual(GlobalDecl GD) { + const CXXMethodDecl *MD = cast(GD.getDecl()); + + if (const CXXDestructorDecl *DD = dyn_cast(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(GD.getDecl()); for (unsigned i = 0; i < Adj.size(); i++) { GlobalDecl OGD = Adj[i].first; const CXXMethodDecl *OMD = cast(OGD.getDecl()); diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 49eea98243..56bea52f28 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -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(*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); diff --git a/lib/CodeGen/CGVtable.h b/lib/CodeGen/CGVtable.h index f3574987fa..ae2263e2f3 100644 --- a/lib/CodeGen/CGVtable.h +++ b/lib/CodeGen/CGVtable.h @@ -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. diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 50ac7a31fc..1606710bc5 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -714,20 +714,9 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) { Context.getSourceManager(), "Generating code for declaration"); - if (const CXXMethodDecl *MD = dyn_cast(D)) { + if (isa(D)) getVTables().EmitVTableRelatedData(GD); - if (MD->isVirtual() && MD->isOutOfLine() && - (!isa(D) || GD.getDtorType() != Dtor_Base)) { - if (isa(D)) { - GlobalDecl CanonGD(cast(D->getCanonicalDecl()), - GD.getDtorType()); - BuildThunksForVirtual(CanonGD); - } else { - BuildThunksForVirtual(MD->getCanonicalDecl()); - } - } - } - + if (const CXXConstructorDecl *CD = dyn_cast(D)) EmitCXXConstructor(CD, GD.getCtorType()); else if (const CXXDestructorDecl *DD = dyn_cast(D)) @@ -758,7 +747,7 @@ CodeGenModule::GetOrCreateLLVMFunction(llvm::StringRef MangledName, if (WeakRefReferences.count(Entry)) { const FunctionDecl *FD = cast_or_null(D.getDecl()); if (FD && !FD->hasAttr()) - 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()) - Entry->setLinkage(llvm::Function::ExternalLinkage); + Entry->setLinkage(llvm::Function::ExternalLinkage); WeakRefReferences.erase(Entry); }