CGVTables.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //===--- CGVTables.h - Emit LLVM Code for C++ vtables -----------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This contains code dealing with C++ code generation of virtual tables.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_LIB_CODEGEN_CGVTABLES_H
  14. #define LLVM_CLANG_LIB_CODEGEN_CGVTABLES_H
  15. #include "clang/AST/BaseSubobject.h"
  16. #include "clang/AST/CharUnits.h"
  17. #include "clang/AST/GlobalDecl.h"
  18. #include "clang/AST/VTableBuilder.h"
  19. #include "clang/Basic/ABI.h"
  20. #include "llvm/ADT/DenseMap.h"
  21. #include "llvm/IR/GlobalVariable.h"
  22. namespace clang {
  23. class CXXRecordDecl;
  24. namespace CodeGen {
  25. class CodeGenModule;
  26. class CodeGenVTables {
  27. CodeGenModule &CGM;
  28. VTableContextBase *VTContext;
  29. /// VTableAddressPointsMapTy - Address points for a single vtable.
  30. typedef llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPointsMapTy;
  31. typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy;
  32. typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy;
  33. /// SubVTTIndicies - Contains indices into the various sub-VTTs.
  34. SubVTTIndiciesMapTy SubVTTIndicies;
  35. typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t>
  36. SecondaryVirtualPointerIndicesMapTy;
  37. /// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer
  38. /// indices.
  39. SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices;
  40. /// emitThunk - Emit a single thunk.
  41. void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable);
  42. /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by
  43. /// the ABI.
  44. void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk);
  45. public:
  46. /// CreateVTableInitializer - Create a vtable initializer for the given record
  47. /// decl.
  48. /// \param Components - The vtable components; this is really an array of
  49. /// VTableComponents.
  50. llvm::Constant *CreateVTableInitializer(
  51. const CXXRecordDecl *RD, const VTableComponent *Components,
  52. unsigned NumComponents, const VTableLayout::VTableThunkTy *VTableThunks,
  53. unsigned NumVTableThunks, llvm::Constant *RTTI);
  54. CodeGenVTables(CodeGenModule &CGM);
  55. ItaniumVTableContext &getItaniumVTableContext() {
  56. return *cast<ItaniumVTableContext>(VTContext);
  57. }
  58. MicrosoftVTableContext &getMicrosoftVTableContext() {
  59. return *cast<MicrosoftVTableContext>(VTContext);
  60. }
  61. /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the
  62. /// given record decl.
  63. uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base);
  64. /// getSecondaryVirtualPointerIndex - Return the index in the VTT where the
  65. /// virtual pointer for the given subobject is located.
  66. uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
  67. BaseSubobject Base);
  68. /// getAddressPoint - Get the address point of the given subobject in the
  69. /// class decl.
  70. uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD);
  71. /// GenerateConstructionVTable - Generate a construction vtable for the given
  72. /// base subobject.
  73. llvm::GlobalVariable *
  74. GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base,
  75. bool BaseIsVirtual,
  76. llvm::GlobalVariable::LinkageTypes Linkage,
  77. VTableAddressPointsMapTy& AddressPoints);
  78. /// GetAddrOfVTT - Get the address of the VTT for the given record decl.
  79. llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
  80. /// EmitVTTDefinition - Emit the definition of the given vtable.
  81. void EmitVTTDefinition(llvm::GlobalVariable *VTT,
  82. llvm::GlobalVariable::LinkageTypes Linkage,
  83. const CXXRecordDecl *RD);
  84. /// EmitThunks - Emit the associated thunks for the given global decl.
  85. void EmitThunks(GlobalDecl GD);
  86. /// GenerateClassData - Generate all the class data required to be
  87. /// generated upon definition of a KeyFunction. This includes the
  88. /// vtable, the RTTI data structure (if RTTI is enabled) and the VTT
  89. /// (if the class has virtual bases).
  90. void GenerateClassData(const CXXRecordDecl *RD);
  91. bool isVTableExternal(const CXXRecordDecl *RD);
  92. };
  93. } // end namespace CodeGen
  94. } // end namespace clang
  95. #endif