Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1 | //===--- CGVtable.h - Emit LLVM Code for C++ vtables ----------------------===// |
| 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" |
Eli Friedman | 72649ed | 2009-12-06 22:01:30 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseSet.h" |
Anders Carlsson | 3527225 | 2009-12-06 00:23:49 +0000 | [diff] [blame] | 19 | #include "llvm/GlobalVariable.h" |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 20 | #include "GlobalDecl.h" |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 21 | |
| 22 | namespace clang { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 23 | class CXXRecordDecl; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 24 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 25 | namespace CodeGen { |
| 26 | class CodeGenModule; |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 27 | |
Anders Carlsson | 80d8d7d | 2010-03-23 15:13:06 +0000 | [diff] [blame] | 28 | /// ReturnAdjustment - A return adjustment. |
| 29 | struct ReturnAdjustment { |
| 30 | /// NonVirtual - The non-virtual adjustment from the derived object to its |
| 31 | /// nearest virtual base. |
| 32 | int64_t NonVirtual; |
| 33 | |
| 34 | /// VBaseOffsetOffset - The offset (in bytes), relative to the address point |
| 35 | /// of the virtual base class offset. |
| 36 | int64_t VBaseOffsetOffset; |
| 37 | |
| 38 | ReturnAdjustment() : NonVirtual(0), VBaseOffsetOffset(0) { } |
| 39 | |
| 40 | bool isEmpty() const { return !NonVirtual && !VBaseOffsetOffset; } |
| 41 | |
| 42 | friend bool operator==(const ReturnAdjustment &LHS, |
| 43 | const ReturnAdjustment &RHS) { |
| 44 | return LHS.NonVirtual == RHS.NonVirtual && |
| 45 | LHS.VBaseOffsetOffset == RHS.VBaseOffsetOffset; |
| 46 | } |
| 47 | |
| 48 | friend bool operator<(const ReturnAdjustment &LHS, |
| 49 | const ReturnAdjustment &RHS) { |
| 50 | if (LHS.NonVirtual < RHS.NonVirtual) |
| 51 | return true; |
| 52 | |
| 53 | return LHS.NonVirtual == RHS.NonVirtual && |
| 54 | LHS.VBaseOffsetOffset < RHS.VBaseOffsetOffset; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | /// ThisAdjustment - A 'this' pointer adjustment. |
| 59 | struct ThisAdjustment { |
| 60 | /// NonVirtual - The non-virtual adjustment from the derived object to its |
| 61 | /// nearest virtual base. |
| 62 | int64_t NonVirtual; |
| 63 | |
| 64 | /// VCallOffsetOffset - The offset (in bytes), relative to the address point, |
| 65 | /// of the virtual call offset. |
| 66 | int64_t VCallOffsetOffset; |
| 67 | |
| 68 | ThisAdjustment() : NonVirtual(0), VCallOffsetOffset(0) { } |
| 69 | |
| 70 | bool isEmpty() const { return !NonVirtual && !VCallOffsetOffset; } |
| 71 | |
| 72 | friend bool operator==(const ThisAdjustment &LHS, |
| 73 | const ThisAdjustment &RHS) { |
| 74 | return LHS.NonVirtual == RHS.NonVirtual && |
| 75 | LHS.VCallOffsetOffset == RHS.VCallOffsetOffset; |
| 76 | } |
| 77 | |
| 78 | friend bool operator<(const ThisAdjustment &LHS, |
| 79 | const ThisAdjustment &RHS) { |
| 80 | if (LHS.NonVirtual < RHS.NonVirtual) |
| 81 | return true; |
| 82 | |
| 83 | return LHS.NonVirtual == RHS.NonVirtual && |
| 84 | LHS.VCallOffsetOffset < RHS.VCallOffsetOffset; |
| 85 | } |
Anders Carlsson | 80d8d7d | 2010-03-23 15:13:06 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Anders Carlsson | b4e4c96 | 2010-03-23 15:17:13 +0000 | [diff] [blame] | 88 | /// ThunkInfo - The 'this' pointer adjustment as well as an optional return |
| 89 | /// adjustment for a thunk. |
| 90 | struct ThunkInfo { |
| 91 | /// This - The 'this' pointer adjustment. |
| 92 | ThisAdjustment This; |
| 93 | |
| 94 | /// Return - The return adjustment. |
| 95 | ReturnAdjustment Return; |
| 96 | |
| 97 | ThunkInfo() { } |
| 98 | |
| 99 | ThunkInfo(const ThisAdjustment &This, const ReturnAdjustment &Return) |
| 100 | : This(This), Return(Return) { } |
| 101 | |
| 102 | friend bool operator==(const ThunkInfo &LHS, const ThunkInfo &RHS) { |
| 103 | return LHS.This == RHS.This && LHS.Return == RHS.Return; |
| 104 | } |
| 105 | |
| 106 | friend bool operator<(const ThunkInfo &LHS, const ThunkInfo &RHS) { |
| 107 | if (LHS.This < RHS.This) |
| 108 | return true; |
| 109 | |
| 110 | return LHS.This == RHS.This && LHS.Return < RHS.Return; |
| 111 | } |
| 112 | |
| 113 | bool isEmpty() const { return This.isEmpty() && Return.isEmpty(); } |
| 114 | }; |
| 115 | |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 116 | /// ThunkAdjustment - Virtual and non-virtual adjustment for thunks. |
| 117 | class ThunkAdjustment { |
| 118 | public: |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 119 | ThunkAdjustment(int64_t NonVirtual, int64_t Virtual) |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 120 | : NonVirtual(NonVirtual), |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 121 | Virtual(Virtual) { } |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 122 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 123 | ThunkAdjustment() |
| 124 | : NonVirtual(0), Virtual(0) { } |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 125 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 126 | // isEmpty - Return whether this thunk adjustment is empty. |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 127 | bool isEmpty() const { |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 128 | return NonVirtual == 0 && Virtual == 0; |
| 129 | } |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 130 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 131 | /// NonVirtual - The non-virtual adjustment. |
| 132 | int64_t NonVirtual; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 133 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 134 | /// Virtual - The virtual adjustment. |
| 135 | int64_t Virtual; |
| 136 | }; |
| 137 | |
Anders Carlsson | 7622cd3 | 2009-11-26 03:09:37 +0000 | [diff] [blame] | 138 | /// CovariantThunkAdjustment - Adjustment of the 'this' pointer and the |
| 139 | /// return pointer for covariant thunks. |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 140 | class CovariantThunkAdjustment { |
| 141 | public: |
Anders Carlsson | 7622cd3 | 2009-11-26 03:09:37 +0000 | [diff] [blame] | 142 | CovariantThunkAdjustment(const ThunkAdjustment &ThisAdjustment, |
| 143 | const ThunkAdjustment &ReturnAdjustment) |
| 144 | : ThisAdjustment(ThisAdjustment), ReturnAdjustment(ReturnAdjustment) { } |
| 145 | |
| 146 | CovariantThunkAdjustment() { } |
| 147 | |
| 148 | ThunkAdjustment ThisAdjustment; |
| 149 | ThunkAdjustment ReturnAdjustment; |
| 150 | }; |
| 151 | |
Anders Carlsson | 6b4333d | 2010-01-13 20:11:15 +0000 | [diff] [blame] | 152 | // BaseSubobject - Uniquely identifies a direct or indirect base class. |
| 153 | // Stores both the base class decl and the offset from the most derived class to |
| 154 | // the base class. |
| 155 | class BaseSubobject { |
| 156 | /// Base - The base class declaration. |
| 157 | const CXXRecordDecl *Base; |
| 158 | |
| 159 | /// BaseOffset - The offset from the most derived class to the base class. |
| 160 | uint64_t BaseOffset; |
| 161 | |
| 162 | public: |
| 163 | BaseSubobject(const CXXRecordDecl *Base, uint64_t BaseOffset) |
| 164 | : Base(Base), BaseOffset(BaseOffset) { } |
| 165 | |
| 166 | /// getBase - Returns the base class declaration. |
| 167 | const CXXRecordDecl *getBase() const { return Base; } |
| 168 | |
| 169 | /// getBaseOffset - Returns the base class offset. |
| 170 | uint64_t getBaseOffset() const { return BaseOffset; } |
Anders Carlsson | 7e37a69 | 2010-01-14 01:39:42 +0000 | [diff] [blame] | 171 | |
Anders Carlsson | 6b4333d | 2010-01-13 20:11:15 +0000 | [diff] [blame] | 172 | friend bool operator==(const BaseSubobject &LHS, const BaseSubobject &RHS) { |
| 173 | return LHS.Base == RHS.Base && LHS.BaseOffset == RHS.BaseOffset; |
| 174 | } |
| 175 | }; |
Anders Carlsson | 7e37a69 | 2010-01-14 01:39:42 +0000 | [diff] [blame] | 176 | |
| 177 | } // end namespace CodeGen |
| 178 | } // end namespace clang |
| 179 | |
| 180 | namespace llvm { |
| 181 | |
| 182 | template<> struct DenseMapInfo<clang::CodeGen::BaseSubobject> { |
| 183 | static clang::CodeGen::BaseSubobject getEmptyKey() { |
| 184 | return clang::CodeGen::BaseSubobject( |
| 185 | DenseMapInfo<const clang::CXXRecordDecl *>::getEmptyKey(), |
| 186 | DenseMapInfo<uint64_t>::getEmptyKey()); |
| 187 | } |
| 188 | |
| 189 | static clang::CodeGen::BaseSubobject getTombstoneKey() { |
| 190 | return clang::CodeGen::BaseSubobject( |
| 191 | DenseMapInfo<const clang::CXXRecordDecl *>::getTombstoneKey(), |
| 192 | DenseMapInfo<uint64_t>::getTombstoneKey()); |
| 193 | } |
| 194 | |
| 195 | static unsigned getHashValue(const clang::CodeGen::BaseSubobject &Base) { |
| 196 | return |
| 197 | DenseMapInfo<const clang::CXXRecordDecl *>::getHashValue(Base.getBase()) ^ |
| 198 | DenseMapInfo<uint64_t>::getHashValue(Base.getBaseOffset()); |
| 199 | } |
| 200 | |
| 201 | static bool isEqual(const clang::CodeGen::BaseSubobject &LHS, |
| 202 | const clang::CodeGen::BaseSubobject &RHS) { |
| 203 | return LHS == RHS; |
| 204 | } |
| 205 | }; |
| 206 | |
Anders Carlsson | 1bb6099 | 2010-01-14 02:29:07 +0000 | [diff] [blame] | 207 | // It's OK to treat BaseSubobject as a POD type. |
| 208 | template <> struct isPodLike<clang::CodeGen::BaseSubobject> { |
| 209 | static const bool value = true; |
| 210 | }; |
| 211 | |
Anders Carlsson | 7e37a69 | 2010-01-14 01:39:42 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | namespace clang { |
| 215 | namespace CodeGen { |
| 216 | |
Anders Carlsson | af44035 | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 217 | class CodeGenVTables { |
Eli Friedman | b455f0e | 2009-12-07 23:56:34 +0000 | [diff] [blame] | 218 | public: |
| 219 | typedef std::vector<std::pair<GlobalDecl, ThunkAdjustment> > |
| 220 | AdjustmentVectorTy; |
| 221 | |
Anders Carlsson | 21431c5 | 2010-01-02 18:02:32 +0000 | [diff] [blame] | 222 | typedef std::pair<const CXXRecordDecl *, uint64_t> CtorVtable_t; |
| 223 | typedef llvm::DenseMap<CtorVtable_t, int64_t> AddrSubMap_t; |
| 224 | typedef llvm::DenseMap<const CXXRecordDecl *, AddrSubMap_t *> AddrMap_t; |
Anders Carlsson | 21431c5 | 2010-01-02 18:02:32 +0000 | [diff] [blame] | 225 | |
Anders Carlsson | 1bb6099 | 2010-01-14 02:29:07 +0000 | [diff] [blame] | 226 | typedef llvm::DenseMap<BaseSubobject, uint64_t> AddressPointsMapTy; |
| 227 | |
Anders Carlsson | 5c6c1d9 | 2010-03-24 03:57:14 +0000 | [diff] [blame] | 228 | const CodeGenVTables::AddrSubMap_t& getAddressPoints(const CXXRecordDecl *RD); |
| 229 | |
| 230 | llvm::DenseMap<const CXXRecordDecl *, AddrMap_t*> AddressPoints; |
| 231 | |
Eli Friedman | b455f0e | 2009-12-07 23:56:34 +0000 | [diff] [blame] | 232 | private: |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 233 | CodeGenModule &CGM; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 234 | |
Anders Carlsson | 5c6c1d9 | 2010-03-24 03:57:14 +0000 | [diff] [blame] | 235 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 236 | /// MethodVtableIndices - Contains the index (relative to the vtable address |
| 237 | /// point) where the function pointer for a virtual function is stored. |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 238 | typedef llvm::DenseMap<GlobalDecl, int64_t> MethodVtableIndicesTy; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 239 | MethodVtableIndicesTy MethodVtableIndices; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 240 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 241 | typedef std::pair<const CXXRecordDecl *, |
| 242 | const CXXRecordDecl *> ClassPairTy; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 243 | |
Anders Carlsson | bba1607 | 2010-03-11 07:15:17 +0000 | [diff] [blame] | 244 | /// VirtualBaseClassOffsetOffsets - Contains the vtable offset (relative to |
| 245 | /// the address point) in bytes where the offsets for virtual bases of a class |
| 246 | /// are stored. |
| 247 | typedef llvm::DenseMap<ClassPairTy, int64_t> |
| 248 | VirtualBaseClassOffsetOffsetsMapTy; |
| 249 | VirtualBaseClassOffsetOffsetsMapTy VirtualBaseClassOffsetOffsets; |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 250 | |
Anders Carlsson | 8c2d36f | 2009-12-06 00:01:05 +0000 | [diff] [blame] | 251 | /// Vtables - All the vtables which have been defined. |
| 252 | llvm::DenseMap<const CXXRecordDecl *, llvm::GlobalVariable *> Vtables; |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 253 | |
| 254 | /// NumVirtualFunctionPointers - Contains the number of virtual function |
| 255 | /// pointers in the vtable for a given record decl. |
| 256 | llvm::DenseMap<const CXXRecordDecl *, uint64_t> NumVirtualFunctionPointers; |
| 257 | |
Anders Carlsson | fbf6ed4 | 2010-03-23 16:36:50 +0000 | [diff] [blame] | 258 | typedef llvm::SmallVector<ThunkInfo, 1> ThunkInfoVectorTy; |
| 259 | typedef llvm::DenseMap<const CXXMethodDecl *, ThunkInfoVectorTy> ThunksMapTy; |
| 260 | |
| 261 | /// Thunks - Contains all thunks that a given method decl will need. |
| 262 | ThunksMapTy Thunks; |
Anders Carlsson | fbf6ed4 | 2010-03-23 16:36:50 +0000 | [diff] [blame] | 263 | |
Anders Carlsson | ccd83d7 | 2010-03-24 16:42:11 +0000 | [diff] [blame] | 264 | typedef llvm::DenseMap<const CXXRecordDecl *, uint64_t *> VTableLayoutMapTy; |
| 265 | |
| 266 | /// VTableLayoutMap - Stores the vtable layout for all record decls. |
| 267 | /// The layout is stored as an array of 64-bit integers, where the first |
| 268 | /// integer is the number of vtable entries in the layout, and the subsequent |
| 269 | /// integers are the vtable components. |
| 270 | VTableLayoutMapTy VTableLayoutMap; |
| 271 | |
| 272 | uint64_t getNumVTableComponents(const CXXRecordDecl *RD) const { |
| 273 | assert(VTableLayoutMap.count(RD) && "No vtable layout for this class!"); |
| 274 | |
| 275 | return VTableLayoutMap.lookup(RD)[0]; |
| 276 | } |
| 277 | |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 278 | typedef llvm::DenseMap<ClassPairTy, uint64_t> SubVTTIndiciesTy; |
| 279 | SubVTTIndiciesTy SubVTTIndicies; |
| 280 | |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 281 | /// getNumVirtualFunctionPointers - Return the number of virtual function |
| 282 | /// pointers in the vtable for a given record decl. |
| 283 | uint64_t getNumVirtualFunctionPointers(const CXXRecordDecl *RD); |
| 284 | |
| 285 | void ComputeMethodVtableIndices(const CXXRecordDecl *RD); |
Rafael Espindola | bbf58bb | 2010-03-10 02:19:29 +0000 | [diff] [blame] | 286 | |
Anders Carlsson | 3527225 | 2009-12-06 00:23:49 +0000 | [diff] [blame] | 287 | llvm::GlobalVariable * |
Anders Carlsson | 3527225 | 2009-12-06 00:23:49 +0000 | [diff] [blame] | 288 | GenerateVtable(llvm::GlobalVariable::LinkageTypes Linkage, |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 289 | bool GenerateDefinition, const CXXRecordDecl *LayoutClass, |
Anders Carlsson | 5d7af6b | 2010-02-28 00:36:23 +0000 | [diff] [blame] | 290 | const CXXRecordDecl *RD, uint64_t Offset, bool IsVirtual, |
Anders Carlsson | 1bb6099 | 2010-01-14 02:29:07 +0000 | [diff] [blame] | 291 | AddressPointsMapTy& AddressPoints); |
Anders Carlsson | c3a46ef | 2009-12-06 01:09:21 +0000 | [diff] [blame] | 292 | |
| 293 | llvm::GlobalVariable *GenerateVTT(llvm::GlobalVariable::LinkageTypes Linkage, |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 294 | bool GenerateDefinition, |
Anders Carlsson | c3a46ef | 2009-12-06 01:09:21 +0000 | [diff] [blame] | 295 | const CXXRecordDecl *RD); |
| 296 | |
Anders Carlsson | fbf6ed4 | 2010-03-23 16:36:50 +0000 | [diff] [blame] | 297 | /// EmitThunk - Emit a single thunk. |
| 298 | void EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk); |
| 299 | |
Anders Carlsson | ee5ab9f | 2010-03-23 04:59:02 +0000 | [diff] [blame] | 300 | /// EmitThunks - Emit the associated thunks for the given global decl. |
| 301 | void EmitThunks(GlobalDecl GD); |
| 302 | |
Anders Carlsson | ccd83d7 | 2010-03-24 16:42:11 +0000 | [diff] [blame] | 303 | /// ComputeVTableRelatedInformation - Compute and store all vtable related |
| 304 | /// information (vtable layout, vbase offset offsets, thunks etc) for the |
| 305 | /// given record decl. |
| 306 | void ComputeVTableRelatedInformation(const CXXRecordDecl *RD); |
| 307 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 308 | public: |
Anders Carlsson | af44035 | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 309 | CodeGenVTables(CodeGenModule &CGM) |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 310 | : CGM(CGM) { } |
| 311 | |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 312 | /// needsVTTParameter - Return whether the given global decl needs a VTT |
| 313 | /// parameter, which it does if it's a base constructor or destructor with |
| 314 | /// virtual bases. |
| 315 | static bool needsVTTParameter(GlobalDecl GD); |
| 316 | |
| 317 | /// getSubVTTIndex - Return the index of the sub-VTT for the base class of the |
| 318 | /// given record decl. |
| 319 | uint64_t getSubVTTIndex(const CXXRecordDecl *RD, const CXXRecordDecl *Base); |
| 320 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 321 | /// getMethodVtableIndex - Return the index (relative to the vtable address |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 322 | /// point) where the function pointer for the given virtual function is |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 323 | /// stored. |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 324 | uint64_t getMethodVtableIndex(GlobalDecl GD); |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 325 | |
Anders Carlsson | bba1607 | 2010-03-11 07:15:17 +0000 | [diff] [blame] | 326 | /// getVirtualBaseOffsetOffset - Return the offset in bytes (relative to the |
| 327 | /// vtable address point) where the offset of the virtual base that contains |
| 328 | /// the given base is stored, otherwise, if no virtual base contains the given |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 329 | /// class, return 0. Base must be a virtual base class or an unambigious |
| 330 | /// base. |
Anders Carlsson | bba1607 | 2010-03-11 07:15:17 +0000 | [diff] [blame] | 331 | int64_t getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, |
| 332 | const CXXRecordDecl *VBase); |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 333 | |
Anders Carlsson | 5eea876 | 2010-03-24 05:32:05 +0000 | [diff] [blame] | 334 | /// GetAddrOfVTable - Get the address of the vtable for the given record decl. |
| 335 | llvm::Constant *GetAddrOfVTable(const CXXRecordDecl *RD); |
Anders Carlsson | 5c6c1d9 | 2010-03-24 03:57:14 +0000 | [diff] [blame] | 336 | |
Anders Carlsson | 1bb6099 | 2010-01-14 02:29:07 +0000 | [diff] [blame] | 337 | /// CtorVtableInfo - Information about a constructor vtable. |
| 338 | struct CtorVtableInfo { |
| 339 | /// Vtable - The vtable itself. |
| 340 | llvm::GlobalVariable *Vtable; |
| 341 | |
| 342 | /// AddressPoints - The address points in this constructor vtable. |
| 343 | AddressPointsMapTy AddressPoints; |
| 344 | |
| 345 | CtorVtableInfo() : Vtable(0) { } |
| 346 | }; |
| 347 | |
| 348 | CtorVtableInfo getCtorVtable(const CXXRecordDecl *RD, |
Anders Carlsson | 5d7af6b | 2010-02-28 00:36:23 +0000 | [diff] [blame] | 349 | const BaseSubobject &Base, |
| 350 | bool BaseIsVirtual); |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 351 | |
Anders Carlsson | c997d42 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 352 | llvm::GlobalVariable *getVTT(const CXXRecordDecl *RD); |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 353 | |
Anders Carlsson | 13189d0 | 2010-03-23 04:15:00 +0000 | [diff] [blame] | 354 | // EmitVTableRelatedData - Will emit any thunks that the global decl might |
| 355 | // have, as well as the vtable itself if the global decl is the key function. |
| 356 | void EmitVTableRelatedData(GlobalDecl GD); |
Rafael Espindola | bbf58bb | 2010-03-10 02:19:29 +0000 | [diff] [blame] | 357 | |
Anders Carlsson | 7986ad5 | 2010-03-23 18:18:41 +0000 | [diff] [blame] | 358 | /// GenerateClassData - Generate all the class data required to be generated |
Rafael Espindola | bbf58bb | 2010-03-10 02:19:29 +0000 | [diff] [blame] | 359 | /// upon definition of a KeyFunction. This includes the vtable, the |
| 360 | /// rtti data structure and the VTT. |
| 361 | /// |
| 362 | /// \param Linkage - The desired linkage of the vtable, the RTTI and the VTT. |
| 363 | void GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage, |
| 364 | const CXXRecordDecl *RD); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 365 | }; |
Benjamin Kramer | 39411b9 | 2009-11-26 13:09:03 +0000 | [diff] [blame] | 366 | |
Anders Carlsson | 1bb6099 | 2010-01-14 02:29:07 +0000 | [diff] [blame] | 367 | } // end namespace CodeGen |
| 368 | } // end namespace clang |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 369 | #endif |