CGVTables.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 CLANG_CODEGEN_CGVTABLE_H
  14. #define CLANG_CODEGEN_CGVTABLE_H
  15. #include "llvm/ADT/DenseMap.h"
  16. #include "llvm/GlobalVariable.h"
  17. #include "clang/Basic/ABI.h"
  18. #include "clang/AST/BaseSubobject.h"
  19. #include "clang/AST/CharUnits.h"
  20. #include "clang/AST/GlobalDecl.h"
  21. #include "clang/AST/VTableBuilder.h"
  22. namespace clang {
  23. class CXXRecordDecl;
  24. namespace CodeGen {
  25. class CodeGenModule;
  26. class CodeGenVTables {
  27. CodeGenModule &CGM;
  28. VTableContext VTContext;
  29. /// VTables - All the vtables which have been defined.
  30. llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
  31. /// VTableAddressPointsMapTy - Address points for a single vtable.
  32. typedef llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPointsMapTy;
  33. typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy;
  34. typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy;
  35. /// SubVTTIndicies - Contains indices into the various sub-VTTs.
  36. SubVTTIndiciesMapTy SubVTTIndicies;
  37. typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t>
  38. SecondaryVirtualPointerIndicesMapTy;
  39. /// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer
  40. /// indices.
  41. SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices;
  42. /// EmitThunk - Emit a single thunk.
  43. void EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
  44. bool UseAvailableExternallyLinkage);
  45. /// MaybeEmitThunkAvailableExternally - Try to emit the given thunk with
  46. /// available_externally linkage to allow for inlining of thunks.
  47. /// This will be done iff optimizations are enabled and the member function
  48. /// doesn't contain any incomplete types.
  49. void MaybeEmitThunkAvailableExternally(GlobalDecl GD, const ThunkInfo &Thunk);
  50. /// CreateVTableInitializer - Create a vtable initializer for the given record
  51. /// decl.
  52. /// \param Components - The vtable components; this is really an array of
  53. /// VTableComponents.
  54. llvm::Constant *CreateVTableInitializer(const CXXRecordDecl *RD,
  55. const VTableComponent *Components,
  56. unsigned NumComponents,
  57. const VTableLayout::VTableThunkTy *VTableThunks,
  58. unsigned NumVTableThunks);
  59. public:
  60. CodeGenVTables(CodeGenModule &CGM);
  61. VTableContext &getVTableContext() { return VTContext; }
  62. /// \brief True if the VTable of this record must be emitted in the
  63. /// translation unit.
  64. bool ShouldEmitVTableInThisTU(const CXXRecordDecl *RD);
  65. /// needsVTTParameter - Return whether the given global decl needs a VTT
  66. /// parameter, which it does if it's a base constructor or destructor with
  67. /// virtual bases.
  68. static bool needsVTTParameter(GlobalDecl GD);
  69. /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the
  70. /// given record decl.
  71. uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base);
  72. /// getSecondaryVirtualPointerIndex - Return the index in the VTT where the
  73. /// virtual pointer for the given subobject is located.
  74. uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
  75. BaseSubobject Base);
  76. /// getAddressPoint - Get the address point of the given subobject in the
  77. /// class decl.
  78. uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD);
  79. /// GetAddrOfVTable - Get the address of the vtable for the given record decl.
  80. llvm::GlobalVariable *GetAddrOfVTable(const CXXRecordDecl *RD);
  81. /// EmitVTableDefinition - Emit the definition of the given vtable.
  82. void EmitVTableDefinition(llvm::GlobalVariable *VTable,
  83. llvm::GlobalVariable::LinkageTypes Linkage,
  84. const CXXRecordDecl *RD);
  85. /// GenerateConstructionVTable - Generate a construction vtable for the given
  86. /// base subobject.
  87. llvm::GlobalVariable *
  88. GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base,
  89. bool BaseIsVirtual,
  90. llvm::GlobalVariable::LinkageTypes Linkage,
  91. VTableAddressPointsMapTy& AddressPoints);
  92. /// GetAddrOfVTable - Get the address of the VTT for the given record decl.
  93. llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
  94. /// EmitVTTDefinition - Emit the definition of the given vtable.
  95. void EmitVTTDefinition(llvm::GlobalVariable *VTT,
  96. llvm::GlobalVariable::LinkageTypes Linkage,
  97. const CXXRecordDecl *RD);
  98. /// EmitThunks - Emit the associated thunks for the given global decl.
  99. void EmitThunks(GlobalDecl GD);
  100. /// GenerateClassData - Generate all the class data required to be generated
  101. /// upon definition of a KeyFunction. This includes the vtable, the
  102. /// rtti data structure and the VTT.
  103. ///
  104. /// \param Linkage - The desired linkage of the vtable, the RTTI and the VTT.
  105. void GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage,
  106. const CXXRecordDecl *RD);
  107. };
  108. } // end namespace CodeGen
  109. } // end namespace clang
  110. #endif