diff options
author | Anders Carlsson <andersca@mac.com> | 2010-03-25 00:35:49 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-03-25 00:35:49 +0000 |
commit | ff143f8f78f6f2417d4b46d41c83f287485f0aec (patch) | |
tree | 7c3b5df643570034e50f6187618b0b3e1907b563 /lib/CodeGen | |
parent | f0e0b17d0504d25b4673de015cf7401e2296323c (diff) |
Shuffle some code around; this will make it easier to use the new layout code for address points.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGVTT.cpp | 36 | ||||
-rw-r--r-- | lib/CodeGen/CGVtable.cpp | 51 | ||||
-rw-r--r-- | lib/CodeGen/CGVtable.h | 27 |
3 files changed, 57 insertions, 57 deletions
diff --git a/lib/CodeGen/CGVTT.cpp b/lib/CodeGen/CGVTT.cpp index 66a96967de..863eac30d4 100644 --- a/lib/CodeGen/CGVTT.cpp +++ b/lib/CodeGen/CGVTT.cpp @@ -53,26 +53,10 @@ class VTTBuilder { 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 @@ CodeGenVTables::GenerateVTT(llvm::GlobalVariable::LinkageTypes Linkage, 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); diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 890b437c4b..2d32ee82a4 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -1132,8 +1132,10 @@ private: /// 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 @@ void VtableBuilder::dumpLayout(llvm::raw_ostream& Out) { // 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 @@ public: 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 @@ private: 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 @@ private: 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 @@ int64_t CodeGenVTables::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, 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 @@ CodeGenVTables::GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage, 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 @@ CodeGenVTables::GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage, return; } - AddressPointsMapTy AddressPoints; + llvm::DenseMap<BaseSubobject, uint64_t> AddressPoints; Vtable = GenerateVtable(Linkage, /*GenerateDefinition=*/true, RD, RD, 0, /*IsVirtual=*/false, AddressPoints); @@ -3994,6 +3998,37 @@ llvm::Constant *CodeGenVTables::GetAddrOfVTable(const CXXRecordDecl *RD) { 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(); diff --git a/lib/CodeGen/CGVtable.h b/lib/CodeGen/CGVtable.h index 6670b4ed72..28e2bcb084 100644 --- a/lib/CodeGen/CGVtable.h +++ b/lib/CodeGen/CGVtable.h @@ -223,8 +223,6 @@ public: 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 @@ private: /// 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 @@ private: 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 @@ public: /// 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); |