Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1 | //===--- CGVtable.cpp - 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 | #include "CodeGenModule.h" |
| 15 | #include "CodeGenFunction.h" |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 16 | #include "clang/AST/CXXInheritance.h" |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 17 | #include "clang/AST/RecordLayout.h" |
Anders Carlsson | 5dd730a | 2009-11-26 19:32:45 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/DenseSet.h" |
Zhongxing Xu | 7fe26ac | 2009-11-13 05:46:16 +0000 | [diff] [blame] | 19 | #include <cstdio> |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace clang; |
| 22 | using namespace CodeGen; |
| 23 | |
Anders Carlsson | 27f69d0 | 2009-11-27 22:21:51 +0000 | [diff] [blame] | 24 | namespace { |
Benjamin Kramer | 85b4521 | 2009-11-28 19:45:26 +0000 | [diff] [blame] | 25 | class VtableBuilder { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 26 | public: |
| 27 | /// Index_t - Vtable index type. |
| 28 | typedef uint64_t Index_t; |
| 29 | private: |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 30 | |
| 31 | // Vtable - The components of the vtable being built. |
Anders Carlsson | a22fd85 | 2009-12-04 16:24:46 +0000 | [diff] [blame] | 32 | typedef llvm::SmallVector<llvm::Constant *, 64> VtableVectorTy; |
| 33 | VtableVectorTy Vtable; |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 34 | const bool BuildVtable; |
| 35 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 36 | llvm::Type *Ptr8Ty; |
Anders Carlsson | ac3f7bd | 2009-12-04 18:36:22 +0000 | [diff] [blame] | 37 | |
| 38 | /// MostDerivedClass - The most derived class that this vtable is being |
| 39 | /// built for. |
| 40 | const CXXRecordDecl *MostDerivedClass; |
| 41 | |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 42 | /// LayoutClass - The most derived class used for virtual base layout |
| 43 | /// information. |
| 44 | const CXXRecordDecl *LayoutClass; |
Mike Stump | 4cde626 | 2009-11-13 02:13:54 +0000 | [diff] [blame] | 45 | /// LayoutOffset - The offset for Class in LayoutClass. |
| 46 | uint64_t LayoutOffset; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 47 | /// BLayout - Layout for the most derived class that this vtable is being |
| 48 | /// built for. |
| 49 | const ASTRecordLayout &BLayout; |
| 50 | llvm::SmallSet<const CXXRecordDecl *, 32> IndirectPrimary; |
| 51 | llvm::SmallSet<const CXXRecordDecl *, 32> SeenVBase; |
| 52 | llvm::Constant *rtti; |
| 53 | llvm::LLVMContext &VMContext; |
| 54 | CodeGenModule &CGM; // Per-module state. |
Anders Carlsson | 0e88116 | 2009-12-04 03:46:21 +0000 | [diff] [blame] | 55 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 56 | llvm::DenseMap<GlobalDecl, Index_t> VCall; |
| 57 | llvm::DenseMap<GlobalDecl, Index_t> VCallOffset; |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 58 | // This is the offset to the nearest virtual base |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 59 | llvm::DenseMap<GlobalDecl, Index_t> NonVirtualOffset; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 60 | llvm::DenseMap<const CXXRecordDecl *, Index_t> VBIndex; |
Mike Stump | 94aff93 | 2009-10-27 23:46:47 +0000 | [diff] [blame] | 61 | |
Anders Carlsson | 6d4ccb7 | 2009-11-26 19:54:33 +0000 | [diff] [blame] | 62 | /// PureVirtualFunction - Points to __cxa_pure_virtual. |
| 63 | llvm::Constant *PureVirtualFn; |
| 64 | |
Anders Carlsson | c7ab1a8 | 2009-12-04 02:01:07 +0000 | [diff] [blame] | 65 | /// VtableMethods - A data structure for keeping track of methods in a vtable. |
| 66 | /// Can add methods, override methods and iterate in vtable order. |
| 67 | class VtableMethods { |
| 68 | // MethodToIndexMap - Maps from a global decl to the index it has in the |
| 69 | // Methods vector. |
| 70 | llvm::DenseMap<GlobalDecl, uint64_t> MethodToIndexMap; |
| 71 | |
| 72 | /// Methods - The methods, in vtable order. |
| 73 | typedef llvm::SmallVector<GlobalDecl, 16> MethodsVectorTy; |
| 74 | MethodsVectorTy Methods; |
| 75 | |
| 76 | public: |
| 77 | /// AddMethod - Add a method to the vtable methods. |
| 78 | void AddMethod(GlobalDecl GD) { |
| 79 | assert(!MethodToIndexMap.count(GD) && |
| 80 | "Method has already been added!"); |
| 81 | |
| 82 | MethodToIndexMap[GD] = Methods.size(); |
| 83 | Methods.push_back(GD); |
| 84 | } |
| 85 | |
| 86 | /// OverrideMethod - Replace a method with another. |
| 87 | void OverrideMethod(GlobalDecl OverriddenGD, GlobalDecl GD) { |
| 88 | llvm::DenseMap<GlobalDecl, uint64_t>::iterator i |
| 89 | = MethodToIndexMap.find(OverriddenGD); |
| 90 | assert(i != MethodToIndexMap.end() && "Did not find entry!"); |
| 91 | |
| 92 | // Get the index of the old decl. |
| 93 | uint64_t Index = i->second; |
| 94 | |
| 95 | // Replace the old decl with the new decl. |
| 96 | Methods[Index] = GD; |
| 97 | |
Anders Carlsson | c7ab1a8 | 2009-12-04 02:01:07 +0000 | [diff] [blame] | 98 | // And add the new. |
| 99 | MethodToIndexMap[GD] = Index; |
| 100 | } |
| 101 | |
Anders Carlsson | 77c23e5 | 2009-12-04 15:49:02 +0000 | [diff] [blame] | 102 | /// getIndex - Gives the index of a passed in GlobalDecl. Returns false if |
| 103 | /// the index couldn't be found. |
Benjamin Kramer | cce9fde | 2009-12-04 22:45:27 +0000 | [diff] [blame] | 104 | bool getIndex(GlobalDecl GD, uint64_t &Index) const { |
Anders Carlsson | 77c23e5 | 2009-12-04 15:49:02 +0000 | [diff] [blame] | 105 | llvm::DenseMap<GlobalDecl, uint64_t>::const_iterator i |
| 106 | = MethodToIndexMap.find(GD); |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 107 | |
Anders Carlsson | 77c23e5 | 2009-12-04 15:49:02 +0000 | [diff] [blame] | 108 | if (i == MethodToIndexMap.end()) |
| 109 | return false; |
Anders Carlsson | c0c4993 | 2009-12-04 03:41:37 +0000 | [diff] [blame] | 110 | |
Anders Carlsson | 77c23e5 | 2009-12-04 15:49:02 +0000 | [diff] [blame] | 111 | Index = i->second; |
| 112 | return true; |
Anders Carlsson | c0c4993 | 2009-12-04 03:41:37 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Anders Carlsson | c7ab1a8 | 2009-12-04 02:01:07 +0000 | [diff] [blame] | 115 | MethodsVectorTy::size_type size() const { |
| 116 | return Methods.size(); |
| 117 | } |
| 118 | |
| 119 | void clear() { |
| 120 | MethodToIndexMap.clear(); |
| 121 | Methods.clear(); |
| 122 | } |
| 123 | |
Anders Carlsson | c0c4993 | 2009-12-04 03:41:37 +0000 | [diff] [blame] | 124 | GlobalDecl operator[](uint64_t Index) const { |
Anders Carlsson | c7ab1a8 | 2009-12-04 02:01:07 +0000 | [diff] [blame] | 125 | return Methods[Index]; |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | /// Methods - The vtable methods we're currently building. |
| 130 | VtableMethods Methods; |
| 131 | |
Anders Carlsson | 98fdb24 | 2009-12-04 02:26:15 +0000 | [diff] [blame] | 132 | /// ThisAdjustments - For a given index in the vtable, contains the 'this' |
| 133 | /// pointer adjustment needed for a method. |
| 134 | typedef llvm::DenseMap<uint64_t, ThunkAdjustment> ThisAdjustmentsMapTy; |
| 135 | ThisAdjustmentsMapTy ThisAdjustments; |
Anders Carlsson | 5dd730a | 2009-11-26 19:32:45 +0000 | [diff] [blame] | 136 | |
Anders Carlsson | a875670 | 2009-12-04 02:22:02 +0000 | [diff] [blame] | 137 | /// BaseReturnTypes - Contains the base return types of methods who have been |
| 138 | /// overridden with methods whose return types require adjustment. Used for |
| 139 | /// generating covariant thunk information. |
| 140 | typedef llvm::DenseMap<uint64_t, CanQualType> BaseReturnTypesMapTy; |
| 141 | BaseReturnTypesMapTy BaseReturnTypes; |
Anders Carlsson | 5dd730a | 2009-11-26 19:32:45 +0000 | [diff] [blame] | 142 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 143 | std::vector<Index_t> VCalls; |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 144 | |
| 145 | typedef std::pair<const CXXRecordDecl *, uint64_t> CtorVtable_t; |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 146 | // subAddressPoints - Used to hold the AddressPoints (offsets) into the built |
| 147 | // vtable for use in computing the initializers for the VTT. |
| 148 | llvm::DenseMap<CtorVtable_t, int64_t> &subAddressPoints; |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 149 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 150 | typedef CXXRecordDecl::method_iterator method_iter; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 151 | const bool Extern; |
| 152 | const uint32_t LLVMPointerWidth; |
| 153 | Index_t extra; |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 154 | typedef std::vector<std::pair<const CXXRecordDecl *, int64_t> > Path_t; |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 155 | static llvm::DenseMap<CtorVtable_t, int64_t>& |
| 156 | AllocAddressPoint(CodeGenModule &cgm, const CXXRecordDecl *l, |
| 157 | const CXXRecordDecl *c) { |
| 158 | CodeGenModule::AddrMap_t *&oref = cgm.AddressPoints[l]; |
| 159 | if (oref == 0) |
| 160 | oref = new CodeGenModule::AddrMap_t; |
| 161 | |
| 162 | llvm::DenseMap<CtorVtable_t, int64_t> *&ref = (*oref)[c]; |
| 163 | if (ref == 0) |
| 164 | ref = new llvm::DenseMap<CtorVtable_t, int64_t>; |
| 165 | return *ref; |
| 166 | } |
Anders Carlsson | 6d4ccb7 | 2009-11-26 19:54:33 +0000 | [diff] [blame] | 167 | |
| 168 | /// getPureVirtualFn - Return the __cxa_pure_virtual function. |
| 169 | llvm::Constant* getPureVirtualFn() { |
| 170 | if (!PureVirtualFn) { |
| 171 | const llvm::FunctionType *Ty = |
| 172 | llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), |
| 173 | /*isVarArg=*/false); |
| 174 | PureVirtualFn = wrap(CGM.CreateRuntimeFunction(Ty, "__cxa_pure_virtual")); |
| 175 | } |
| 176 | |
| 177 | return PureVirtualFn; |
| 178 | } |
| 179 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 180 | public: |
Anders Carlsson | ac3f7bd | 2009-12-04 18:36:22 +0000 | [diff] [blame] | 181 | VtableBuilder(const CXXRecordDecl *MostDerivedClass, |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 182 | const CXXRecordDecl *l, uint64_t lo, CodeGenModule &cgm, |
| 183 | bool build) |
| 184 | : BuildVtable(build), MostDerivedClass(MostDerivedClass), LayoutClass(l), |
| 185 | LayoutOffset(lo), BLayout(cgm.getContext().getASTRecordLayout(l)), |
| 186 | rtti(0), VMContext(cgm.getModule().getContext()),CGM(cgm), |
| 187 | PureVirtualFn(0), |
Anders Carlsson | ac3f7bd | 2009-12-04 18:36:22 +0000 | [diff] [blame] | 188 | subAddressPoints(AllocAddressPoint(cgm, l, MostDerivedClass)), |
Mike Stump | 6be2b17 | 2009-11-19 00:49:05 +0000 | [diff] [blame] | 189 | Extern(!l->isInAnonymousNamespace()), |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 190 | LLVMPointerWidth(cgm.getContext().Target.getPointerWidth(0)) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 191 | Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0); |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 192 | if (BuildVtable) |
| 193 | rtti = cgm.GenerateRTTIRef(MostDerivedClass); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 196 | // getVtable - Returns a reference to the vtable components. |
Anders Carlsson | a22fd85 | 2009-12-04 16:24:46 +0000 | [diff] [blame] | 197 | const VtableVectorTy &getVtable() const { |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 198 | return Vtable; |
| 199 | } |
| 200 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 201 | llvm::DenseMap<const CXXRecordDecl *, Index_t> &getVBIndex() |
| 202 | { return VBIndex; } |
| 203 | |
| 204 | llvm::Constant *wrap(Index_t i) { |
| 205 | llvm::Constant *m; |
| 206 | m = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), i); |
| 207 | return llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty); |
| 208 | } |
| 209 | |
| 210 | llvm::Constant *wrap(llvm::Constant *m) { |
| 211 | return llvm::ConstantExpr::getBitCast(m, Ptr8Ty); |
| 212 | } |
| 213 | |
Mike Stump | 7933628 | 2009-12-02 19:50:41 +0000 | [diff] [blame] | 214 | #define D1(x) |
| 215 | //#define D1(X) do { if (getenv("DEBUG")) { X; } } while (0) |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 216 | |
| 217 | void GenerateVBaseOffsets(const CXXRecordDecl *RD, uint64_t Offset, |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 218 | bool updateVBIndex, Index_t current_vbindex) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 219 | for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), |
| 220 | e = RD->bases_end(); i != e; ++i) { |
| 221 | const CXXRecordDecl *Base = |
| 222 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 223 | Index_t next_vbindex = current_vbindex; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 224 | if (i->isVirtual() && !SeenVBase.count(Base)) { |
| 225 | SeenVBase.insert(Base); |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 226 | if (updateVBIndex) { |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 227 | next_vbindex = (ssize_t)(-(VCalls.size()*LLVMPointerWidth/8) |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 228 | - 3*LLVMPointerWidth/8); |
| 229 | VBIndex[Base] = next_vbindex; |
| 230 | } |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 231 | int64_t BaseOffset = -(Offset/8) + BLayout.getVBaseClassOffset(Base)/8; |
| 232 | VCalls.push_back((0?700:0) + BaseOffset); |
| 233 | D1(printf(" vbase for %s at %d delta %d most derived %s\n", |
| 234 | Base->getNameAsCString(), |
| 235 | (int)-VCalls.size()-3, (int)BaseOffset, |
| 236 | Class->getNameAsCString())); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 237 | } |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 238 | // We also record offsets for non-virtual bases to closest enclosing |
| 239 | // virtual base. We do this so that we don't have to search |
| 240 | // for the nearst virtual base class when generating thunks. |
| 241 | if (updateVBIndex && VBIndex.count(Base) == 0) |
| 242 | VBIndex[Base] = next_vbindex; |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 243 | GenerateVBaseOffsets(Base, Offset, updateVBIndex, next_vbindex); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | void StartNewTable() { |
| 248 | SeenVBase.clear(); |
| 249 | } |
| 250 | |
Mike Stump | 3425b97 | 2009-10-15 09:30:16 +0000 | [diff] [blame] | 251 | Index_t getNVOffset_1(const CXXRecordDecl *D, const CXXRecordDecl *B, |
| 252 | Index_t Offset = 0) { |
| 253 | |
| 254 | if (B == D) |
| 255 | return Offset; |
| 256 | |
| 257 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(D); |
| 258 | for (CXXRecordDecl::base_class_const_iterator i = D->bases_begin(), |
| 259 | e = D->bases_end(); i != e; ++i) { |
| 260 | const CXXRecordDecl *Base = |
| 261 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 262 | int64_t BaseOffset = 0; |
| 263 | if (!i->isVirtual()) |
| 264 | BaseOffset = Offset + Layout.getBaseClassOffset(Base); |
| 265 | int64_t o = getNVOffset_1(Base, B, BaseOffset); |
| 266 | if (o >= 0) |
| 267 | return o; |
| 268 | } |
| 269 | |
| 270 | return -1; |
| 271 | } |
| 272 | |
| 273 | /// getNVOffset - Returns the non-virtual offset for the given (B) base of the |
| 274 | /// derived class D. |
| 275 | Index_t getNVOffset(QualType qB, QualType qD) { |
Mike Stump | 9c21289 | 2009-11-03 19:03:17 +0000 | [diff] [blame] | 276 | qD = qD->getPointeeType(); |
| 277 | qB = qB->getPointeeType(); |
Mike Stump | 3425b97 | 2009-10-15 09:30:16 +0000 | [diff] [blame] | 278 | CXXRecordDecl *D = cast<CXXRecordDecl>(qD->getAs<RecordType>()->getDecl()); |
| 279 | CXXRecordDecl *B = cast<CXXRecordDecl>(qB->getAs<RecordType>()->getDecl()); |
| 280 | int64_t o = getNVOffset_1(D, B); |
| 281 | if (o >= 0) |
| 282 | return o; |
| 283 | |
| 284 | assert(false && "FIXME: non-virtual base not found"); |
| 285 | return 0; |
| 286 | } |
| 287 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 288 | /// getVbaseOffset - Returns the index into the vtable for the virtual base |
| 289 | /// offset for the given (B) virtual base of the derived class D. |
| 290 | Index_t getVbaseOffset(QualType qB, QualType qD) { |
Mike Stump | 9c21289 | 2009-11-03 19:03:17 +0000 | [diff] [blame] | 291 | qD = qD->getPointeeType(); |
| 292 | qB = qB->getPointeeType(); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 293 | CXXRecordDecl *D = cast<CXXRecordDecl>(qD->getAs<RecordType>()->getDecl()); |
| 294 | CXXRecordDecl *B = cast<CXXRecordDecl>(qB->getAs<RecordType>()->getDecl()); |
Anders Carlsson | ac3f7bd | 2009-12-04 18:36:22 +0000 | [diff] [blame] | 295 | if (D != MostDerivedClass) |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 296 | return CGM.getVtableInfo().getVirtualBaseOffsetIndex(D, B); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 297 | llvm::DenseMap<const CXXRecordDecl *, Index_t>::iterator i; |
| 298 | i = VBIndex.find(B); |
| 299 | if (i != VBIndex.end()) |
| 300 | return i->second; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 301 | |
Mike Stump | ab28c13 | 2009-10-13 22:54:56 +0000 | [diff] [blame] | 302 | assert(false && "FIXME: Base not found"); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
Eli Friedman | 367d122 | 2009-12-04 08:40:51 +0000 | [diff] [blame] | 306 | bool OverrideMethod(GlobalDecl GD, bool MorallyVirtual, |
| 307 | Index_t OverrideOffset, Index_t Offset, |
| 308 | int64_t CurrentVBaseOffset); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 309 | |
Anders Carlsson | adfa267 | 2009-12-04 02:39:04 +0000 | [diff] [blame] | 310 | /// AppendMethods - Append the current methods to the vtable. |
Anders Carlsson | bf54027 | 2009-12-04 02:56:03 +0000 | [diff] [blame] | 311 | void AppendMethodsToVtable(); |
Anders Carlsson | adfa267 | 2009-12-04 02:39:04 +0000 | [diff] [blame] | 312 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 313 | llvm::Constant *WrapAddrOf(GlobalDecl GD) { |
| 314 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl()); |
| 315 | |
Anders Carlsson | ecf282b | 2009-11-24 05:08:52 +0000 | [diff] [blame] | 316 | const llvm::Type *Ty = CGM.getTypes().GetFunctionTypeForVtable(MD); |
Mike Stump | 1ae3178 | 2009-10-27 23:36:26 +0000 | [diff] [blame] | 317 | |
Mike Stump | c085a98 | 2009-12-03 16:55:20 +0000 | [diff] [blame] | 318 | return wrap(CGM.GetAddrOfFunction(GD, Ty)); |
Mike Stump | 1ae3178 | 2009-10-27 23:36:26 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 321 | void OverrideMethods(Path_t *Path, bool MorallyVirtual, int64_t Offset, |
| 322 | int64_t CurrentVBaseOffset) { |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 323 | for (Path_t::reverse_iterator i = Path->rbegin(), |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 324 | e = Path->rend(); i != e; ++i) { |
| 325 | const CXXRecordDecl *RD = i->first; |
Mike Stump | 3425b97 | 2009-10-15 09:30:16 +0000 | [diff] [blame] | 326 | int64_t OverrideOffset = i->second; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 327 | for (method_iter mi = RD->method_begin(), me = RD->method_end(); mi != me; |
| 328 | ++mi) { |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 329 | const CXXMethodDecl *MD = *mi; |
| 330 | |
| 331 | if (!MD->isVirtual()) |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 332 | continue; |
| 333 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 334 | if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) { |
| 335 | // Override both the complete and the deleting destructor. |
| 336 | GlobalDecl CompDtor(DD, Dtor_Complete); |
Eli Friedman | 367d122 | 2009-12-04 08:40:51 +0000 | [diff] [blame] | 337 | OverrideMethod(CompDtor, MorallyVirtual, OverrideOffset, Offset, |
| 338 | CurrentVBaseOffset); |
| 339 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 340 | GlobalDecl DeletingDtor(DD, Dtor_Deleting); |
Eli Friedman | 367d122 | 2009-12-04 08:40:51 +0000 | [diff] [blame] | 341 | OverrideMethod(DeletingDtor, MorallyVirtual, OverrideOffset, Offset, |
| 342 | CurrentVBaseOffset); |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 343 | } else { |
Eli Friedman | 367d122 | 2009-12-04 08:40:51 +0000 | [diff] [blame] | 344 | OverrideMethod(MD, MorallyVirtual, OverrideOffset, Offset, |
| 345 | CurrentVBaseOffset); |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 346 | } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 351 | void AddMethod(const GlobalDecl GD, bool MorallyVirtual, Index_t Offset, |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 352 | int64_t CurrentVBaseOffset) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 353 | // If we can find a previously allocated slot for this, reuse it. |
Eli Friedman | 367d122 | 2009-12-04 08:40:51 +0000 | [diff] [blame] | 354 | if (OverrideMethod(GD, MorallyVirtual, Offset, Offset, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 355 | CurrentVBaseOffset)) |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 356 | return; |
| 357 | |
Anders Carlsson | a7f1911 | 2009-12-04 02:08:24 +0000 | [diff] [blame] | 358 | // We didn't find an entry in the vtable that we could use, add a new |
| 359 | // entry. |
| 360 | Methods.AddMethod(GD); |
| 361 | |
Mike Stump | e99cc45 | 2009-11-13 23:45:53 +0000 | [diff] [blame] | 362 | D1(printf(" vfn for %s at %d\n", MD->getNameAsString().c_str(), |
| 363 | (int)Index[GD])); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 364 | if (MorallyVirtual) { |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 365 | VCallOffset[GD] = Offset/8; |
| 366 | Index_t &idx = VCall[GD]; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 367 | // Allocate the first one, after that, we reuse the previous one. |
| 368 | if (idx == 0) { |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 369 | NonVirtualOffset[GD] = CurrentVBaseOffset/8 - Offset/8; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 370 | idx = VCalls.size()+1; |
| 371 | VCalls.push_back(0); |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 372 | D1(printf(" vcall for %s at %d with delta %d\n", |
Mike Stump | e99cc45 | 2009-11-13 23:45:53 +0000 | [diff] [blame] | 373 | MD->getNameAsString().c_str(), (int)-VCalls.size()-3, 0)); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | void AddMethods(const CXXRecordDecl *RD, bool MorallyVirtual, |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 379 | Index_t Offset, int64_t CurrentVBaseOffset) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 380 | for (method_iter mi = RD->method_begin(), me = RD->method_end(); mi != me; |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 381 | ++mi) { |
| 382 | const CXXMethodDecl *MD = *mi; |
| 383 | if (!MD->isVirtual()) |
| 384 | continue; |
| 385 | |
| 386 | if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) { |
| 387 | // For destructors, add both the complete and the deleting destructor |
| 388 | // to the vtable. |
| 389 | AddMethod(GlobalDecl(DD, Dtor_Complete), MorallyVirtual, Offset, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 390 | CurrentVBaseOffset); |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 391 | AddMethod(GlobalDecl(DD, Dtor_Deleting), MorallyVirtual, Offset, |
| 392 | CurrentVBaseOffset); |
| 393 | } else |
| 394 | AddMethod(MD, MorallyVirtual, Offset, CurrentVBaseOffset); |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 395 | } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | void NonVirtualBases(const CXXRecordDecl *RD, const ASTRecordLayout &Layout, |
| 399 | const CXXRecordDecl *PrimaryBase, |
| 400 | bool PrimaryBaseWasVirtual, bool MorallyVirtual, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 401 | int64_t Offset, int64_t CurrentVBaseOffset, |
| 402 | Path_t *Path) { |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 403 | Path->push_back(std::make_pair(RD, Offset)); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 404 | for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), |
| 405 | e = RD->bases_end(); i != e; ++i) { |
| 406 | if (i->isVirtual()) |
| 407 | continue; |
| 408 | const CXXRecordDecl *Base = |
| 409 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 410 | if (Base != PrimaryBase || PrimaryBaseWasVirtual) { |
| 411 | uint64_t o = Offset + Layout.getBaseClassOffset(Base); |
| 412 | StartNewTable(); |
Mike Stump | 4cde626 | 2009-11-13 02:13:54 +0000 | [diff] [blame] | 413 | GenerateVtableForBase(Base, o, MorallyVirtual, false, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 414 | CurrentVBaseOffset, Path); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 415 | } |
| 416 | } |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 417 | Path->pop_back(); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 420 | // #define D(X) do { X; } while (0) |
| 421 | #define D(X) |
| 422 | |
| 423 | void insertVCalls(int InsertionPoint) { |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 424 | D1(printf("============= combining vbase/vcall\n")); |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 425 | D(VCalls.insert(VCalls.begin(), 673)); |
| 426 | D(VCalls.push_back(672)); |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 427 | |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 428 | Vtable.insert(Vtable.begin() + InsertionPoint, VCalls.size(), 0); |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 429 | if (BuildVtable) { |
| 430 | // The vcalls come first... |
| 431 | for (std::vector<Index_t>::reverse_iterator i = VCalls.rbegin(), |
| 432 | e = VCalls.rend(); |
| 433 | i != e; ++i) |
| 434 | Vtable[InsertionPoint++] = wrap((0?600:0) + *i); |
| 435 | } |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 436 | VCalls.clear(); |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 437 | VCall.clear(); |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Mike Stump | 65d0e28 | 2009-11-13 23:13:20 +0000 | [diff] [blame] | 440 | void AddAddressPoints(const CXXRecordDecl *RD, uint64_t Offset, |
| 441 | Index_t AddressPoint) { |
| 442 | D1(printf("XXX address point for %s in %s layout %s at offset %d is %d\n", |
| 443 | RD->getNameAsCString(), Class->getNameAsCString(), |
| 444 | LayoutClass->getNameAsCString(), (int)Offset, (int)AddressPoint)); |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 445 | subAddressPoints[std::make_pair(RD, Offset)] = AddressPoint; |
Mike Stump | 65d0e28 | 2009-11-13 23:13:20 +0000 | [diff] [blame] | 446 | |
| 447 | // Now also add the address point for all our primary bases. |
| 448 | while (1) { |
| 449 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 450 | RD = Layout.getPrimaryBase(); |
| 451 | const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual(); |
| 452 | // FIXME: Double check this. |
| 453 | if (RD == 0) |
| 454 | break; |
| 455 | if (PrimaryBaseWasVirtual && |
| 456 | BLayout.getVBaseClassOffset(RD) != Offset) |
| 457 | break; |
| 458 | D1(printf("XXX address point for %s in %s layout %s at offset %d is %d\n", |
| 459 | RD->getNameAsCString(), Class->getNameAsCString(), |
| 460 | LayoutClass->getNameAsCString(), (int)Offset, (int)AddressPoint)); |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 461 | subAddressPoints[std::make_pair(RD, Offset)] = AddressPoint; |
Mike Stump | 65d0e28 | 2009-11-13 23:13:20 +0000 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
| 465 | |
Eli Friedman | d6a3e67 | 2009-12-04 03:54:56 +0000 | [diff] [blame] | 466 | Index_t FinishGenerateVtable(const CXXRecordDecl *RD, |
| 467 | const ASTRecordLayout &Layout, |
| 468 | const CXXRecordDecl *PrimaryBase, |
| 469 | bool PrimaryBaseWasVirtual, |
| 470 | bool MorallyVirtual, int64_t Offset, |
| 471 | bool ForVirtualBase, int64_t CurrentVBaseOffset, |
| 472 | Path_t *Path) { |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 473 | bool alloc = false; |
| 474 | if (Path == 0) { |
| 475 | alloc = true; |
| 476 | Path = new Path_t; |
| 477 | } |
| 478 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 479 | StartNewTable(); |
| 480 | extra = 0; |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 481 | bool DeferVCalls = MorallyVirtual || ForVirtualBase; |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 482 | int VCallInsertionPoint = Vtable.size(); |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 483 | if (!DeferVCalls) { |
| 484 | insertVCalls(VCallInsertionPoint); |
Mike Stump | 3425b97 | 2009-10-15 09:30:16 +0000 | [diff] [blame] | 485 | } else |
| 486 | // FIXME: just for extra, or for all uses of VCalls.size post this? |
| 487 | extra = -VCalls.size(); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 488 | |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 489 | // Add the offset to top. |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 490 | Vtable.push_back(BuildVtable ? wrap(-((Offset-LayoutOffset)/8)) : 0); |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 491 | |
| 492 | // Add the RTTI information. |
| 493 | Vtable.push_back(rtti); |
| 494 | |
| 495 | Index_t AddressPoint = Vtable.size(); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 496 | |
Anders Carlsson | bf54027 | 2009-12-04 02:56:03 +0000 | [diff] [blame] | 497 | AppendMethodsToVtable(); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 498 | |
| 499 | // and then the non-virtual bases. |
| 500 | NonVirtualBases(RD, Layout, PrimaryBase, PrimaryBaseWasVirtual, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 501 | MorallyVirtual, Offset, CurrentVBaseOffset, Path); |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 502 | |
| 503 | if (ForVirtualBase) { |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 504 | // FIXME: We're adding to VCalls in callers, we need to do the overrides |
| 505 | // in the inner part, so that we know the complete set of vcalls during |
| 506 | // the build and don't have to insert into methods. Saving out the |
| 507 | // AddressPoint here, would need to be fixed, if we didn't do that. Also |
| 508 | // retroactively adding vcalls for overrides later wind up in the wrong |
| 509 | // place, the vcall slot has to be alloted during the walk of the base |
| 510 | // when the function is first introduces. |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 511 | AddressPoint += VCalls.size(); |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 512 | insertVCalls(VCallInsertionPoint); |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Mike Stump | 65d0e28 | 2009-11-13 23:13:20 +0000 | [diff] [blame] | 515 | AddAddressPoints(RD, Offset, AddressPoint); |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 516 | |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 517 | if (alloc) { |
| 518 | delete Path; |
| 519 | } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 520 | return AddressPoint; |
| 521 | } |
| 522 | |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 523 | void Primaries(const CXXRecordDecl *RD, bool MorallyVirtual, int64_t Offset, |
| 524 | bool updateVBIndex, Index_t current_vbindex, |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 525 | int64_t CurrentVBaseOffset) { |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 526 | if (!RD->isDynamicClass()) |
| 527 | return; |
| 528 | |
| 529 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 530 | const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); |
| 531 | const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual(); |
| 532 | |
| 533 | // vtables are composed from the chain of primaries. |
Eli Friedman | dfe33bb | 2009-12-04 08:52:11 +0000 | [diff] [blame] | 534 | if (PrimaryBase && !PrimaryBaseWasVirtual) { |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 535 | D1(printf(" doing primaries for %s most derived %s\n", |
| 536 | RD->getNameAsCString(), Class->getNameAsCString())); |
Eli Friedman | dfe33bb | 2009-12-04 08:52:11 +0000 | [diff] [blame] | 537 | Primaries(PrimaryBase, PrimaryBaseWasVirtual|MorallyVirtual, Offset, |
| 538 | updateVBIndex, current_vbindex, CurrentVBaseOffset); |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | D1(printf(" doing vcall entries for %s most derived %s\n", |
| 542 | RD->getNameAsCString(), Class->getNameAsCString())); |
| 543 | |
| 544 | // And add the virtuals for the class to the primary vtable. |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 545 | AddMethods(RD, MorallyVirtual, Offset, CurrentVBaseOffset); |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void VBPrimaries(const CXXRecordDecl *RD, bool MorallyVirtual, int64_t Offset, |
| 549 | bool updateVBIndex, Index_t current_vbindex, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 550 | bool RDisVirtualBase, int64_t CurrentVBaseOffset, |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 551 | bool bottom) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 552 | if (!RD->isDynamicClass()) |
| 553 | return; |
| 554 | |
| 555 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 556 | const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); |
| 557 | const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual(); |
| 558 | |
| 559 | // vtables are composed from the chain of primaries. |
| 560 | if (PrimaryBase) { |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 561 | int BaseCurrentVBaseOffset = CurrentVBaseOffset; |
| 562 | if (PrimaryBaseWasVirtual) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 563 | IndirectPrimary.insert(PrimaryBase); |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 564 | BaseCurrentVBaseOffset = BLayout.getVBaseClassOffset(PrimaryBase); |
| 565 | } |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 566 | |
| 567 | D1(printf(" doing primaries for %s most derived %s\n", |
| 568 | RD->getNameAsCString(), Class->getNameAsCString())); |
| 569 | |
| 570 | VBPrimaries(PrimaryBase, PrimaryBaseWasVirtual|MorallyVirtual, Offset, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 571 | updateVBIndex, current_vbindex, PrimaryBaseWasVirtual, |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 572 | BaseCurrentVBaseOffset, false); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 575 | D1(printf(" doing vbase entries for %s most derived %s\n", |
| 576 | RD->getNameAsCString(), Class->getNameAsCString())); |
| 577 | GenerateVBaseOffsets(RD, Offset, updateVBIndex, current_vbindex); |
| 578 | |
| 579 | if (RDisVirtualBase || bottom) { |
| 580 | Primaries(RD, MorallyVirtual, Offset, updateVBIndex, current_vbindex, |
Eli Friedman | 76ed1f7 | 2009-11-30 01:19:33 +0000 | [diff] [blame] | 581 | CurrentVBaseOffset); |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 582 | } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Mike Stump | 4cde626 | 2009-11-13 02:13:54 +0000 | [diff] [blame] | 585 | int64_t GenerateVtableForBase(const CXXRecordDecl *RD, int64_t Offset = 0, |
| 586 | bool MorallyVirtual = false, |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 587 | bool ForVirtualBase = false, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 588 | int CurrentVBaseOffset = 0, |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 589 | Path_t *Path = 0) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 590 | if (!RD->isDynamicClass()) |
| 591 | return 0; |
| 592 | |
Mike Stump | 92774d1 | 2009-11-13 02:35:38 +0000 | [diff] [blame] | 593 | // Construction vtable don't need parts that have no virtual bases and |
| 594 | // aren't morally virtual. |
Anders Carlsson | ac3f7bd | 2009-12-04 18:36:22 +0000 | [diff] [blame] | 595 | if ((LayoutClass != MostDerivedClass) && |
| 596 | RD->getNumVBases() == 0 && !MorallyVirtual) |
Mike Stump | 92774d1 | 2009-11-13 02:35:38 +0000 | [diff] [blame] | 597 | return 0; |
| 598 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 599 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 600 | const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); |
| 601 | const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual(); |
| 602 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 603 | extra = 0; |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 604 | D1(printf("building entries for base %s most derived %s\n", |
| 605 | RD->getNameAsCString(), Class->getNameAsCString())); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 606 | |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 607 | if (ForVirtualBase) |
| 608 | extra = VCalls.size(); |
| 609 | |
| 610 | VBPrimaries(RD, MorallyVirtual, Offset, !ForVirtualBase, 0, ForVirtualBase, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 611 | CurrentVBaseOffset, true); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 612 | |
| 613 | if (Path) |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 614 | OverrideMethods(Path, MorallyVirtual, Offset, CurrentVBaseOffset); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 615 | |
Eli Friedman | d6a3e67 | 2009-12-04 03:54:56 +0000 | [diff] [blame] | 616 | return FinishGenerateVtable(RD, Layout, PrimaryBase, PrimaryBaseWasVirtual, |
| 617 | MorallyVirtual, Offset, ForVirtualBase, |
| 618 | CurrentVBaseOffset, Path); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | void GenerateVtableForVBases(const CXXRecordDecl *RD, |
| 622 | int64_t Offset = 0, |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 623 | Path_t *Path = 0) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 624 | bool alloc = false; |
| 625 | if (Path == 0) { |
| 626 | alloc = true; |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 627 | Path = new Path_t; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 628 | } |
| 629 | // FIXME: We also need to override using all paths to a virtual base, |
| 630 | // right now, we just process the first path |
| 631 | Path->push_back(std::make_pair(RD, Offset)); |
| 632 | for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), |
| 633 | e = RD->bases_end(); i != e; ++i) { |
| 634 | const CXXRecordDecl *Base = |
| 635 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 636 | if (i->isVirtual() && !IndirectPrimary.count(Base)) { |
| 637 | // Mark it so we don't output it twice. |
| 638 | IndirectPrimary.insert(Base); |
| 639 | StartNewTable(); |
Mike Stump | 0ca4279 | 2009-10-14 18:14:51 +0000 | [diff] [blame] | 640 | VCall.clear(); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 641 | int64_t BaseOffset = BLayout.getVBaseClassOffset(Base); |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 642 | int64_t CurrentVBaseOffset = BaseOffset; |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 643 | D1(printf("vtable %s virtual base %s\n", |
| 644 | Class->getNameAsCString(), Base->getNameAsCString())); |
Mike Stump | 4cde626 | 2009-11-13 02:13:54 +0000 | [diff] [blame] | 645 | GenerateVtableForBase(Base, BaseOffset, true, true, CurrentVBaseOffset, |
Mike Stump | 9e7e3c6 | 2009-11-06 23:27:42 +0000 | [diff] [blame] | 646 | Path); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 647 | } |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 648 | int64_t BaseOffset; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 649 | if (i->isVirtual()) |
| 650 | BaseOffset = BLayout.getVBaseClassOffset(Base); |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 651 | else { |
| 652 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 653 | BaseOffset = Offset + Layout.getBaseClassOffset(Base); |
| 654 | } |
| 655 | |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 656 | if (Base->getNumVBases()) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 657 | GenerateVtableForVBases(Base, BaseOffset, Path); |
Mike Stump | 11dea94 | 2009-10-15 02:04:03 +0000 | [diff] [blame] | 658 | } |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 659 | } |
| 660 | Path->pop_back(); |
| 661 | if (alloc) |
| 662 | delete Path; |
| 663 | } |
| 664 | }; |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 665 | } // end anonymous namespace |
| 666 | |
Anders Carlsson | 891bb4b | 2009-12-03 02:32:59 +0000 | [diff] [blame] | 667 | /// TypeConversionRequiresAdjustment - Returns whether conversion from a |
| 668 | /// derived type to a base type requires adjustment. |
| 669 | static bool |
| 670 | TypeConversionRequiresAdjustment(ASTContext &Ctx, |
| 671 | const CXXRecordDecl *DerivedDecl, |
| 672 | const CXXRecordDecl *BaseDecl) { |
| 673 | CXXBasePaths Paths(/*FindAmbiguities=*/false, |
| 674 | /*RecordPaths=*/true, /*DetectVirtual=*/true); |
| 675 | if (!const_cast<CXXRecordDecl *>(DerivedDecl)-> |
| 676 | isDerivedFrom(const_cast<CXXRecordDecl *>(BaseDecl), Paths)) { |
| 677 | assert(false && "Class must be derived from the passed in base class!"); |
| 678 | return false; |
| 679 | } |
| 680 | |
| 681 | // If we found a virtual base we always want to require adjustment. |
| 682 | if (Paths.getDetectedVirtual()) |
| 683 | return true; |
| 684 | |
| 685 | const CXXBasePath &Path = Paths.front(); |
| 686 | |
| 687 | for (size_t Start = 0, End = Path.size(); Start != End; ++Start) { |
| 688 | const CXXBasePathElement &Element = Path[Start]; |
| 689 | |
| 690 | // Check the base class offset. |
| 691 | const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Element.Class); |
| 692 | |
| 693 | const RecordType *BaseType = Element.Base->getType()->getAs<RecordType>(); |
| 694 | const CXXRecordDecl *Base = cast<CXXRecordDecl>(BaseType->getDecl()); |
| 695 | |
| 696 | if (Layout.getBaseClassOffset(Base) != 0) { |
| 697 | // This requires an adjustment. |
| 698 | return true; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return false; |
| 703 | } |
| 704 | |
| 705 | static bool |
| 706 | TypeConversionRequiresAdjustment(ASTContext &Ctx, |
| 707 | QualType DerivedType, QualType BaseType) { |
| 708 | // Canonicalize the types. |
| 709 | QualType CanDerivedType = Ctx.getCanonicalType(DerivedType); |
| 710 | QualType CanBaseType = Ctx.getCanonicalType(BaseType); |
| 711 | |
| 712 | assert(CanDerivedType->getTypeClass() == CanBaseType->getTypeClass() && |
| 713 | "Types must have same type class!"); |
| 714 | |
| 715 | if (CanDerivedType == CanBaseType) { |
| 716 | // No adjustment needed. |
| 717 | return false; |
| 718 | } |
| 719 | |
| 720 | if (const ReferenceType *RT = dyn_cast<ReferenceType>(CanDerivedType)) { |
| 721 | CanDerivedType = RT->getPointeeType(); |
| 722 | CanBaseType = cast<ReferenceType>(CanBaseType)->getPointeeType(); |
| 723 | } else if (const PointerType *PT = dyn_cast<PointerType>(CanDerivedType)) { |
| 724 | CanDerivedType = PT->getPointeeType(); |
| 725 | CanBaseType = cast<PointerType>(CanBaseType)->getPointeeType(); |
| 726 | } else { |
| 727 | assert(false && "Unexpected return type!"); |
| 728 | } |
| 729 | |
| 730 | if (CanDerivedType == CanBaseType) { |
| 731 | // No adjustment needed. |
| 732 | return false; |
| 733 | } |
| 734 | |
| 735 | const CXXRecordDecl *DerivedDecl = |
Anders Carlsson | 1750b4f | 2009-12-03 03:28:24 +0000 | [diff] [blame] | 736 | cast<CXXRecordDecl>(cast<RecordType>(CanDerivedType)->getDecl()); |
Anders Carlsson | 891bb4b | 2009-12-03 02:32:59 +0000 | [diff] [blame] | 737 | |
| 738 | const CXXRecordDecl *BaseDecl = |
| 739 | cast<CXXRecordDecl>(cast<RecordType>(CanBaseType)->getDecl()); |
| 740 | |
| 741 | return TypeConversionRequiresAdjustment(Ctx, DerivedDecl, BaseDecl); |
| 742 | } |
| 743 | |
Eli Friedman | 367d122 | 2009-12-04 08:40:51 +0000 | [diff] [blame] | 744 | bool VtableBuilder::OverrideMethod(GlobalDecl GD, bool MorallyVirtual, |
| 745 | Index_t OverrideOffset, Index_t Offset, |
| 746 | int64_t CurrentVBaseOffset) { |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 747 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl()); |
| 748 | |
| 749 | const bool isPure = MD->isPure(); |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 750 | |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 751 | // FIXME: Should OverrideOffset's be Offset? |
| 752 | |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 753 | for (CXXMethodDecl::method_iterator mi = MD->begin_overridden_methods(), |
| 754 | e = MD->end_overridden_methods(); mi != e; ++mi) { |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 755 | GlobalDecl OGD; |
| 756 | |
Anders Carlsson | 3aaf486 | 2009-12-04 05:51:56 +0000 | [diff] [blame] | 757 | const CXXMethodDecl *OMD = *mi; |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 758 | if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(OMD)) |
| 759 | OGD = GlobalDecl(DD, GD.getDtorType()); |
| 760 | else |
| 761 | OGD = OMD; |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 762 | |
| 763 | // FIXME: Explain why this is necessary! |
Anders Carlsson | 77c23e5 | 2009-12-04 15:49:02 +0000 | [diff] [blame] | 764 | uint64_t Index; |
| 765 | if (!Methods.getIndex(OGD, Index)) |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 766 | continue; |
| 767 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 768 | QualType ReturnType = |
| 769 | MD->getType()->getAs<FunctionType>()->getResultType(); |
| 770 | QualType OverriddenReturnType = |
| 771 | OMD->getType()->getAs<FunctionType>()->getResultType(); |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 772 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 773 | // Check if we need a return type adjustment. |
| 774 | if (TypeConversionRequiresAdjustment(CGM.getContext(), ReturnType, |
| 775 | OverriddenReturnType)) { |
| 776 | CanQualType &BaseReturnType = BaseReturnTypes[Index]; |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 777 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 778 | // Get the canonical return type. |
| 779 | CanQualType CanReturnType = |
| 780 | CGM.getContext().getCanonicalType(ReturnType); |
Anders Carlsson | c0c4993 | 2009-12-04 03:41:37 +0000 | [diff] [blame] | 781 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 782 | // Insert the base return type. |
| 783 | if (BaseReturnType.isNull()) |
| 784 | BaseReturnType = |
| 785 | CGM.getContext().getCanonicalType(OverriddenReturnType); |
| 786 | } |
Anders Carlsson | dd454be | 2009-12-04 03:52:52 +0000 | [diff] [blame] | 787 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 788 | Methods.OverrideMethod(OGD, GD); |
| 789 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 790 | ThisAdjustments.erase(Index); |
| 791 | if (MorallyVirtual || VCall.count(OGD)) { |
| 792 | Index_t &idx = VCall[OGD]; |
| 793 | if (idx == 0) { |
| 794 | NonVirtualOffset[GD] = -OverrideOffset/8 + CurrentVBaseOffset/8; |
| 795 | VCallOffset[GD] = OverrideOffset/8; |
| 796 | idx = VCalls.size()+1; |
| 797 | VCalls.push_back(0); |
| 798 | D1(printf(" vcall for %s at %d with delta %d most derived %s\n", |
| 799 | MD->getNameAsString().c_str(), (int)-idx-3, |
| 800 | (int)VCalls[idx-1], Class->getNameAsCString())); |
| 801 | } else { |
| 802 | NonVirtualOffset[GD] = NonVirtualOffset[OGD]; |
| 803 | VCallOffset[GD] = VCallOffset[OGD]; |
| 804 | VCalls[idx-1] = -VCallOffset[OGD] + OverrideOffset/8; |
| 805 | D1(printf(" vcall patch for %s at %d with delta %d most derived %s\n", |
| 806 | MD->getNameAsString().c_str(), (int)-idx-3, |
| 807 | (int)VCalls[idx-1], Class->getNameAsCString())); |
| 808 | } |
| 809 | VCall[GD] = idx; |
| 810 | int64_t NonVirtualAdjustment = NonVirtualOffset[GD]; |
| 811 | int64_t VirtualAdjustment = |
| 812 | -((idx + extra + 2) * LLVMPointerWidth / 8); |
Anders Carlsson | 891bb4b | 2009-12-03 02:32:59 +0000 | [diff] [blame] | 813 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 814 | // Optimize out virtual adjustments of 0. |
| 815 | if (VCalls[idx-1] == 0) |
| 816 | VirtualAdjustment = 0; |
Anders Carlsson | 891bb4b | 2009-12-03 02:32:59 +0000 | [diff] [blame] | 817 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 818 | ThunkAdjustment ThisAdjustment(NonVirtualAdjustment, |
| 819 | VirtualAdjustment); |
Anders Carlsson | bc0e339 | 2009-12-03 02:22:59 +0000 | [diff] [blame] | 820 | |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 821 | if (!isPure && !ThisAdjustment.isEmpty()) |
| 822 | ThisAdjustments[Index] = ThisAdjustment; |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 823 | return true; |
| 824 | } |
Eli Friedman | 4714583 | 2009-12-04 08:34:14 +0000 | [diff] [blame] | 825 | |
| 826 | // FIXME: finish off |
| 827 | int64_t NonVirtualAdjustment = VCallOffset[OGD] - OverrideOffset/8; |
| 828 | |
| 829 | if (NonVirtualAdjustment) { |
| 830 | ThunkAdjustment ThisAdjustment(NonVirtualAdjustment, 0); |
| 831 | |
| 832 | if (!isPure) |
| 833 | ThisAdjustments[Index] = ThisAdjustment; |
| 834 | } |
| 835 | return true; |
Anders Carlsson | 27682a3 | 2009-12-03 01:54:02 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | return false; |
Anders Carlsson | 27f69d0 | 2009-11-27 22:21:51 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Anders Carlsson | bf54027 | 2009-12-04 02:56:03 +0000 | [diff] [blame] | 841 | void VtableBuilder::AppendMethodsToVtable() { |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 842 | if (!BuildVtable) { |
| 843 | Vtable.insert(Vtable.end(), Methods.size(), (llvm::Constant*)0); |
| 844 | ThisAdjustments.clear(); |
| 845 | BaseReturnTypes.clear(); |
| 846 | Methods.clear(); |
| 847 | return; |
| 848 | } |
| 849 | |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 850 | // Reserve room in the vtable for our new methods. |
| 851 | Vtable.reserve(Vtable.size() + Methods.size()); |
Anders Carlsson | 29202d5 | 2009-12-04 03:07:26 +0000 | [diff] [blame] | 852 | |
Anders Carlsson | b73ba39 | 2009-12-04 02:43:50 +0000 | [diff] [blame] | 853 | for (unsigned i = 0, e = Methods.size(); i != e; ++i) { |
| 854 | GlobalDecl GD = Methods[i]; |
Anders Carlsson | ea35722 | 2009-12-04 02:52:22 +0000 | [diff] [blame] | 855 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl()); |
| 856 | |
| 857 | // Get the 'this' pointer adjustment. |
Anders Carlsson | b73ba39 | 2009-12-04 02:43:50 +0000 | [diff] [blame] | 858 | ThunkAdjustment ThisAdjustment = ThisAdjustments.lookup(i); |
Anders Carlsson | ea35722 | 2009-12-04 02:52:22 +0000 | [diff] [blame] | 859 | |
| 860 | // Construct the return type adjustment. |
| 861 | ThunkAdjustment ReturnAdjustment; |
| 862 | |
| 863 | QualType BaseReturnType = BaseReturnTypes.lookup(i); |
| 864 | if (!BaseReturnType.isNull() && !MD->isPure()) { |
| 865 | QualType DerivedType = |
| 866 | MD->getType()->getAs<FunctionType>()->getResultType(); |
| 867 | |
| 868 | int64_t NonVirtualAdjustment = |
| 869 | getNVOffset(BaseReturnType, DerivedType) / 8; |
| 870 | |
| 871 | int64_t VirtualAdjustment = |
| 872 | getVbaseOffset(BaseReturnType, DerivedType); |
| 873 | |
| 874 | ReturnAdjustment = ThunkAdjustment(NonVirtualAdjustment, |
| 875 | VirtualAdjustment); |
| 876 | } |
| 877 | |
Anders Carlsson | 2fce216 | 2009-12-04 03:06:03 +0000 | [diff] [blame] | 878 | llvm::Constant *Method = 0; |
Anders Carlsson | ea35722 | 2009-12-04 02:52:22 +0000 | [diff] [blame] | 879 | if (!ReturnAdjustment.isEmpty()) { |
| 880 | // Build a covariant thunk. |
| 881 | CovariantThunkAdjustment Adjustment(ThisAdjustment, ReturnAdjustment); |
Anders Carlsson | 2fce216 | 2009-12-04 03:06:03 +0000 | [diff] [blame] | 882 | Method = CGM.BuildCovariantThunk(MD, Extern, Adjustment); |
Anders Carlsson | ea35722 | 2009-12-04 02:52:22 +0000 | [diff] [blame] | 883 | } else if (!ThisAdjustment.isEmpty()) { |
| 884 | // Build a "regular" thunk. |
Anders Carlsson | 2fce216 | 2009-12-04 03:06:03 +0000 | [diff] [blame] | 885 | Method = CGM.BuildThunk(GD, Extern, ThisAdjustment); |
Anders Carlsson | bf54027 | 2009-12-04 02:56:03 +0000 | [diff] [blame] | 886 | } else if (MD->isPure()) { |
| 887 | // We have a pure virtual method. |
Anders Carlsson | 2fce216 | 2009-12-04 03:06:03 +0000 | [diff] [blame] | 888 | Method = getPureVirtualFn(); |
| 889 | } else { |
| 890 | // We have a good old regular method. |
| 891 | Method = WrapAddrOf(GD); |
Anders Carlsson | ea35722 | 2009-12-04 02:52:22 +0000 | [diff] [blame] | 892 | } |
Anders Carlsson | 2fce216 | 2009-12-04 03:06:03 +0000 | [diff] [blame] | 893 | |
| 894 | // Add the method to the vtable. |
Anders Carlsson | 15318f4 | 2009-12-04 16:19:30 +0000 | [diff] [blame] | 895 | Vtable.push_back(Method); |
Anders Carlsson | b73ba39 | 2009-12-04 02:43:50 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Anders Carlsson | 2fce216 | 2009-12-04 03:06:03 +0000 | [diff] [blame] | 898 | |
Anders Carlsson | b73ba39 | 2009-12-04 02:43:50 +0000 | [diff] [blame] | 899 | ThisAdjustments.clear(); |
Anders Carlsson | ea35722 | 2009-12-04 02:52:22 +0000 | [diff] [blame] | 900 | BaseReturnTypes.clear(); |
Anders Carlsson | b73ba39 | 2009-12-04 02:43:50 +0000 | [diff] [blame] | 901 | |
Anders Carlsson | adfa267 | 2009-12-04 02:39:04 +0000 | [diff] [blame] | 902 | Methods.clear(); |
Anders Carlsson | adfa267 | 2009-12-04 02:39:04 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 905 | void CGVtableInfo::ComputeMethodVtableIndices(const CXXRecordDecl *RD) { |
| 906 | |
| 907 | // Itanium C++ ABI 2.5.2: |
| 908 | // The order of the virtual function pointers in a virtual table is the |
| 909 | // order of declaration of the corresponding member functions in the class. |
| 910 | // |
| 911 | // There is an entry for any virtual function declared in a class, |
| 912 | // whether it is a new function or overrides a base class function, |
| 913 | // unless it overrides a function from the primary base, and conversion |
| 914 | // between their return types does not require an adjustment. |
| 915 | |
| 916 | int64_t CurrentIndex = 0; |
| 917 | |
| 918 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 919 | const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); |
| 920 | |
| 921 | if (PrimaryBase) { |
Anders Carlsson | 0121fbd | 2009-11-30 19:43:26 +0000 | [diff] [blame] | 922 | assert(PrimaryBase->isDefinition() && |
| 923 | "Should have the definition decl of the primary base!"); |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 924 | |
| 925 | // Since the record decl shares its vtable pointer with the primary base |
| 926 | // we need to start counting at the end of the primary base's vtable. |
| 927 | CurrentIndex = getNumVirtualFunctionPointers(PrimaryBase); |
| 928 | } |
| 929 | |
| 930 | const CXXDestructorDecl *ImplicitVirtualDtor = 0; |
| 931 | |
| 932 | for (CXXRecordDecl::method_iterator i = RD->method_begin(), |
| 933 | e = RD->method_end(); i != e; ++i) { |
| 934 | const CXXMethodDecl *MD = *i; |
| 935 | |
| 936 | // We only want virtual methods. |
| 937 | if (!MD->isVirtual()) |
| 938 | continue; |
| 939 | |
| 940 | bool ShouldAddEntryForMethod = true; |
| 941 | |
| 942 | // Check if this method overrides a method in the primary base. |
| 943 | for (CXXMethodDecl::method_iterator i = MD->begin_overridden_methods(), |
| 944 | e = MD->end_overridden_methods(); i != e; ++i) { |
Anders Carlsson | 3aaf486 | 2009-12-04 05:51:56 +0000 | [diff] [blame] | 945 | const CXXMethodDecl *OverriddenMD = *i; |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 946 | const CXXRecordDecl *OverriddenRD = OverriddenMD->getParent(); |
| 947 | assert(OverriddenMD->isCanonicalDecl() && |
| 948 | "Should have the canonical decl of the overridden RD!"); |
| 949 | |
| 950 | if (OverriddenRD == PrimaryBase) { |
| 951 | // Check if converting from the return type of the method to the |
| 952 | // return type of the overridden method requires conversion. |
| 953 | QualType ReturnType = |
| 954 | MD->getType()->getAs<FunctionType>()->getResultType(); |
| 955 | QualType OverriddenReturnType = |
| 956 | OverriddenMD->getType()->getAs<FunctionType>()->getResultType(); |
| 957 | |
| 958 | if (!TypeConversionRequiresAdjustment(CGM.getContext(), |
| 959 | ReturnType, OverriddenReturnType)) { |
| 960 | // This index is shared between the index in the vtable of the primary |
| 961 | // base class. |
| 962 | if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) { |
| 963 | const CXXDestructorDecl *OverriddenDD = |
| 964 | cast<CXXDestructorDecl>(OverriddenMD); |
| 965 | |
| 966 | // Add both the complete and deleting entries. |
| 967 | MethodVtableIndices[GlobalDecl(DD, Dtor_Complete)] = |
| 968 | getMethodVtableIndex(GlobalDecl(OverriddenDD, Dtor_Complete)); |
| 969 | MethodVtableIndices[GlobalDecl(DD, Dtor_Deleting)] = |
| 970 | getMethodVtableIndex(GlobalDecl(OverriddenDD, Dtor_Deleting)); |
| 971 | } else { |
| 972 | MethodVtableIndices[MD] = getMethodVtableIndex(OverriddenMD); |
| 973 | } |
| 974 | |
| 975 | // We don't need to add an entry for this method. |
| 976 | ShouldAddEntryForMethod = false; |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | if (!ShouldAddEntryForMethod) |
| 983 | continue; |
| 984 | |
| 985 | if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(MD)) { |
| 986 | if (MD->isImplicit()) { |
| 987 | assert(!ImplicitVirtualDtor && |
| 988 | "Did already see an implicit virtual dtor!"); |
| 989 | ImplicitVirtualDtor = DD; |
| 990 | continue; |
| 991 | } |
| 992 | |
| 993 | // Add the complete dtor. |
| 994 | MethodVtableIndices[GlobalDecl(DD, Dtor_Complete)] = CurrentIndex++; |
| 995 | |
| 996 | // Add the deleting dtor. |
| 997 | MethodVtableIndices[GlobalDecl(DD, Dtor_Deleting)] = CurrentIndex++; |
| 998 | } else { |
| 999 | // Add the entry. |
| 1000 | MethodVtableIndices[MD] = CurrentIndex++; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | if (ImplicitVirtualDtor) { |
| 1005 | // Itanium C++ ABI 2.5.2: |
| 1006 | // If a class has an implicitly-defined virtual destructor, |
| 1007 | // its entries come after the declared virtual function pointers. |
| 1008 | |
| 1009 | // Add the complete dtor. |
| 1010 | MethodVtableIndices[GlobalDecl(ImplicitVirtualDtor, Dtor_Complete)] = |
| 1011 | CurrentIndex++; |
| 1012 | |
| 1013 | // Add the deleting dtor. |
| 1014 | MethodVtableIndices[GlobalDecl(ImplicitVirtualDtor, Dtor_Deleting)] = |
| 1015 | CurrentIndex++; |
| 1016 | } |
| 1017 | |
| 1018 | NumVirtualFunctionPointers[RD] = CurrentIndex; |
| 1019 | } |
| 1020 | |
| 1021 | uint64_t CGVtableInfo::getNumVirtualFunctionPointers(const CXXRecordDecl *RD) { |
| 1022 | llvm::DenseMap<const CXXRecordDecl *, uint64_t>::iterator I = |
| 1023 | NumVirtualFunctionPointers.find(RD); |
| 1024 | if (I != NumVirtualFunctionPointers.end()) |
| 1025 | return I->second; |
| 1026 | |
| 1027 | ComputeMethodVtableIndices(RD); |
| 1028 | |
| 1029 | I = NumVirtualFunctionPointers.find(RD); |
| 1030 | assert(I != NumVirtualFunctionPointers.end() && "Did not find entry!"); |
| 1031 | return I->second; |
| 1032 | } |
| 1033 | |
| 1034 | uint64_t CGVtableInfo::getMethodVtableIndex(GlobalDecl GD) { |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 1035 | MethodVtableIndicesTy::iterator I = MethodVtableIndices.find(GD); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1036 | if (I != MethodVtableIndices.end()) |
| 1037 | return I->second; |
| 1038 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 1039 | const CXXRecordDecl *RD = cast<CXXMethodDecl>(GD.getDecl())->getParent(); |
Anders Carlsson | d6b07fb | 2009-11-27 20:47:55 +0000 | [diff] [blame] | 1040 | |
| 1041 | ComputeMethodVtableIndices(RD); |
| 1042 | |
Anders Carlsson | a0fdd91 | 2009-11-13 17:08:56 +0000 | [diff] [blame] | 1043 | I = MethodVtableIndices.find(GD); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1044 | assert(I != MethodVtableIndices.end() && "Did not find index!"); |
| 1045 | return I->second; |
| 1046 | } |
| 1047 | |
| 1048 | int64_t CGVtableInfo::getVirtualBaseOffsetIndex(const CXXRecordDecl *RD, |
| 1049 | const CXXRecordDecl *VBase) { |
| 1050 | ClassPairTy ClassPair(RD, VBase); |
| 1051 | |
| 1052 | VirtualBaseClassIndiciesTy::iterator I = |
| 1053 | VirtualBaseClassIndicies.find(ClassPair); |
| 1054 | if (I != VirtualBaseClassIndicies.end()) |
| 1055 | return I->second; |
| 1056 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1057 | // FIXME: This seems expensive. Can we do a partial job to get |
| 1058 | // just this data. |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 1059 | VtableBuilder b(RD, RD, 0, CGM, false); |
Mike Stump | 6a9612f | 2009-10-31 20:06:59 +0000 | [diff] [blame] | 1060 | D1(printf("vtable %s\n", RD->getNameAsCString())); |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1061 | b.GenerateVtableForBase(RD); |
| 1062 | b.GenerateVtableForVBases(RD); |
| 1063 | |
| 1064 | for (llvm::DenseMap<const CXXRecordDecl *, uint64_t>::iterator I = |
| 1065 | b.getVBIndex().begin(), E = b.getVBIndex().end(); I != E; ++I) { |
| 1066 | // Insert all types. |
| 1067 | ClassPairTy ClassPair(RD, I->first); |
| 1068 | |
| 1069 | VirtualBaseClassIndicies.insert(std::make_pair(ClassPair, I->second)); |
| 1070 | } |
| 1071 | |
| 1072 | I = VirtualBaseClassIndicies.find(ClassPair); |
| 1073 | assert(I != VirtualBaseClassIndicies.end() && "Did not find index!"); |
| 1074 | |
| 1075 | return I->second; |
| 1076 | } |
| 1077 | |
Anders Carlsson | 9ac95b9 | 2009-12-05 21:03:56 +0000 | [diff] [blame] | 1078 | uint64_t CGVtableInfo::getVtableAddressPoint(const CXXRecordDecl *RD) { |
| 1079 | uint64_t AddressPoint = |
| 1080 | (*(*(CGM.AddressPoints[RD]))[RD])[std::make_pair(RD, 0)]; |
| 1081 | |
| 1082 | return AddressPoint; |
| 1083 | } |
| 1084 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 1085 | /// createGlobalVariable - Create a global variable to be used for storing |
| 1086 | /// either a vtable, a construction vtable or a VTT. The returned global |
| 1087 | // variable will have the correct linkage set based on the given record decl. |
| 1088 | static llvm::GlobalVariable * |
| 1089 | createGlobalVariable(CodeGenModule &CGM, const CXXRecordDecl *RD, |
| 1090 | const llvm::Type *Type, llvm::Constant *Init, |
| 1091 | const llvm::Twine &Name) { |
| 1092 | |
| 1093 | // Figure out the right linkage. |
| 1094 | llvm::GlobalVariable::LinkageTypes Linkage = |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 1095 | llvm::GlobalValue::WeakODRLinkage; |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 1096 | if (!Init) |
| 1097 | Linkage = llvm::GlobalValue::ExternalLinkage; |
| 1098 | else if (RD->isInAnonymousNamespace()) |
| 1099 | Linkage = llvm::GlobalValue::InternalLinkage; |
| 1100 | |
| 1101 | // Create the variable. |
| 1102 | llvm::GlobalVariable *V = |
| 1103 | new llvm::GlobalVariable(CGM.getModule(), Type, /*isConstant=*/true, |
| 1104 | Linkage, Init, Name); |
| 1105 | |
| 1106 | |
| 1107 | bool Hidden = CGM.getDeclVisibilityMode(RD) == LangOptions::Hidden; |
| 1108 | if (Hidden) |
| 1109 | V->setVisibility(llvm::GlobalVariable::HiddenVisibility); |
| 1110 | |
| 1111 | return V; |
| 1112 | } |
| 1113 | |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1114 | llvm::Constant *CodeGenModule::GenerateVtable(const CXXRecordDecl *LayoutClass, |
| 1115 | const CXXRecordDecl *RD, |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 1116 | uint64_t Offset) { |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1117 | llvm::SmallString<256> OutName; |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1118 | if (LayoutClass != RD) |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 1119 | getMangleContext().mangleCXXCtorVtable(LayoutClass, Offset/8, RD, OutName); |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 1120 | else |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 1121 | getMangleContext().mangleCXXVtable(RD, OutName); |
| 1122 | llvm::StringRef Name = OutName.str(); |
Benjamin Kramer | 7a9474e | 2009-10-11 22:57:54 +0000 | [diff] [blame] | 1123 | |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1124 | llvm::Type *Ptr8Ty=llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext),0); |
| 1125 | int64_t AddressPoint; |
| 1126 | |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1127 | llvm::GlobalVariable *GV = getModule().getGlobalVariable(Name); |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 1128 | if (GV && AddressPoints[LayoutClass] && !GV->isDeclaration()) { |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1129 | AddressPoint=(*(*(AddressPoints[LayoutClass]))[RD])[std::make_pair(RD, |
| 1130 | Offset)]; |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 1131 | // FIXME: We can never have 0 address point. Do this for now so gepping |
| 1132 | // retains the same structure. Later, we'll just assert. |
| 1133 | if (AddressPoint == 0) |
| 1134 | AddressPoint = 1; |
| 1135 | } else { |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1136 | bool CreateDefinition = true; |
| 1137 | if (LayoutClass != RD) |
| 1138 | CreateDefinition = true; |
| 1139 | else { |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 1140 | const ASTRecordLayout &Layout = |
| 1141 | getContext().getASTRecordLayout(LayoutClass); |
| 1142 | |
| 1143 | if (const CXXMethodDecl *KeyFunction = Layout.getKeyFunction()) { |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1144 | if (!KeyFunction->getBody()) { |
| 1145 | // If there is a KeyFunction, and it isn't defined, just build a |
| 1146 | // reference to the vtable. |
| 1147 | CreateDefinition = false; |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | |
Eli Friedman | 152b5b1 | 2009-12-05 01:05:03 +0000 | [diff] [blame] | 1152 | VtableBuilder b(RD, LayoutClass, Offset, *this, CreateDefinition); |
| 1153 | |
| 1154 | D1(printf("vtable %s\n", RD->getNameAsCString())); |
| 1155 | // First comes the vtables for all the non-virtual bases... |
| 1156 | AddressPoint = b.GenerateVtableForBase(RD, Offset); |
| 1157 | |
| 1158 | // then the vtables for all the virtual bases. |
| 1159 | b.GenerateVtableForVBases(RD, Offset); |
| 1160 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 1161 | llvm::Constant *Init = 0; |
| 1162 | llvm::ArrayType *ArrayType = |
Anders Carlsson | e40477c | 2009-12-05 21:09:05 +0000 | [diff] [blame] | 1163 | llvm::ArrayType::get(Ptr8Ty, b.getVtable().size()); |
| 1164 | |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1165 | if (CreateDefinition) { |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 1166 | Init = llvm::ConstantArray::get(ArrayType, &b.getVtable()[0], |
| 1167 | b.getVtable().size()); |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1168 | } |
| 1169 | llvm::GlobalVariable *OGV = GV; |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 1170 | GV = createGlobalVariable(*this, LayoutClass, ArrayType, Init, Name); |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1171 | if (OGV) { |
| 1172 | GV->takeName(OGV); |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 1173 | llvm::Constant *NewPtr = |
| 1174 | llvm::ConstantExpr::getBitCast(GV, OGV->getType()); |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1175 | OGV->replaceAllUsesWith(NewPtr); |
| 1176 | OGV->eraseFromParent(); |
| 1177 | } |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1178 | } |
Anders Carlsson | bb27d86 | 2009-12-05 21:28:12 +0000 | [diff] [blame] | 1179 | |
| 1180 | return GV; |
Anders Carlsson | dbd920c | 2009-10-11 22:13:54 +0000 | [diff] [blame] | 1181 | } |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1182 | |
Mike Stump | 92f2fe2 | 2009-12-02 19:07:44 +0000 | [diff] [blame] | 1183 | namespace { |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1184 | class VTTBuilder { |
| 1185 | /// Inits - The list of values built for the VTT. |
| 1186 | std::vector<llvm::Constant *> &Inits; |
| 1187 | /// Class - The most derived class that this vtable is being built for. |
| 1188 | const CXXRecordDecl *Class; |
| 1189 | CodeGenModule &CGM; // Per-module state. |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1190 | llvm::SmallSet<const CXXRecordDecl *, 32> SeenVBase; |
Mike Stump | aee8de3 | 2009-11-11 03:08:24 +0000 | [diff] [blame] | 1191 | /// BLayout - Layout for the most derived class that this vtable is being |
| 1192 | /// built for. |
| 1193 | const ASTRecordLayout &BLayout; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1194 | CodeGenModule::AddrMap_t &AddressPoints; |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1195 | // vtbl - A pointer to the vtable for Class. |
| 1196 | llvm::Constant *ClassVtbl; |
| 1197 | llvm::LLVMContext &VMContext; |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1198 | |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1199 | /// BuildVtablePtr - Build up a referene to the given secondary vtable |
Anders Carlsson | bb27d86 | 2009-12-05 21:28:12 +0000 | [diff] [blame] | 1200 | llvm::Constant *BuildVtablePtr(llvm::Constant *Vtable, |
| 1201 | const CXXRecordDecl *VtableClass, |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1202 | const CXXRecordDecl *RD, |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1203 | uint64_t Offset) { |
Anders Carlsson | bb27d86 | 2009-12-05 21:28:12 +0000 | [diff] [blame] | 1204 | int64_t AddressPoint = |
| 1205 | (*AddressPoints[VtableClass])[std::make_pair(RD, Offset)]; |
| 1206 | |
Mike Stump | 80ac235 | 2009-11-12 23:36:21 +0000 | [diff] [blame] | 1207 | // FIXME: We can never have 0 address point. Do this for now so gepping |
Mike Stump | 23a3542 | 2009-11-19 20:52:19 +0000 | [diff] [blame] | 1208 | // retains the same structure. Later we'll just assert. |
Mike Stump | 80ac235 | 2009-11-12 23:36:21 +0000 | [diff] [blame] | 1209 | if (AddressPoint == 0) |
| 1210 | AddressPoint = 1; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1211 | D1(printf("XXX address point for %s in %s layout %s at offset %d was %d\n", |
| 1212 | RD->getNameAsCString(), VtblClass->getNameAsCString(), |
| 1213 | Class->getNameAsCString(), (int)Offset, (int)AddressPoint)); |
Anders Carlsson | bb27d86 | 2009-12-05 21:28:12 +0000 | [diff] [blame] | 1214 | |
| 1215 | llvm::Value *Idxs[] = { |
| 1216 | llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), 0), |
| 1217 | llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), AddressPoint) |
| 1218 | }; |
| 1219 | |
| 1220 | llvm::Constant *Init = |
| 1221 | llvm::ConstantExpr::getInBoundsGetElementPtr(Vtable, Idxs, 2); |
| 1222 | |
| 1223 | const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); |
| 1224 | return llvm::ConstantExpr::getBitCast(Init, Int8PtrTy); |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1227 | /// Secondary - Add the secondary vtable pointers to Inits. Offset is the |
| 1228 | /// current offset in bits to the object we're working on. |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1229 | void Secondary(const CXXRecordDecl *RD, llvm::Constant *vtbl, |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1230 | const CXXRecordDecl *VtblClass, uint64_t Offset=0, |
| 1231 | bool MorallyVirtual=false) { |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1232 | if (RD->getNumVBases() == 0 && ! MorallyVirtual) |
| 1233 | return; |
| 1234 | |
| 1235 | for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), |
| 1236 | e = RD->bases_end(); i != e; ++i) { |
| 1237 | const CXXRecordDecl *Base = |
| 1238 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 1239 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 1240 | const CXXRecordDecl *PrimaryBase = Layout.getPrimaryBase(); |
| 1241 | const bool PrimaryBaseWasVirtual = Layout.getPrimaryBaseWasVirtual(); |
| 1242 | bool NonVirtualPrimaryBase; |
| 1243 | NonVirtualPrimaryBase = !PrimaryBaseWasVirtual && Base == PrimaryBase; |
| 1244 | bool BaseMorallyVirtual = MorallyVirtual | i->isVirtual(); |
Mike Stump | aee8de3 | 2009-11-11 03:08:24 +0000 | [diff] [blame] | 1245 | uint64_t BaseOffset; |
| 1246 | if (!i->isVirtual()) { |
| 1247 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 1248 | BaseOffset = Offset + Layout.getBaseClassOffset(Base); |
| 1249 | } else |
| 1250 | BaseOffset = BLayout.getVBaseClassOffset(Base); |
Mike Stump | 80ac235 | 2009-11-12 23:36:21 +0000 | [diff] [blame] | 1251 | llvm::Constant *subvtbl = vtbl; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1252 | const CXXRecordDecl *subVtblClass = VtblClass; |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1253 | if ((Base->getNumVBases() || BaseMorallyVirtual) |
| 1254 | && !NonVirtualPrimaryBase) { |
| 1255 | // FIXME: Slightly too many of these for __ZTT8test8_B2 |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1256 | llvm::Constant *init; |
Mike Stump | 80ac235 | 2009-11-12 23:36:21 +0000 | [diff] [blame] | 1257 | if (BaseMorallyVirtual) |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1258 | init = BuildVtablePtr(vtbl, VtblClass, RD, Offset); |
Mike Stump | 80ac235 | 2009-11-12 23:36:21 +0000 | [diff] [blame] | 1259 | else { |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1260 | init = CGM.getVtableInfo().getCtorVtable(Class, Base, BaseOffset); |
Anders Carlsson | be58b39 | 2009-12-05 20:42:53 +0000 | [diff] [blame] | 1261 | |
| 1262 | subvtbl = init; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1263 | subVtblClass = Base; |
Anders Carlsson | be58b39 | 2009-12-05 20:42:53 +0000 | [diff] [blame] | 1264 | |
| 1265 | init = BuildVtablePtr(init, Class, Base, BaseOffset); |
Mike Stump | 80ac235 | 2009-11-12 23:36:21 +0000 | [diff] [blame] | 1266 | } |
Mike Stump | 28f7ce1 | 2009-11-12 22:56:32 +0000 | [diff] [blame] | 1267 | Inits.push_back(init); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1268 | } |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1269 | Secondary(Base, subvtbl, subVtblClass, BaseOffset, BaseMorallyVirtual); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1270 | } |
| 1271 | } |
| 1272 | |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1273 | /// BuiltVTT - Add the VTT to Inits. Offset is the offset in bits to the |
| 1274 | /// currnet object we're working on. |
| 1275 | void BuildVTT(const CXXRecordDecl *RD, uint64_t Offset, bool MorallyVirtual) { |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1276 | if (RD->getNumVBases() == 0 && !MorallyVirtual) |
| 1277 | return; |
| 1278 | |
Anders Carlsson | 4282edf | 2009-12-05 21:02:25 +0000 | [diff] [blame] | 1279 | llvm::Constant *Vtable; |
| 1280 | const CXXRecordDecl *VtableClass; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1281 | |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1282 | // First comes the primary virtual table pointer... |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1283 | if (MorallyVirtual) { |
Anders Carlsson | 4282edf | 2009-12-05 21:02:25 +0000 | [diff] [blame] | 1284 | Vtable = ClassVtbl; |
| 1285 | VtableClass = Class; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1286 | } else { |
Anders Carlsson | 4282edf | 2009-12-05 21:02:25 +0000 | [diff] [blame] | 1287 | Vtable = CGM.getVtableInfo().getCtorVtable(Class, RD, Offset); |
| 1288 | VtableClass = RD; |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1289 | } |
Anders Carlsson | 4282edf | 2009-12-05 21:02:25 +0000 | [diff] [blame] | 1290 | |
| 1291 | llvm::Constant *Init = BuildVtablePtr(Vtable, VtableClass, RD, Offset); |
| 1292 | Inits.push_back(Init); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1293 | |
| 1294 | // then the secondary VTTs.... |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1295 | SecondaryVTTs(RD, Offset, MorallyVirtual); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1296 | |
| 1297 | // and last the secondary vtable pointers. |
Anders Carlsson | 4282edf | 2009-12-05 21:02:25 +0000 | [diff] [blame] | 1298 | Secondary(RD, Vtable, VtableClass, Offset, MorallyVirtual); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /// SecondaryVTTs - Add the secondary VTTs to Inits. The secondary VTTs are |
| 1302 | /// built from each direct non-virtual proper base that requires a VTT in |
| 1303 | /// declaration order. |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1304 | void SecondaryVTTs(const CXXRecordDecl *RD, uint64_t Offset=0, |
| 1305 | bool MorallyVirtual=false) { |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1306 | for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), |
| 1307 | e = RD->bases_end(); i != e; ++i) { |
| 1308 | const CXXRecordDecl *Base = |
| 1309 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 1310 | if (i->isVirtual()) |
| 1311 | continue; |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1312 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 1313 | uint64_t BaseOffset = Offset + Layout.getBaseClassOffset(Base); |
| 1314 | BuildVTT(Base, BaseOffset, MorallyVirtual); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | /// VirtualVTTs - Add the VTT for each proper virtual base in inheritance |
| 1319 | /// graph preorder. |
| 1320 | void VirtualVTTs(const CXXRecordDecl *RD) { |
| 1321 | for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), |
| 1322 | e = RD->bases_end(); i != e; ++i) { |
| 1323 | const CXXRecordDecl *Base = |
| 1324 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 1325 | if (i->isVirtual() && !SeenVBase.count(Base)) { |
| 1326 | SeenVBase.insert(Base); |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1327 | uint64_t BaseOffset = BLayout.getVBaseClassOffset(Base); |
| 1328 | BuildVTT(Base, BaseOffset, true); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1329 | } |
| 1330 | VirtualVTTs(Base); |
| 1331 | } |
| 1332 | } |
Anders Carlsson | be58b39 | 2009-12-05 20:42:53 +0000 | [diff] [blame] | 1333 | |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1334 | public: |
| 1335 | VTTBuilder(std::vector<llvm::Constant *> &inits, const CXXRecordDecl *c, |
Mike Stump | aee8de3 | 2009-11-11 03:08:24 +0000 | [diff] [blame] | 1336 | CodeGenModule &cgm) |
| 1337 | : Inits(inits), Class(c), CGM(cgm), |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1338 | BLayout(cgm.getContext().getASTRecordLayout(c)), |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1339 | AddressPoints(*cgm.AddressPoints[c]), |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1340 | VMContext(cgm.getModule().getContext()) { |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 1341 | |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1342 | // First comes the primary virtual table pointer for the complete class... |
Anders Carlsson | bb27d86 | 2009-12-05 21:28:12 +0000 | [diff] [blame] | 1343 | ClassVtbl = CGM.getVtableInfo().getVtable(Class); |
Anders Carlsson | 2e32aae | 2009-12-05 20:58:49 +0000 | [diff] [blame] | 1344 | Inits.push_back(BuildVtablePtr(ClassVtbl, Class, Class, 0)); |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1345 | |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1346 | // then the secondary VTTs... |
| 1347 | SecondaryVTTs(Class); |
| 1348 | |
| 1349 | // then the secondary vtable pointers... |
Mike Stump | acfd1e5 | 2009-11-13 01:54:23 +0000 | [diff] [blame] | 1350 | Secondary(Class, ClassVtbl, Class); |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1351 | |
| 1352 | // and last, the virtual VTTs. |
| 1353 | VirtualVTTs(Class); |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1354 | } |
| 1355 | }; |
Mike Stump | 92f2fe2 | 2009-12-02 19:07:44 +0000 | [diff] [blame] | 1356 | } |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1357 | |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 1358 | llvm::Constant *CodeGenModule::GenerateVTT(const CXXRecordDecl *RD) { |
Mike Stump | f1c0333 | 2009-11-10 19:13:04 +0000 | [diff] [blame] | 1359 | // Only classes that have virtual bases need a VTT. |
| 1360 | if (RD->getNumVBases() == 0) |
| 1361 | return 0; |
| 1362 | |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1363 | llvm::SmallString<256> OutName; |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 1364 | getMangleContext().mangleCXXVTT(RD, OutName); |
| 1365 | llvm::StringRef Name = OutName.str(); |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1366 | |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1367 | |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1368 | D1(printf("vtt %s\n", RD->getNameAsCString())); |
| 1369 | |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 1370 | std::vector<llvm::Constant *> inits; |
Mike Stump | 971977f | 2009-11-11 00:35:07 +0000 | [diff] [blame] | 1371 | VTTBuilder b(inits, RD, *this); |
| 1372 | |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 1373 | const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(VMContext); |
| 1374 | const llvm::ArrayType *Type = llvm::ArrayType::get(Int8PtrTy, inits.size()); |
| 1375 | |
| 1376 | llvm::Constant *Init = llvm::ConstantArray::get(Type, inits); |
| 1377 | |
| 1378 | llvm::GlobalVariable *VTT = |
| 1379 | createGlobalVariable(*this, RD, Type, Init, Name); |
| 1380 | |
| 1381 | return llvm::ConstantExpr::getBitCast(VTT, Int8PtrTy); |
Mike Stump | fbfb52d | 2009-11-10 02:30:51 +0000 | [diff] [blame] | 1382 | } |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 1383 | |
Mike Stump | 5858894 | 2009-11-19 01:08:19 +0000 | [diff] [blame] | 1384 | void CGVtableInfo::GenerateClassData(const CXXRecordDecl *RD) { |
| 1385 | Vtables[RD] = CGM.GenerateVtable(RD, RD); |
Mike Stump | de05057 | 2009-12-02 18:57:08 +0000 | [diff] [blame] | 1386 | CGM.GenerateRTTI(RD); |
Mike Stump | 5858894 | 2009-11-19 01:08:19 +0000 | [diff] [blame] | 1387 | CGM.GenerateVTT(RD); |
| 1388 | } |
| 1389 | |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 1390 | llvm::Constant *CGVtableInfo::getVtable(const CXXRecordDecl *RD) { |
Anders Carlsson | 224c312 | 2009-12-05 22:42:54 +0000 | [diff] [blame^] | 1391 | llvm::Constant *&Vtable = Vtables[RD]; |
| 1392 | if (!Vtable) |
| 1393 | Vtable = CGM.GenerateVtable(RD, RD); |
Mike Stump | 85615df | 2009-11-19 04:04:36 +0000 | [diff] [blame] | 1394 | |
Anders Carlsson | 224c312 | 2009-12-05 22:42:54 +0000 | [diff] [blame^] | 1395 | return Vtable; |
Mike Stump | 380dd75 | 2009-11-10 07:44:33 +0000 | [diff] [blame] | 1396 | } |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 1397 | |
Mike Stump | 9840c70 | 2009-11-12 20:47:57 +0000 | [diff] [blame] | 1398 | llvm::Constant *CGVtableInfo::getCtorVtable(const CXXRecordDecl *LayoutClass, |
| 1399 | const CXXRecordDecl *RD, |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 1400 | uint64_t Offset) { |
Anders Carlsson | bb27d86 | 2009-12-05 21:28:12 +0000 | [diff] [blame] | 1401 | return CGM.GenerateVtable(LayoutClass, RD, Offset); |
Mike Stump | 8cfcb52 | 2009-11-11 20:26:26 +0000 | [diff] [blame] | 1402 | } |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 1403 | |
| 1404 | void CGVtableInfo::MaybeEmitVtable(GlobalDecl GD) { |
| 1405 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl()); |
| 1406 | const CXXRecordDecl *RD = MD->getParent(); |
| 1407 | |
Anders Carlsson | 224c312 | 2009-12-05 22:42:54 +0000 | [diff] [blame^] | 1408 | // If the class doesn't have a vtable we don't need to emit one. |
| 1409 | if (!RD->isDynamicClass()) |
| 1410 | return; |
| 1411 | |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 1412 | const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD); |
| 1413 | |
| 1414 | // Get the key function. |
| 1415 | const CXXMethodDecl *KeyFunction = Layout.getKeyFunction(); |
| 1416 | |
Anders Carlsson | 224c312 | 2009-12-05 22:42:54 +0000 | [diff] [blame^] | 1417 | if (KeyFunction) { |
| 1418 | // We don't have the right key function. |
| 1419 | if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl()) |
| 1420 | return; |
| 1421 | |
| 1422 | // If the key function is a destructor, we only want to emit the vtable |
| 1423 | // once, so do it for the complete destructor. |
| 1424 | if (isa<CXXDestructorDecl>(MD) && GD.getDtorType() != Dtor_Complete) |
| 1425 | return; |
| 1426 | } else { |
| 1427 | // If there is no key function, we only want to emit the vtable if we are |
| 1428 | // emitting a constructor. |
| 1429 | if (!isa<CXXConstructorDecl>(MD) || GD.getCtorType() != Ctor_Complete) |
| 1430 | return; |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Anders Carlsson | 1a5e0d7 | 2009-11-30 23:41:22 +0000 | [diff] [blame] | 1433 | // Emit the data. |
| 1434 | GenerateClassData(RD); |
| 1435 | } |
| 1436 | |