leonardchan updated this revision to Diff 257786. leonardchan retitled this revision from "[NFC}[CodeGen] Make VTable initialization a method of CGCXXABI" to "[NFC][CodeGen] Add enum for selecting the layout of components in the vtable". leonardchan edited the summary of this revision. leonardchan added a comment. Herald added a subscriber: phosek.
I'm not sure how to test it yet without adding all the mechanisms for actually laying out the components, but at the very least this adds the switch for it. If you don't mind the patch getting bigger, I could include the `cc1` option in this patch for selecting the enum and some parts of codegen so we can test this. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D77592/new/ https://reviews.llvm.org/D77592 Files: clang/include/clang/AST/VTableBuilder.h clang/lib/AST/ASTContext.cpp clang/lib/AST/VTableBuilder.cpp clang/lib/CodeGen/CGVTables.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1681,6 +1681,9 @@ // Create and set the initializer. ConstantInitBuilder Builder(CGM); auto Components = Builder.beginStruct(); + // TODO: Check for a Relative VTableComponentLayout, and call a different + // initializer from CodeGenVTables for this relative layout once it is + // implemented. CGVT.createVTableInitializer(Components, VTLayout, RTTI); Components.finishAndSetAsInitializer(VTable); Index: clang/lib/CodeGen/CGVTables.cpp =================================================================== --- clang/lib/CodeGen/CGVTables.cpp +++ clang/lib/CodeGen/CGVTables.cpp @@ -808,6 +808,9 @@ // Create and set the initializer. ConstantInitBuilder builder(CGM); auto components = builder.beginStruct(); + // TODO: Check for a Relative VTableComponentLayout, and call a different + // initializer from CodeGenVTables for this relative layout once it is + // implemented. createVTableInitializer(components, *VTLayout, RTTI); components.finishAndSetAsInitializer(VTable); Index: clang/lib/AST/VTableBuilder.cpp =================================================================== --- clang/lib/AST/VTableBuilder.cpp +++ clang/lib/AST/VTableBuilder.cpp @@ -2221,8 +2221,9 @@ VTableLayout::~VTableLayout() { } -ItaniumVTableContext::ItaniumVTableContext(ASTContext &Context) - : VTableContextBase(/*MS=*/false) {} +ItaniumVTableContext::ItaniumVTableContext( + ASTContext &Context, VTableComponentLayout ComponentLayout) + : VTableContextBase(/*MS=*/false), ComponentLayout(ComponentLayout) {} ItaniumVTableContext::~ItaniumVTableContext() {} Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -10390,6 +10390,8 @@ if (Target->getCXXABI().isMicrosoft()) VTContext.reset(new MicrosoftVTableContext(*this)); else + // TODO: Specify that we want to use the Relative VTableComponentLayout + // here once we add the option for selecting it for Fuchsia. VTContext.reset(new ItaniumVTableContext(*this)); } return VTContext.get(); Index: clang/include/clang/AST/VTableBuilder.h =================================================================== --- clang/include/clang/AST/VTableBuilder.h +++ clang/include/clang/AST/VTableBuilder.h @@ -371,7 +371,17 @@ void computeVTableRelatedInformation(const CXXRecordDecl *RD) override; public: - ItaniumVTableContext(ASTContext &Context); + enum VTableComponentLayout { + /// Components in the vtable are pointers to other structs/functions. + Pointer, + + /// Components in the vtable are relative offsets between the vtable and the + /// other structs/functions. + Relative, + }; + + ItaniumVTableContext(ASTContext &Context, + VTableComponentLayout ComponentLayout = Pointer); ~ItaniumVTableContext() override; const VTableLayout &getVTableLayout(const CXXRecordDecl *RD) { @@ -402,6 +412,16 @@ static bool classof(const VTableContextBase *VT) { return !VT->isMicrosoft(); } + + VTableComponentLayout getVTableComponentLayout() const { + return ComponentLayout; + } + + bool isPointerLayout() const { return ComponentLayout == Pointer; } + bool isRelativeLayout() const { return ComponentLayout == Relative; } + +private: + VTableComponentLayout ComponentLayout; }; /// Holds information about the inheritance path to a virtual base or function
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1681,6 +1681,9 @@ // Create and set the initializer. ConstantInitBuilder Builder(CGM); auto Components = Builder.beginStruct(); + // TODO: Check for a Relative VTableComponentLayout, and call a different + // initializer from CodeGenVTables for this relative layout once it is + // implemented. CGVT.createVTableInitializer(Components, VTLayout, RTTI); Components.finishAndSetAsInitializer(VTable); Index: clang/lib/CodeGen/CGVTables.cpp =================================================================== --- clang/lib/CodeGen/CGVTables.cpp +++ clang/lib/CodeGen/CGVTables.cpp @@ -808,6 +808,9 @@ // Create and set the initializer. ConstantInitBuilder builder(CGM); auto components = builder.beginStruct(); + // TODO: Check for a Relative VTableComponentLayout, and call a different + // initializer from CodeGenVTables for this relative layout once it is + // implemented. createVTableInitializer(components, *VTLayout, RTTI); components.finishAndSetAsInitializer(VTable); Index: clang/lib/AST/VTableBuilder.cpp =================================================================== --- clang/lib/AST/VTableBuilder.cpp +++ clang/lib/AST/VTableBuilder.cpp @@ -2221,8 +2221,9 @@ VTableLayout::~VTableLayout() { } -ItaniumVTableContext::ItaniumVTableContext(ASTContext &Context) - : VTableContextBase(/*MS=*/false) {} +ItaniumVTableContext::ItaniumVTableContext( + ASTContext &Context, VTableComponentLayout ComponentLayout) + : VTableContextBase(/*MS=*/false), ComponentLayout(ComponentLayout) {} ItaniumVTableContext::~ItaniumVTableContext() {} Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -10390,6 +10390,8 @@ if (Target->getCXXABI().isMicrosoft()) VTContext.reset(new MicrosoftVTableContext(*this)); else + // TODO: Specify that we want to use the Relative VTableComponentLayout + // here once we add the option for selecting it for Fuchsia. VTContext.reset(new ItaniumVTableContext(*this)); } return VTContext.get(); Index: clang/include/clang/AST/VTableBuilder.h =================================================================== --- clang/include/clang/AST/VTableBuilder.h +++ clang/include/clang/AST/VTableBuilder.h @@ -371,7 +371,17 @@ void computeVTableRelatedInformation(const CXXRecordDecl *RD) override; public: - ItaniumVTableContext(ASTContext &Context); + enum VTableComponentLayout { + /// Components in the vtable are pointers to other structs/functions. + Pointer, + + /// Components in the vtable are relative offsets between the vtable and the + /// other structs/functions. + Relative, + }; + + ItaniumVTableContext(ASTContext &Context, + VTableComponentLayout ComponentLayout = Pointer); ~ItaniumVTableContext() override; const VTableLayout &getVTableLayout(const CXXRecordDecl *RD) { @@ -402,6 +412,16 @@ static bool classof(const VTableContextBase *VT) { return !VT->isMicrosoft(); } + + VTableComponentLayout getVTableComponentLayout() const { + return ComponentLayout; + } + + bool isPointerLayout() const { return ComponentLayout == Pointer; } + bool isRelativeLayout() const { return ComponentLayout == Relative; } + +private: + VTableComponentLayout ComponentLayout; }; /// Holds information about the inheritance path to a virtual base or function
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits