leonardchan created this revision. leonardchan added reviewers: pcc, rjmccall, rsmith. leonardchan added a project: clang.
This patch moves the following instances of this snippet: ConstantInitBuilder builder(CGM); auto components = builder.beginStruct(); CGVT.createVTableInitializer(components, VTLayout, RTTI); components.finishAndSetAsInitializer(VTable); into CGCXXABI under a virtual method called `SetVTableInitializer`, which will be in charge of selecting the correct vtable initialization from `CodegenVTables`. This is a prerequisite for landing the relative vtables ABI in Fuchsia (see D72959 <https://reviews.llvm.org/D72959>). The plan is to add a `createRelativeVTableInitializer()` method to `CodegenVTables` which will be a helper for making PIC-friendly vtables. This does not affect any tests. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D77592 Files: clang/lib/CodeGen/CGCXXABI.cpp clang/lib/CodeGen/CGCXXABI.h clang/lib/CodeGen/CGVTables.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1690,10 +1690,7 @@ [](const VTableComponent &VTC) { return VTC.isRTTIKind(); })) RTTI = getMSCompleteObjectLocator(RD, *Info); - ConstantInitBuilder Builder(CGM); - auto Components = Builder.beginStruct(); - CGVT.createVTableInitializer(Components, VTLayout, RTTI); - Components.finishAndSetAsInitializer(VTable); + SetVTableInitializer(CGVT, VTable, VTLayout, RTTI); emitVTableTypeMetadata(*Info, RD, VTable); } Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -493,6 +493,20 @@ explicit FuchsiaCXXABI(CodeGen::CodeGenModule &CGM) : ItaniumCXXABI(CGM) {} + void SetVTableInitializer(CodeGenVTables &CGVT, llvm::GlobalVariable *VTable, + const VTableLayout &VTLayout, + llvm::Constant *RTTI) override { + ConstantInitBuilder builder(CGM); + auto components = builder.beginStruct(); + + // TODO: Replace this with CodeGenVTables::createRelativeVTableInitializer() + // once it is implemented. This will be the helper for the relative-vtables + // ABI. + CGVT.createVTableInitializer(components, VTLayout, RTTI); + + components.finishAndSetAsInitializer(VTable); + } + private: bool HasThisReturn(GlobalDecl GD) const override { return isa<CXXConstructorDecl>(GD.getDecl()) || @@ -1679,10 +1693,7 @@ CGM.GetAddrOfRTTIDescriptor(CGM.getContext().getTagDeclType(RD)); // Create and set the initializer. - ConstantInitBuilder Builder(CGM); - auto Components = Builder.beginStruct(); - CGVT.createVTableInitializer(Components, VTLayout, RTTI); - Components.finishAndSetAsInitializer(VTable); + SetVTableInitializer(CGVT, VTable, VTLayout, RTTI); // Set the correct linkage. VTable->setLinkage(Linkage); Index: clang/lib/CodeGen/CGVTables.cpp =================================================================== --- clang/lib/CodeGen/CGVTables.cpp +++ clang/lib/CodeGen/CGVTables.cpp @@ -806,10 +806,7 @@ CGM.getContext().getTagDeclType(Base.getBase())); // Create and set the initializer. - ConstantInitBuilder builder(CGM); - auto components = builder.beginStruct(); - createVTableInitializer(components, *VTLayout, RTTI); - components.finishAndSetAsInitializer(VTable); + CGM.getCXXABI().SetVTableInitializer(*this, VTable, *VTLayout, RTTI); // Set properties only after the initializer has been set to ensure that the // GV is treated as definition and not declaration. Index: clang/lib/CodeGen/CGCXXABI.h =================================================================== --- clang/lib/CodeGen/CGCXXABI.h +++ clang/lib/CodeGen/CGCXXABI.h @@ -209,6 +209,12 @@ llvm::Value *MemPtr, const MemberPointerType *MPT); + /// Create and set the initializer for the vtable. + virtual void SetVTableInitializer(CodeGenVTables &CGVT, + llvm::GlobalVariable *VTable, + const VTableLayout &VTLayout, + llvm::Constant *RTTI); + protected: /// A utility method for computing the offset required for the given /// base-to-derived or derived-to-base member-pointer conversion. Index: clang/lib/CodeGen/CGCXXABI.cpp =================================================================== --- clang/lib/CodeGen/CGCXXABI.cpp +++ clang/lib/CodeGen/CGCXXABI.cpp @@ -14,6 +14,7 @@ #include "CGCXXABI.h" #include "CGCleanup.h" #include "clang/AST/Attr.h" +#include "clang/CodeGen/ConstantInitBuilder.h" using namespace clang; using namespace CodeGen; @@ -95,6 +96,16 @@ return CGF.Builder.getFalse(); } +void CGCXXABI::SetVTableInitializer(CodeGenVTables &CGVT, + llvm::GlobalVariable *VTable, + const VTableLayout &VTLayout, + llvm::Constant *RTTI) { + ConstantInitBuilder builder(CGM); + auto components = builder.beginStruct(); + CGVT.createVTableInitializer(components, VTLayout, RTTI); + components.finishAndSetAsInitializer(VTable); +} + llvm::Constant * CGCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) { return GetBogusMemberPointer(QualType(MPT, 0));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits