clang  3.7.0
CGVTables.h
Go to the documentation of this file.
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 
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGVTABLES_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGVTABLES_H
16 
18 #include "clang/AST/CharUnits.h"
19 #include "clang/AST/GlobalDecl.h"
21 #include "clang/Basic/ABI.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/IR/GlobalVariable.h"
24 
25 namespace clang {
26  class CXXRecordDecl;
27 
28 namespace CodeGen {
29  class CodeGenModule;
30 
32  CodeGenModule &CGM;
33 
34  VTableContextBase *VTContext;
35 
36  /// VTableAddressPointsMapTy - Address points for a single vtable.
37  typedef llvm::DenseMap<BaseSubobject, uint64_t> VTableAddressPointsMapTy;
38 
39  typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy;
40  typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy;
41 
42  /// SubVTTIndicies - Contains indices into the various sub-VTTs.
43  SubVTTIndiciesMapTy SubVTTIndicies;
44 
45  typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t>
46  SecondaryVirtualPointerIndicesMapTy;
47 
48  /// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer
49  /// indices.
50  SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices;
51 
52  /// emitThunk - Emit a single thunk.
53  void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable);
54 
55  /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by
56  /// the ABI.
57  void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk);
58 
59 public:
60  /// CreateVTableInitializer - Create a vtable initializer for the given record
61  /// decl.
62  /// \param Components - The vtable components; this is really an array of
63  /// VTableComponents.
64  llvm::Constant *CreateVTableInitializer(
65  const CXXRecordDecl *RD, const VTableComponent *Components,
66  unsigned NumComponents, const VTableLayout::VTableThunkTy *VTableThunks,
67  unsigned NumVTableThunks, llvm::Constant *RTTI);
68 
70 
72  return *cast<ItaniumVTableContext>(VTContext);
73  }
74 
76  return *cast<MicrosoftVTableContext>(VTContext);
77  }
78 
79  /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the
80  /// given record decl.
81  uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base);
82 
83  /// getSecondaryVirtualPointerIndex - Return the index in the VTT where the
84  /// virtual pointer for the given subobject is located.
87 
88  /// getAddressPoint - Get the address point of the given subobject in the
89  /// class decl.
90  uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD);
91 
92  /// GenerateConstructionVTable - Generate a construction vtable for the given
93  /// base subobject.
94  llvm::GlobalVariable *
96  bool BaseIsVirtual,
97  llvm::GlobalVariable::LinkageTypes Linkage,
98  VTableAddressPointsMapTy& AddressPoints);
99 
100 
101  /// GetAddrOfVTT - Get the address of the VTT for the given record decl.
102  llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
103 
104  /// EmitVTTDefinition - Emit the definition of the given vtable.
105  void EmitVTTDefinition(llvm::GlobalVariable *VTT,
106  llvm::GlobalVariable::LinkageTypes Linkage,
107  const CXXRecordDecl *RD);
108 
109  /// EmitThunks - Emit the associated thunks for the given global decl.
110  void EmitThunks(GlobalDecl GD);
111 
112  /// GenerateClassData - Generate all the class data required to be
113  /// generated upon definition of a KeyFunction. This includes the
114  /// vtable, the RTTI data structure (if RTTI is enabled) and the VTT
115  /// (if the class has virtual bases).
116  void GenerateClassData(const CXXRecordDecl *RD);
117 
118  bool isVTableExternal(const CXXRecordDecl *RD);
119 };
120 
121 } // end namespace CodeGen
122 } // end namespace clang
123 #endif
void EmitVTTDefinition(llvm::GlobalVariable *VTT, llvm::GlobalVariable::LinkageTypes Linkage, const CXXRecordDecl *RD)
EmitVTTDefinition - Emit the definition of the given vtable.
Definition: CGVTT.cpp:42
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD)
uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base)
Definition: CGVTT.cpp:129
The this pointer adjustment as well as an optional return adjustment for a thunk. ...
Definition: ABI.h:179
Enums/classes describing ABI related information about constructors, destructors and thunks...
ItaniumVTableContext & getItaniumVTableContext()
Definition: CGVTables.h:71
bool isVTableExternal(const CXXRecordDecl *RD)
Definition: CGVTables.cpp:791
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
Definition: CGVTT.cpp:104
Represents a single component in a vtable.
Definition: VTableBuilder.h:31
CodeGenVTables(CodeGenModule &CGM)
Definition: CGVTables.cpp:32
llvm::GlobalVariable * GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, bool BaseIsVirtual, llvm::GlobalVariable::LinkageTypes Linkage, VTableAddressPointsMapTy &AddressPoints)
Definition: CGVTables.cpp:624
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
Definition: CGVTables.cpp:490
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD, BaseSubobject Base)
Definition: CGVTT.cpp:155
void GenerateClassData(const CXXRecordDecl *RD)
Definition: CGVTables.cpp:771
MicrosoftVTableContext & getMicrosoftVTableContext()
Definition: CGVTables.h:75
Represents a C++ struct/union/class.
Definition: DeclCXX.h:285
llvm::Constant * CreateVTableInitializer(const CXXRecordDecl *RD, const VTableComponent *Components, unsigned NumComponents, const VTableLayout::VTableThunkTy *VTableThunks, unsigned NumVTableThunks, llvm::Constant *RTTI)
Definition: CGVTables.cpp:509
std::pair< uint64_t, ThunkInfo > VTableThunkTy