From a00a4bcede57362261c01f6135e802763d8dec33 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Tue, 18 Nov 2014 03:40:46 +0000 Subject: [PATCH] [DebugInfo] Move collection of various function/var decl properties into helper functions. NFC. Helpers to be re-used in upcoming commit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222219 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 138 +++++++++++++++++++++--------------- lib/CodeGen/CGDebugInfo.h | 15 ++++ 2 files changed, 94 insertions(+), 59 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 24d86e5c00..8ba69eaa5c 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2303,6 +2303,77 @@ llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType, return Ty; } +void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, + llvm::DIFile Unit, + StringRef &Name, StringRef &LinkageName, + llvm::DIDescriptor &FDContext, + llvm::DIArray &TParamsArray, + unsigned &Flags) { + const FunctionDecl *FD = cast(GD.getDecl()); + Name = getFunctionName(FD); + // Use mangled name as linkage name for C/C++ functions. + if (FD->hasPrototype()) { + LinkageName = CGM.getMangledName(GD); + Flags |= llvm::DIDescriptor::FlagPrototyped; + } + // No need to replicate the linkage name if it isn't different from the + // subprogram name, no need to have it at all unless coverage is enabled or + // debug is set to more than just line tables. + if (LinkageName == Name || + (!CGM.getCodeGenOpts().EmitGcovArcs && + !CGM.getCodeGenOpts().EmitGcovNotes && + DebugKind <= CodeGenOptions::DebugLineTablesOnly)) + LinkageName = StringRef(); + + if (DebugKind >= CodeGenOptions::LimitedDebugInfo) { + if (const NamespaceDecl *NSDecl = + dyn_cast_or_null(FD->getDeclContext())) + FDContext = getOrCreateNameSpace(NSDecl); + else if (const RecordDecl *RDecl = + dyn_cast_or_null(FD->getDeclContext())) + FDContext = getContextDescriptor(cast(RDecl)); + // Collect template parameters. + TParamsArray = CollectFunctionTemplateParams(FD, Unit); + } +} + +void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile &Unit, + unsigned &LineNo, QualType &T, + StringRef &Name, StringRef &LinkageName, + llvm::DIDescriptor &VDContext) { + Unit = getOrCreateFile(VD->getLocation()); + LineNo = getLineNumber(VD->getLocation()); + + setLocation(VD->getLocation()); + + T = VD->getType(); + if (T->isIncompleteArrayType()) { + // CodeGen turns int[] into int[1] so we'll do the same here. + llvm::APInt ConstVal(32, 1); + QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); + + T = CGM.getContext().getConstantArrayType(ET, ConstVal, + ArrayType::Normal, 0); + } + + Name = VD->getName(); + if (VD->getDeclContext() && !isa(VD->getDeclContext()) && + !isa(VD->getDeclContext())) + LinkageName = CGM.getMangledName(VD); + if (LinkageName == Name) + LinkageName = StringRef(); + + // Since we emit declarations (DW_AT_members) for static members, place the + // definition of those static members in the namespace they were declared in + // in the source code (the lexical decl context). + // FIXME: Generalize this for even non-member global variables where the + // declaration and definition may have different lexical decl contexts, once + // we have support for emitting declarations of (non-member) global variables. + VDContext = getContextDescriptor( + dyn_cast(VD->isStaticDataMember() ? VD->getLexicalDeclContext() + : VD->getDeclContext())); +} + llvm::DIDescriptor CGDebugInfo::getDeclarationOrDefinition(const Decl *D) { // We only need a declaration (not a definition) of the type - so use whatever // we would otherwise do to get a type for a pointee. (forward declarations in @@ -2467,32 +2538,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, return; } } - Name = getFunctionName(FD); - // Use mangled name as linkage name for C/C++ functions. - if (FD->hasPrototype()) { - LinkageName = CGM.getMangledName(GD); - Flags |= llvm::DIDescriptor::FlagPrototyped; - } - // No need to replicate the linkage name if it isn't different from the - // subprogram name, no need to have it at all unless coverage is enabled or - // debug is set to more than just line tables. - if (LinkageName == Name || - (!CGM.getCodeGenOpts().EmitGcovArcs && - !CGM.getCodeGenOpts().EmitGcovNotes && - DebugKind <= CodeGenOptions::DebugLineTablesOnly)) - LinkageName = StringRef(); - - if (DebugKind >= CodeGenOptions::LimitedDebugInfo) { - if (const NamespaceDecl *NSDecl = - dyn_cast_or_null(FD->getDeclContext())) - FDContext = getOrCreateNameSpace(NSDecl); - else if (const RecordDecl *RDecl = - dyn_cast_or_null(FD->getDeclContext())) - FDContext = getContextDescriptor(cast(RDecl)); - - // Collect template parameters. - TParamsArray = CollectFunctionTemplateParams(FD, Unit); - } + collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext, + TParamsArray, Flags); } else if (const ObjCMethodDecl *OMD = dyn_cast(D)) { Name = getObjCMethodName(OMD); Flags |= llvm::DIDescriptor::FlagPrototyped; @@ -3125,39 +3172,12 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { assert(DebugKind >= CodeGenOptions::LimitedDebugInfo); // Create global variable debug descriptor. - llvm::DIFile Unit = getOrCreateFile(D->getLocation()); - unsigned LineNo = getLineNumber(D->getLocation()); - - setLocation(D->getLocation()); - - QualType T = D->getType(); - if (T->isIncompleteArrayType()) { - - // CodeGen turns int[] into int[1] so we'll do the same here. - llvm::APInt ConstVal(32, 1); - QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); - - T = CGM.getContext().getConstantArrayType(ET, ConstVal, ArrayType::Normal, - 0); - } - - StringRef DeclName = D->getName(); - StringRef LinkageName; - if (D->getDeclContext() && !isa(D->getDeclContext()) && - !isa(D->getDeclContext())) - LinkageName = Var->getName(); - if (LinkageName == DeclName) - LinkageName = StringRef(); - - // Since we emit declarations (DW_AT_members) for static members, place the - // definition of those static members in the namespace they were declared in - // in the source code (the lexical decl context). - // FIXME: Generalize this for even non-member global variables where the - // declaration and definition may have different lexical decl contexts, once - // we have support for emitting declarations of (non-member) global variables. - llvm::DIDescriptor DContext = getContextDescriptor( - dyn_cast(D->isStaticDataMember() ? D->getLexicalDeclContext() - : D->getDeclContext())); + llvm::DIFile Unit; + llvm::DIDescriptor DContext; + unsigned LineNo; + StringRef DeclName, LinkageName; + QualType T; + collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName, DContext); // Attempt to store one global variable for the declaration - even if we // emit a lot of fields. diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index e8b6ca91e2..896c54f13f 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -411,6 +411,21 @@ private: /// \param Force Assume DebugColumnInfo option is true. unsigned getColumnNumber(SourceLocation Loc, bool Force=false); + /// \brief Collect various properties of a FunctionDecl. + /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl. + void collectFunctionDeclProps(GlobalDecl GD, + llvm::DIFile Unit, + StringRef &Name, StringRef &LinkageName, + llvm::DIDescriptor &FDContext, + llvm::DIArray &TParamsArray, + unsigned &Flags); + + /// \brief Collect various properties of a VarDecl. + void collectVarDeclProps(const VarDecl *VD, llvm::DIFile &Unit, + unsigned &LineNo, QualType &T, + StringRef &Name, StringRef &LinkageName, + llvm::DIDescriptor &VDContext); + /// internString - Allocate a copy of \p A using the DebugInfoNames allocator /// and return a reference to it. If multiple arguments are given the strings /// are concatenated. -- 2.40.0