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