From c89a7cf3be654e803a173750cc523a3c599e2760 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 11 Mar 2010 16:06:20 +0000 Subject: [PATCH] Use the new vtable layout code for computing virtual base offset offsets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98257 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVtable.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 41fdff17c6..f8b8b01d9f 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -834,6 +834,11 @@ int64_t VCallOffsetMap::getVCallOffsetOffset(const CXXMethodDecl *MD) { /// VCallAndVBaseOffsetBuilder - Class for building vcall and vbase offsets. class VCallAndVBaseOffsetBuilder { +public: + typedef llvm::DenseMap + VBaseOffsetOffsetsMapTy; + +private: /// MostDerivedClass - The most derived class for which we're building vcall /// and vbase offsets. const CXXRecordDecl *MostDerivedClass; @@ -856,8 +861,6 @@ class VCallAndVBaseOffsetBuilder { /// VCallOffsets - Keeps track of vcall offsets. VCallOffsetMap VCallOffsets; - typedef llvm::DenseMap - VBaseOffsetOffsetsMapTy; /// VBaseOffsetOffsets - Contains the offsets of the virtual base offsets, /// relative to the address point. @@ -900,8 +903,8 @@ public: const_iterator components_begin() const { return Components.rbegin(); } const_iterator components_end() const { return Components.rend(); } - const VCallOffsetMap& getVCallOffsets() const { return VCallOffsets; } - const VBaseOffsetOffsetsMapTy getVBaseOffsetOffsets() const { + const VCallOffsetMap &getVCallOffsets() const { return VCallOffsets; } + const VBaseOffsetOffsetsMapTy &getVBaseOffsetOffsets() const { return VBaseOffsetOffsets; } }; @@ -1416,10 +1419,10 @@ VtableBuilder::ComputeReturnAdjustment(BaseOffset Offset) { Offset.VirtualBase); } - // FIXME: Once the assert in getVirtualBaseOffsetIndex is back again, + // FIXME: Once the assert in getVirtualBaseOffsetOffset is back again, // we can get rid of this assert. assert(Adjustment.VBaseOffsetOffset != 0 && - "Invalid base offset offset!"); + "Invalid vbase offset offset!"); } Adjustment.NonVirtual = Offset.NonVirtualOffset; @@ -3453,16 +3456,15 @@ int64_t CGVtableInfo::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, if (I != VirtualBaseClassOffsetOffsets.end()) return I->second; - // FIXME: This seems expensive. Can we do a partial job to get - // just this data. - AddressPointsMapTy AddressPoints; - OldVtableBuilder b(RD, RD, 0, CGM, false, AddressPoints); - D1(printf("vtable %s\n", RD->getNameAsCString())); - b.GenerateVtableForBase(RD); - b.GenerateVtableForVBases(RD); + VCallAndVBaseOffsetBuilder Builder(RD, RD, /*FinalOverriders=*/0, + BaseSubobject(RD, 0), + /*BaseIsVirtual=*/false, + /*OffsetInLayoutClass=*/0); - for (llvm::DenseMap::iterator I = - b.getVBIndex().begin(), E = b.getVBIndex().end(); I != E; ++I) { + + for (VCallAndVBaseOffsetBuilder::VBaseOffsetOffsetsMapTy::const_iterator I = + Builder.getVBaseOffsetOffsets().begin(), + E = Builder.getVBaseOffsetOffsets().end(); I != E; ++I) { // Insert all types. ClassPairTy ClassPair(RD, I->first); @@ -3470,6 +3472,7 @@ int64_t CGVtableInfo::getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, } I = VirtualBaseClassOffsetOffsets.find(ClassPair); + // FIXME: The assertion below assertion currently fails with the old vtable /// layout code if there is a non-virtual thunk adjustment in a vtable. // Once the new layout is in place, this return should be removed. -- 2.40.0