From 2a50f239a90d670b3911cae9024b363cbfae87cc Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 20 Dec 2013 23:58:52 +0000 Subject: [PATCH] Eliminate the ItaniumVTableContext object from CodeGenVTables Now CodeGenVTables has only one VTableContext object, which is either Itanium or Microsoft. Fixes a FIXME with no functionality change intended. Ideally we could avoid the downcasts by pushing the things that reference the Itanium vtable context into ItaniumCXXABI.cpp, but we're not there yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197845 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/VTableBuilder.h | 18 +++++++++++++++--- lib/AST/VTableBuilder.cpp | 5 +---- lib/CodeGen/CGVTT.cpp | 3 ++- lib/CodeGen/CGVTables.cpp | 23 ++++++++--------------- lib/CodeGen/CGVTables.h | 12 ++++++------ 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/include/clang/AST/VTableBuilder.h b/include/clang/AST/VTableBuilder.h index 4e451324d7..02061d437d 100644 --- a/include/clang/AST/VTableBuilder.h +++ b/include/clang/AST/VTableBuilder.h @@ -270,6 +270,10 @@ class VTableContextBase { public: typedef SmallVector ThunkInfoVectorTy; + bool isMicrosoft() const { return IsMicrosoftABI; } + + virtual ~VTableContextBase() {} + protected: typedef llvm::DenseMap ThunksMapTy; @@ -280,7 +284,7 @@ protected: /// offset offsets, thunks etc) for the given record decl. virtual void computeVTableRelatedInformation(const CXXRecordDecl *RD) = 0; - virtual ~VTableContextBase() {} + VTableContextBase(bool MS) : IsMicrosoftABI(MS) {} public: virtual const ThunkInfoVectorTy *getThunkInfo(GlobalDecl GD) { @@ -297,11 +301,12 @@ public: return &I->second; } + + bool IsMicrosoftABI; }; class ItaniumVTableContext : public VTableContextBase { private: - bool IsMicrosoftABI; /// \brief Contains the index (relative to the vtable address point) /// where the function pointer for a virtual function is stored. @@ -355,6 +360,10 @@ public: /// Base must be a virtual base class or an unambiguous base. CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase); + + static bool classof(const VTableContextBase *VT) { + return !VT->isMicrosoft(); + } }; struct VFPtrInfo { @@ -481,7 +490,8 @@ private: void computeVBTableRelatedInformation(const CXXRecordDecl *RD); public: - MicrosoftVTableContext(ASTContext &Context) : Context(Context) {} + MicrosoftVTableContext(ASTContext &Context) + : VTableContextBase(/*MS=*/true), Context(Context) {} ~MicrosoftVTableContext() { llvm::DeleteContainerSeconds(VFTableLayouts); } @@ -512,6 +522,8 @@ public: "VBase must be a vbase of Derived"); return VBTableIndices[Pair]; } + + static bool classof(const VTableContextBase *VT) { return VT->isMicrosoft(); } }; } diff --git a/lib/AST/VTableBuilder.cpp b/lib/AST/VTableBuilder.cpp index 63ac6f2c4a..408fbad17a 100644 --- a/lib/AST/VTableBuilder.cpp +++ b/lib/AST/VTableBuilder.cpp @@ -2282,8 +2282,7 @@ VTableLayout::VTableLayout(uint64_t NumVTableComponents, VTableLayout::~VTableLayout() { } ItaniumVTableContext::ItaniumVTableContext(ASTContext &Context) - : IsMicrosoftABI(Context.getTargetInfo().getCXXABI().isMicrosoft()) { -} + : VTableContextBase(/*MS=*/false) {} ItaniumVTableContext::~ItaniumVTableContext() { llvm::DeleteContainerSeconds(VTableLayouts); @@ -2348,8 +2347,6 @@ static VTableLayout *CreateVTableLayout(const ItaniumVTableBuilder &Builder) { void ItaniumVTableContext::computeVTableRelatedInformation(const CXXRecordDecl *RD) { - assert(!IsMicrosoftABI && "Shouldn't be called in this ABI!"); - const VTableLayout *&Entry = VTableLayouts[RD]; // Check if we've computed this information before. diff --git a/lib/CodeGen/CGVTT.cpp b/lib/CodeGen/CGVTT.cpp index bfff470588..bca5f29d94 100644 --- a/lib/CodeGen/CGVTT.cpp +++ b/lib/CodeGen/CGVTT.cpp @@ -66,7 +66,8 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT, if (VTTVT.getBase() == RD) { // Just get the address point for the regular vtable. AddressPoint = - ItaniumVTContext.getVTableLayout(RD).getAddressPoint(i->VTableBase); + getItaniumVTableContext().getVTableLayout(RD).getAddressPoint( + i->VTableBase); assert(AddressPoint != 0 && "Did not find vtable address point!"); } else { AddressPoint = VTableAddressPoints[i->VTableIndex].lookup(i->VTableBase); diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index a5967fddf2..2edce5d27d 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -29,14 +29,11 @@ using namespace clang; using namespace CodeGen; -CodeGenVTables::CodeGenVTables(CodeGenModule &CGM) - : CGM(CGM), ItaniumVTContext(CGM.getContext()) { - if (CGM.getTarget().getCXXABI().isMicrosoft()) { - // FIXME: Eventually, we should only have one of V*TContexts available. - // Today we use both in the Microsoft ABI as MicrosoftVFTableContext - // is not completely supported in CodeGen yet. - MicrosoftVTContext.reset(new MicrosoftVTableContext(CGM.getContext())); - } +CodeGenVTables::CodeGenVTables(CodeGenModule &CGM) : CGM(CGM) { + if (CGM.getTarget().getCXXABI().isMicrosoft()) + VTContext.reset(new MicrosoftVTableContext(CGM.getContext())); + else + VTContext.reset(new ItaniumVTableContext(CGM.getContext())); } llvm::Constant *CodeGenModule::GetAddrOfThunk(GlobalDecl GD, @@ -465,12 +462,8 @@ void CodeGenVTables::EmitThunks(GlobalDecl GD) if (isa(MD) && GD.getDtorType() == Dtor_Base) return; - const VTableContextBase::ThunkInfoVectorTy *ThunkInfoVector; - if (MicrosoftVTContext.isValid()) { - ThunkInfoVector = MicrosoftVTContext->getThunkInfo(GD); - } else { - ThunkInfoVector = ItaniumVTContext.getThunkInfo(GD); - } + const VTableContextBase::ThunkInfoVectorTy *ThunkInfoVector = + VTContext->getThunkInfo(GD); if (!ThunkInfoVector) return; @@ -608,7 +601,7 @@ CodeGenVTables::GenerateConstructionVTable(const CXXRecordDecl *RD, DI->completeClassData(Base.getBase()); OwningPtr VTLayout( - ItaniumVTContext.createConstructionVTableLayout( + getItaniumVTableContext().createConstructionVTableLayout( Base.getBase(), Base.getBaseOffset(), BaseIsVirtual, RD)); // Add the address points. diff --git a/lib/CodeGen/CGVTables.h b/lib/CodeGen/CGVTables.h index e8cd55eed8..a8768c22cc 100644 --- a/lib/CodeGen/CGVTables.h +++ b/lib/CodeGen/CGVTables.h @@ -31,10 +31,8 @@ namespace CodeGen { class CodeGenVTables { CodeGenModule &CGM; - // FIXME: Consider moving ItaniumVTContext and MicrosoftVTContext into - // respective CXXABI classes? - ItaniumVTableContext ItaniumVTContext; - OwningPtr MicrosoftVTContext; + // FIXME: Consider moving VTContext into respective CXXABI classes? + OwningPtr VTContext; /// VTableAddressPointsMapTy - Address points for a single vtable. typedef llvm::DenseMap VTableAddressPointsMapTy; @@ -72,10 +70,12 @@ public: CodeGenVTables(CodeGenModule &CGM); - ItaniumVTableContext &getItaniumVTableContext() { return ItaniumVTContext; } + ItaniumVTableContext &getItaniumVTableContext() { + return *cast(VTContext.get()); + } MicrosoftVTableContext &getMicrosoftVTableContext() { - return *MicrosoftVTContext.get(); + return *cast(VTContext.get()); } /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the -- 2.40.0