Deleted Added
full compact
CGVTables.h (218893) CGVTables.h (221345)
1//===--- CGVTables.h - Emit LLVM Code for C++ vtables ---------------------===//
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 CLANG_CODEGEN_CGVTABLE_H
15#define CLANG_CODEGEN_CGVTABLE_H
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/GlobalVariable.h"
19#include "clang/Basic/ABI.h"
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 CLANG_CODEGEN_CGVTABLE_H
15#define CLANG_CODEGEN_CGVTABLE_H
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/GlobalVariable.h"
19#include "clang/Basic/ABI.h"
20#include "clang/AST/CharUnits.h"
20#include "GlobalDecl.h"
21
22namespace clang {
23 class CXXRecordDecl;
24
25namespace CodeGen {
26 class CodeGenModule;
27
28// BaseSubobject - Uniquely identifies a direct or indirect base class.
29// Stores both the base class decl and the offset from the most derived class to
30// the base class.
31class BaseSubobject {
32 /// Base - The base class declaration.
33 const CXXRecordDecl *Base;
34
35 /// BaseOffset - The offset from the most derived class to the base class.
21#include "GlobalDecl.h"
22
23namespace clang {
24 class CXXRecordDecl;
25
26namespace CodeGen {
27 class CodeGenModule;
28
29// BaseSubobject - Uniquely identifies a direct or indirect base class.
30// Stores both the base class decl and the offset from the most derived class to
31// the base class.
32class BaseSubobject {
33 /// Base - The base class declaration.
34 const CXXRecordDecl *Base;
35
36 /// BaseOffset - The offset from the most derived class to the base class.
36 uint64_t BaseOffset;
37 CharUnits BaseOffset;
37
38public:
38
39public:
39 BaseSubobject(const CXXRecordDecl *Base, uint64_t BaseOffset)
40 BaseSubobject(const CXXRecordDecl *Base, CharUnits BaseOffset)
40 : Base(Base), BaseOffset(BaseOffset) { }
41
42 /// getBase - Returns the base class declaration.
43 const CXXRecordDecl *getBase() const { return Base; }
44
45 /// getBaseOffset - Returns the base class offset.
41 : Base(Base), BaseOffset(BaseOffset) { }
42
43 /// getBase - Returns the base class declaration.
44 const CXXRecordDecl *getBase() const { return Base; }
45
46 /// getBaseOffset - Returns the base class offset.
46 uint64_t getBaseOffset() const { return BaseOffset; }
47 CharUnits getBaseOffset() const { return BaseOffset; }
47
48 friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) {
49 return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset;
50 }
51};
52
53} // end namespace CodeGen
54} // end namespace clang
55
56namespace llvm {
57
58template<> struct DenseMapInfo<clang::CodeGen::BaseSubobject> {
59 static clang::CodeGen::BaseSubobject getEmptyKey() {
60 return clang::CodeGen::BaseSubobject(
61 DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(),
48
49 friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) {
50 return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset;
51 }
52};
53
54} // end namespace CodeGen
55} // end namespace clang
56
57namespace llvm {
58
59template<> struct DenseMapInfo<clang::CodeGen::BaseSubobject> {
60 static clang::CodeGen::BaseSubobject getEmptyKey() {
61 return clang::CodeGen::BaseSubobject(
62 DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(),
62 DenseMapInfo<uint64_t>::getEmptyKey());
63 clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getEmptyKey()));
63 }
64
65 static clang::CodeGen::BaseSubobject getTombstoneKey() {
66 return clang::CodeGen::BaseSubobject(
67 DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(),
64 }
65
66 static clang::CodeGen::BaseSubobject getTombstoneKey() {
67 return clang::CodeGen::BaseSubobject(
68 DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(),
68 DenseMapInfo<uint64_t>::getTombstoneKey());
69 clang::CharUnits::fromQuantity(DenseMapInfo<int64_t>::getTombstoneKey()));
69 }
70
71 static unsigned getHashValue(const clang::CodeGen::BaseSubobject &Base) {
72 return
73 DenseMapInfo<const clang::CXXRecordDecl *>::getHashValue(Base.getBase()) ^
70 }
71
72 static unsigned getHashValue(const clang::CodeGen::BaseSubobject &Base) {
73 return
74 DenseMapInfo<const clang::CXXRecordDecl *>::getHashValue(Base.getBase()) ^
74 DenseMapInfo<uint64_t>::getHashValue(Base.getBaseOffset());
75 DenseMapInfo<int64_t>::getHashValue(Base.getBaseOffset().getQuantity());
75 }
76
77 static bool isEqual(const clang::CodeGen::BaseSubobject &LHS,
78 const clang::CodeGen::BaseSubobject &RHS) {
79 return LHS == RHS;
80 }
81};
82

--- 14 unchanged lines hidden (view full) ---

97 /// point) where the function pointer for a virtual function is stored.
98 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
99 MethodVTableIndicesTy MethodVTableIndices;
100
101 typedef std::pair<const CXXRecordDecl *,
102 const CXXRecordDecl *> ClassPairTy;
103
104 /// VirtualBaseClassOffsetOffsets - Contains the vtable offset (relative to
76 }
77
78 static bool isEqual(const clang::CodeGen::BaseSubobject &LHS,
79 const clang::CodeGen::BaseSubobject &RHS) {
80 return LHS == RHS;
81 }
82};
83

--- 14 unchanged lines hidden (view full) ---

98 /// point) where the function pointer for a virtual function is stored.
99 typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVTableIndicesTy;
100 MethodVTableIndicesTy MethodVTableIndices;
101
102 typedef std::pair<const CXXRecordDecl *,
103 const CXXRecordDecl *> ClassPairTy;
104
105 /// VirtualBaseClassOffsetOffsets - Contains the vtable offset (relative to
105 /// the address point) in bytes where the offsets for virtual bases of a class
106 /// the address point) in chars where the offsets for virtual bases of a class
106 /// are stored.
107 /// are stored.
107 typedef llvm::DenseMap<ClassPairTy, int64_t>
108 typedef llvm::DenseMap<ClassPairTy, CharUnits>
108 VirtualBaseClassOffsetOffsetsMapTy;
109 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
110
111 /// VTables - All the vtables which have been defined.
112 llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
113
114 /// NumVirtualFunctionPointers - Contains the number of virtual function
115 /// pointers in the vtable for a given record decl.

--- 113 unchanged lines hidden (view full) ---

229 uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
230 BaseSubobject Base);
231
232 /// getMethodVTableIndex - Return the index (relative to the vtable address
233 /// point) where the function pointer for the given virtual function is
234 /// stored.
235 uint64_t getMethodVTableIndex(GlobalDecl GD);
236
109 VirtualBaseClassOffsetOffsetsMapTy;
110 VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets;
111
112 /// VTables - All the vtables which have been defined.
113 llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> VTables;
114
115 /// NumVirtualFunctionPointers - Contains the number of virtual function
116 /// pointers in the vtable for a given record decl.

--- 113 unchanged lines hidden (view full) ---

230 uint64_t getSecondaryVirtualPointerIndex(const CXXRecordDecl *RD,
231 BaseSubobject Base);
232
233 /// getMethodVTableIndex - Return the index (relative to the vtable address
234 /// point) where the function pointer for the given virtual function is
235 /// stored.
236 uint64_t getMethodVTableIndex(GlobalDecl GD);
237
237 /// getVirtualBaseOffsetOffset - Return the offset in bytes (relative to the
238 /// getVirtualBaseOffsetOffset - Return the offset in chars (relative to the
238 /// vtable address point) where the offset of the virtual base that contains
239 /// the given base is stored, otherwise, if no virtual base contains the given
240 /// class, return 0. Base must be a virtual base class or an unambigious
241 /// base.
239 /// vtable address point) where the offset of the virtual base that contains
240 /// the given base is stored, otherwise, if no virtual base contains the given
241 /// class, return 0. Base must be a virtual base class or an unambigious
242 /// base.
242 int64_t getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
243 const CXXRecordDecl *VBase);
243 CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD,
244 const CXXRecordDecl *VBase);
244
245 /// getAddressPoint - Get the address point of the given subobject in the
246 /// class decl.
247 uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD);
248
249 /// GetAddrOfVTable - Get the address of the vtable for the given record decl.
250 llvm::GlobalVariable *GetAddrOfVTable(const CXXRecordDecl *RD);
251
252 /// EmitVTableDefinition - Emit the definition of the given vtable.
253 void EmitVTableDefinition(llvm::GlobalVariable *VTable,
254 llvm::GlobalVariable::LinkageTypes Linkage,
255 const CXXRecordDecl *RD);
256
257 /// GenerateConstructionVTable - Generate a construction vtable for the given
258 /// base subobject.
259 llvm::GlobalVariable *
260 GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base,
261 bool BaseIsVirtual,
245
246 /// getAddressPoint - Get the address point of the given subobject in the
247 /// class decl.
248 uint64_t getAddressPoint(BaseSubobject Base, const CXXRecordDecl *RD);
249
250 /// GetAddrOfVTable - Get the address of the vtable for the given record decl.
251 llvm::GlobalVariable *GetAddrOfVTable(const CXXRecordDecl *RD);
252
253 /// EmitVTableDefinition - Emit the definition of the given vtable.
254 void EmitVTableDefinition(llvm::GlobalVariable *VTable,
255 llvm::GlobalVariable::LinkageTypes Linkage,
256 const CXXRecordDecl *RD);
257
258 /// GenerateConstructionVTable - Generate a construction vtable for the given
259 /// base subobject.
260 llvm::GlobalVariable *
261 GenerateConstructionVTable(const CXXRecordDecl *RD, const BaseSubobject &Base,
262 bool BaseIsVirtual,
263 llvm::GlobalVariable::LinkageTypes Linkage,
262 VTableAddressPointsMapTy& AddressPoints);
263
264
265 /// GetAddrOfVTable - Get the address of the VTT for the given record decl.
266 llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
267
268 /// EmitVTTDefinition - Emit the definition of the given vtable.
269 void EmitVTTDefinition(llvm::GlobalVariable *VTT,

--- 18 unchanged lines hidden ---
264 VTableAddressPointsMapTy& AddressPoints);
265
266
267 /// GetAddrOfVTable - Get the address of the VTT for the given record decl.
268 llvm::GlobalVariable *GetAddrOfVTT(const CXXRecordDecl *RD);
269
270 /// EmitVTTDefinition - Emit the definition of the given vtable.
271 void EmitVTTDefinition(llvm::GlobalVariable *VTT,

--- 18 unchanged lines hidden ---