diff options
author | Eric Christopher <echristo@apple.com> | 2012-02-15 23:51:20 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2012-02-15 23:51:20 +0000 |
commit | 64a043045874c9a054f9dfb8d37daf6e5e8d054c (patch) | |
tree | ec705af4478c89bd54992e88ee241e07376bf838 /lib/CodeGen/CGDebugInfo.cpp | |
parent | 9a68d4584afcd0853b930bd80235b58736e785b4 (diff) |
Revert "Add a completed/incomplete type difference. This allows us to have"
This reverts commit 9a68d4584afcd0853b930bd80235b58736e785b4.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150637 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 241 |
1 files changed, 66 insertions, 175 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 73ab02519b..34da5f4d99 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -524,8 +524,11 @@ llvm::DIDescriptor CGDebugInfo::createContextChain(const Decl *Context) { if (const RecordDecl *RD = dyn_cast<RecordDecl>(Context)) { if (!RD->isDependentType()) { - llvm::DIType Ty = getOrCreateLimitedType(CGM.getContext().getTypeDeclType(RD), - getOrCreateMainFile()); + llvm::DIDescriptor FDContext = + createContextChain(cast<Decl>(RD->getDeclContext())); + llvm::DIType Ty = createRecordFwdDecl(RD, FDContext); + + RegionMap[Context] = llvm::WeakVH(Ty); return llvm::DIDescriptor(Ty); } } @@ -554,9 +557,7 @@ llvm::DIType CGDebugInfo::CreatePointeeType(QualType PointeeTy, RecordDecl *RD = RTy->getDecl(); llvm::DIDescriptor FDContext = getContextDescriptor(cast<Decl>(RD->getDeclContext())); - llvm::DIType RetTy = createRecordFwdDecl(RD, FDContext); - TypeCache[PointeeTy.getAsOpaquePtr()] = RetTy; - return RetTy; + return createRecordFwdDecl(RD, FDContext); } return getOrCreateType(PointeeTy, Unit); @@ -653,11 +654,10 @@ llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile Unit) { // declared. unsigned Line = getLineNumber(Ty->getDecl()->getLocation()); const TypedefNameDecl *TyDecl = Ty->getDecl(); - llvm::DIDescriptor TypedefContext = getContextDescriptor(cast<Decl>(Ty->getDecl()->getDeclContext())); - - return + + return DBuilder.createTypedef(Src, TyDecl->getName(), Unit, Line, TypedefContext); } @@ -1133,6 +1133,8 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) { // Get overall information about the record type for the debug info. llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); + unsigned Line = getLineNumber(RD->getLocation()); + StringRef RDName = RD->getName(); // Records and classes and unions can all be recursive. To handle them, we // first generate a debug descriptor for the struct as a forward declaration. @@ -1141,21 +1143,28 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) { // may refer to the forward decl if the struct is recursive) and replace all // uses of the forward declaration with the final definition. - llvm::DIType FwdDecl = getOrCreateLimitedType(QualType(Ty, 0), DefUnit); + llvm::DIDescriptor RDContext; + if (CGM.getCodeGenOpts().LimitDebugInfo) + RDContext = createContextChain(cast<Decl>(RD->getDeclContext())); + else + RDContext = getContextDescriptor(cast<Decl>(RD->getDeclContext())); + + // If this is just a forward declaration, construct an appropriately + // marked node and just return it. + if (!RD->getDefinition()) + return createRecordFwdDecl(RD, RDContext); + + llvm::DIType FwdDecl = DBuilder.createTemporaryType(DefUnit); - if (FwdDecl.isForwardDecl()) - return FwdDecl; - llvm::MDNode *MN = FwdDecl; llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; - + // Otherwise, insert it into the TypeCache so that recursive uses will find + // it. + TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; // Push the struct on region stack. LexicalBlockStack.push_back(FwdDeclNode); RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); - // Add this to the completed types cache since we're completing it. - CompletedTypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; - // Convert all the elements. SmallVector<llvm::Value *, 16> EltTys; @@ -1187,20 +1196,50 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) { if (RI != RegionMap.end()) RegionMap.erase(RI); + uint64_t Size = CGM.getContext().getTypeSize(Ty); + uint64_t Align = CGM.getContext().getTypeAlign(Ty); llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys); - // FIXME: Magic numbers ahoy! These should be changed when we - // get some enums in llvm/Analysis/DebugInfo.h to refer to - // them. + llvm::MDNode *RealDecl = NULL; + if (RD->isUnion()) - MN->replaceOperandWith(10, Elements); + RealDecl = DBuilder.createUnionType(RDContext, RDName, DefUnit, Line, + Size, Align, 0, Elements); else if (CXXDecl) { - MN->replaceOperandWith(10, Elements); - MN->replaceOperandWith(13, TParamsArray); + RDName = getClassName(RD); + // A class's primary base or the class itself contains the vtable. + llvm::MDNode *ContainingType = NULL; + const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); + if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) { + // Seek non virtual primary base root. + while (1) { + const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase); + const CXXRecordDecl *PBT = BRL.getPrimaryBase(); + if (PBT && !BRL.isPrimaryBaseVirtual()) + PBase = PBT; + else + break; + } + ContainingType = + getOrCreateType(QualType(PBase->getTypeForDecl(), 0), DefUnit); + } + else if (CXXDecl->isDynamicClass()) + ContainingType = FwdDecl; + + // FIXME: This could be a struct type giving a default visibility different + // than C++ class type, but needs llvm metadata changes first. + RealDecl = DBuilder.createClassType(RDContext, RDName, DefUnit, Line, + Size, Align, 0, 0, llvm::DIType(), + Elements, ContainingType, + TParamsArray); } else - MN->replaceOperandWith(10, Elements); + RealDecl = DBuilder.createStructType(RDContext, RDName, DefUnit, Line, + Size, Align, 0, Elements); - RegionMap[Ty->getDecl()] = llvm::WeakVH(MN); - return llvm::DIType(MN); + // Now that we have a real decl for the struct, replace anything using the + // old decl with the new one. This will recursively update the debug info. + llvm::DIType(FwdDeclNode).replaceAllUsesWith(RealDecl); + RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl); + return llvm::DIType(RealDecl); } /// CreateType - get objective-c object type. @@ -1598,26 +1637,6 @@ llvm::DIType CGDebugInfo::getTypeOrNull(QualType Ty) { return llvm::DIType(); } -/// getCompletedTypeOrNull - Get the type from the cache or return null if it -/// doesn't exist. -llvm::DIType CGDebugInfo::getCompletedTypeOrNull(QualType Ty) { - - // Unwrap the type as needed for debug information. - Ty = UnwrapTypeForDebugInfo(Ty); - - // Check for existing entry. - llvm::DenseMap<void *, llvm::WeakVH>::iterator it = - CompletedTypeCache.find(Ty.getAsOpaquePtr()); - if (it != CompletedTypeCache.end()) { - // Verify that the debug info still exists. - if (&*it->second) - return llvm::DIType(cast<llvm::MDNode>(it->second)); - } - - return llvm::DIType(); -} - - /// getOrCreateType - Get the type from the cache or create a new /// one if necessary. llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) { @@ -1627,21 +1646,14 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) { // Unwrap the type as needed for debug information. Ty = UnwrapTypeForDebugInfo(Ty); - llvm::DIType T = getCompletedTypeOrNull(Ty); - + llvm::DIType T = getTypeOrNull(Ty); if (T.Verify()) return T; // Otherwise create the type. llvm::DIType Res = CreateTypeNode(Ty, Unit); - if (T.Verify() && T.isForwardDecl()) - T.replaceAllUsesWith(Res); - // And update the type cache. - TypeCache[Ty.getAsOpaquePtr()] = Res; - - if (!Res.isForwardDecl()) - CompletedTypeCache[Ty.getAsOpaquePtr()] = Res; + TypeCache[Ty.getAsOpaquePtr()] = Res; return Res; } @@ -1725,127 +1737,6 @@ llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile Unit) { return llvm::DIType(); } -/// getOrCreateLimitedType - Get the type from the cache or create a new -/// limited type if necessary. -llvm::DIType CGDebugInfo::getOrCreateLimitedType(QualType Ty, - llvm::DIFile Unit) { - if (Ty.isNull()) - return llvm::DIType(); - - // Unwrap the type as needed for debug information. - Ty = UnwrapTypeForDebugInfo(Ty); - - llvm::DIType T = getTypeOrNull(Ty); - if (T.Verify() && !T.isForwardDecl()) return T; - - // Otherwise create the type. - llvm::DIType Res = CreateLimitedTypeNode(Ty, Unit); - - if (T.Verify() && T.isForwardDecl()) - T.replaceAllUsesWith(Res); - - // And update the type cache. - TypeCache[Ty.getAsOpaquePtr()] = Res; - return Res; -} - -// TODO: Currently used for context chains when limiting debug info. -llvm::DIType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { - RecordDecl *RD = Ty->getDecl(); - - // Get overall information about the record type for the debug info. - llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); - unsigned Line = getLineNumber(RD->getLocation()); - StringRef RDName = RD->getName(); - - llvm::DIDescriptor RDContext; - if (CGM.getCodeGenOpts().LimitDebugInfo) - RDContext = createContextChain(cast<Decl>(RD->getDeclContext())); - else - RDContext = getContextDescriptor(cast<Decl>(RD->getDeclContext())); - - // If this is just a forward declaration, construct an appropriately - // marked node and just return it. - if (!RD->getDefinition()) { - llvm::DIType RTy = createRecordFwdDecl(RD, RDContext); - TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RTy; - return RTy; - } - - // Create a temporary type here - different than normal forward declared - // types. - llvm::DIType FwdDecl = DBuilder.createTemporaryType(DefUnit); - - llvm::MDNode *MN = FwdDecl; - llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; - // Otherwise, insert it into the TypeCache so that recursive uses will find - // it. - TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; - - uint64_t Size = CGM.getContext().getTypeSize(Ty); - uint64_t Align = CGM.getContext().getTypeAlign(Ty); - const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD); - llvm::MDNode *RealDecl = NULL; - - if (RD->isUnion()) - RealDecl = DBuilder.createUnionType(RDContext, RDName, DefUnit, Line, - Size, Align, 0, llvm::DIArray()); - else if (CXXDecl) { - RDName = getClassName(RD); - // A class's primary base or the class itself contains the vtable. - llvm::MDNode *ContainingType = NULL; - const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); - if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) { - // Seek non virtual primary base root. - while (1) { - const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase); - const CXXRecordDecl *PBT = BRL.getPrimaryBase(); - if (PBT && !BRL.isPrimaryBaseVirtual()) - PBase = PBT; - else - break; - } - ContainingType = - getOrCreateType(QualType(PBase->getTypeForDecl(), 0), DefUnit); - } - else if (CXXDecl->isDynamicClass()) - ContainingType = FwdDecl; - - // FIXME: This could be a struct type giving a default visibility different - // than C++ class type, but needs llvm metadata changes first. - RealDecl = DBuilder.createClassType(RDContext, RDName, DefUnit, Line, - Size, Align, 0, 0, llvm::DIType(), - llvm::DIArray(), ContainingType, - llvm::DIArray()); - } else - RealDecl = DBuilder.createStructType(RDContext, RDName, DefUnit, Line, - Size, Align, 0, llvm::DIArray()); - - llvm::DIType(FwdDeclNode).replaceAllUsesWith(RealDecl); - RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl); - return llvm::DIType(RealDecl); -} - -/// CreateLimitedTypeNode - Create a new debug type node, but only forward -/// declare composite types that haven't been processed yet. -llvm::DIType CGDebugInfo::CreateLimitedTypeNode(QualType Ty,llvm::DIFile Unit) { - - // Work out details of type. - switch (Ty->getTypeClass()) { -#define TYPE(Class, Base) -#define ABSTRACT_TYPE(Class, Base) -#define NON_CANONICAL_TYPE(Class, Base) -#define DEPENDENT_TYPE(Class, Base) case Type::Class: - #include "clang/AST/TypeNodes.def" - llvm_unreachable("Dependent types cannot show up in debug information"); - - case Type::Record: - return CreateLimitedType(cast<RecordType>(Ty)); - default: - return CreateTypeNode(Ty, Unit); - } -} - /// CreateMemberType - Create new member and increase Offset by FType's size. llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType, StringRef Name, |