clang  6.0.0svn
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  class ConstantArrayBuilder;
31  class ConstantStructBuilder;
32 
34  CodeGenModule &CGM;
35 
36  VTableContextBase *VTContext;
37 
38  /// VTableAddressPointsMapTy - Address points for a single vtable.
39  typedef VTableLayout::AddressPointsMapTy VTableAddressPointsMapTy;
40 
41  typedef std::pair<const CXXRecordDecl *, BaseSubobject> BaseSubobjectPairTy;
42  typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t> SubVTTIndiciesMapTy;
43 
44  /// SubVTTIndicies - Contains indices into the various sub-VTTs.
45  SubVTTIndiciesMapTy SubVTTIndicies;
46 
47  typedef llvm::DenseMap<BaseSubobjectPairTy, uint64_t>
48  SecondaryVirtualPointerIndicesMapTy;
49 
50  /// SecondaryVirtualPointerIndices - Contains the secondary virtual pointer
51  /// indices.
52  SecondaryVirtualPointerIndicesMapTy SecondaryVirtualPointerIndices;
53 
54  /// Cache for the pure virtual member call function.
55  llvm::Constant *PureVirtualFn = nullptr;
56 
57  /// Cache for the deleted virtual member call function.
58  llvm::Constant *DeletedVirtualFn = nullptr;
59 
60  /// emitThunk - Emit a single thunk.
61  void emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, bool ForVTable);
62 
63  /// maybeEmitThunkForVTable - Emit the given thunk for the vtable if needed by
64  /// the ABI.
65  void maybeEmitThunkForVTable(GlobalDecl GD, const ThunkInfo &Thunk);
66 
67  void addVTableComponent(ConstantArrayBuilder &builder,
68  const VTableLayout &layout, unsigned idx,
69  llvm::Constant *rtti,
70  unsigned &nextVTableThunkIndex);
71 
72 public:
73  /// Add vtable components for the given vtable layout to the given
74  /// global initializer.
76  const VTableLayout &layout,
77  llvm::Constant *rtti);
78 
80 
82  return *cast<ItaniumVTableContext>(VTContext);
83  }
84 
86  return *cast<MicrosoftVTableContext>(VTContext);
87  }
88 
89  /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the
90  /// given record decl.
91  uint64_t getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base);
92 
93  /// getSecondaryVirtualPointerIndex - Return the index in the VTT where the
94  /// virtual pointer for the given subobject is located.
96  BaseSubobject Base);
97 
98  /// GenerateConstructionVTable - Generate a construction vtable for the given
99  /// base subobject.
100  llvm::GlobalVariable *
102  bool BaseIsVirtual,
103  llvm::GlobalVariable::LinkageTypes Linkage,
104  VTableAddressPointsMapTy& AddressPoints);
105 
106 
107  /// GetAddrOfVTT - Get the address of the VTT for the given record decl.
108  llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
109 
110  /// EmitVTTDefinition - Emit the definition of the given vtable.
111  void EmitVTTDefinition(llvm::GlobalVariable *VTT,
112  llvm::GlobalVariable::LinkageTypes Linkage,
113  const CXXRecordDecl *RD);
114 
115  /// EmitThunks - Emit the associated thunks for the given global decl.
116  void EmitThunks(GlobalDecl GD);
117 
118  /// GenerateClassData - Generate all the class data required to be
119  /// generated upon definition of a KeyFunction. This includes the
120  /// vtable, the RTTI data structure (if RTTI is enabled) and the VTT
121  /// (if the class has virtual bases).
122  void GenerateClassData(const CXXRecordDecl *RD);
123 
124  bool isVTableExternal(const CXXRecordDecl *RD);
125 
126  /// Returns the type of a vtable with the given layout. Normally a struct of
127  /// arrays of pointers, with one struct element for each vtable in the vtable
128  /// group.
129  llvm::Type *getVTableType(const VTableLayout &layout);
130 };
131 
132 } // end namespace CodeGen
133 } // end namespace clang
134 #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 getSubVTTIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSubVTTIndex - Return the index of the sub-VTT for the base class of the given record decl...
Definition: CGVTT.cpp:130
llvm::Type * getVTableType(const VTableLayout &layout)
Returns the type of a vtable with the given layout.
Definition: CGVTables.cpp:672
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:81
bool isVTableExternal(const CXXRecordDecl *RD)
At this point in the translation unit, does it appear that can we rely on the vtable being defined el...
Definition: CGVTables.cpp:879
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:35
The l-value was considered opaque, so the alignment was determined from a type.
llvm::GlobalVariable * GetAddrOfVTT(const CXXRecordDecl *RD)
GetAddrOfVTT - Get the address of the VTT for the given record decl.
Definition: CGVTT.cpp:106
CodeGenVTables(CodeGenModule &CGM)
Definition: CGVTables.cpp:31
void createVTableInitializer(ConstantStructBuilder &builder, const VTableLayout &layout, llvm::Constant *rtti)
Add vtable components for the given vtable layout to the given global initializer.
Definition: CGVTables.cpp:681
llvm::GlobalVariable * GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base, bool BaseIsVirtual, llvm::GlobalVariable::LinkageTypes Linkage, VTableAddressPointsMapTy &AddressPoints)
GenerateConstructionVTable - Generate a construction vtable for the given base subobject.
Definition: CGVTables.cpp:697
This class organizes the cross-function state that is used while generating LLVM code.
Dataflow Directional Tag Classes.
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
Definition: CGVTables.cpp:541
uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD, BaseSubobject Base)
getSecondaryVirtualPointerIndex - Return the index in the VTT where the virtual pointer for the given...
Definition: CGVTT.cpp:156
void GenerateClassData(const CXXRecordDecl *RD)
GenerateClassData - Generate all the class data required to be generated upon definition of a KeyFunc...
Definition: CGVTables.cpp:859
MicrosoftVTableContext & getMicrosoftVTableContext()
Definition: CGVTables.h:85
llvm::DenseMap< BaseSubobject, AddressPointLocation > AddressPointsMapTy
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
A helper class of ConstantInitBuilder, used for building constant struct initializers.
A helper class of ConstantInitBuilder, used for building constant array initializers.