From ce76304627d39e9e4308a2d0fe63d7b4651feaa5 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 20 Aug 2013 21:49:21 +0000 Subject: [PATCH] DebugInfo: comment/inlining based on feedback from Eric & Adrian llvm-svn: 188834 --- clang/lib/CodeGen/CGDebugInfo.cpp | 31 ++++++++++++++++--------------- clang/lib/CodeGen/CGDebugInfo.h | 3 --- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index d30925c..472d35a 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -946,9 +946,18 @@ void CGDebugInfo::CollectRecordFields(const RecordDecl *record, // the corresponding declarations in the source program. for (RecordDecl::decl_iterator I = record->decls_begin(), E = record->decls_end(); I != E; ++I) - if (const VarDecl *V = dyn_cast(*I)) - elements.push_back(getOrCreateStaticDataMemberDeclaration(V, RecordTy)); - else if (FieldDecl *field = dyn_cast(*I)) { + if (const VarDecl *V = dyn_cast(*I)) { + // Reuse the existing static member declaration if one exists + llvm::DenseMap::iterator MI = + StaticDataMemberCache.find(V->getCanonicalDecl()); + if (MI != StaticDataMemberCache.end()) { + assert(MI->second && + "Static data member declaration should still exist"); + elements.push_back( + llvm::DIDerivedType(cast(MI->second))); + } else + elements.push_back(CreateRecordStaticField(V, RecordTy)); + } else if (FieldDecl *field = dyn_cast(*I)) { CollectRecordNormalField(field, layout.getFieldOffset(fieldNo), tunit, elements, RecordTy); @@ -1123,6 +1132,7 @@ CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit, continue; if (const CXXMethodDecl *Method = dyn_cast(D)) { + // Reuse the existing member function declaration if it exists llvm::DenseMap::iterator MI = SPCache.find(Method->getCanonicalDecl()); if (MI == SPCache.end()) @@ -3067,6 +3077,9 @@ CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { assert(MI->second && "Static data member declaration should still exist"); return llvm::DIDerivedType(cast(MI->second)); } + + // If the member wasn't found in the cache, lazily construct and add it to the + // type (used when a limited form of the type is emitted). llvm::DICompositeType Ctxt( getContextDescriptor(cast(D->getDeclContext()))); llvm::DIDerivedType T = CreateRecordStaticField(D, Ctxt); @@ -3074,18 +3087,6 @@ CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { return T; } -llvm::DIDerivedType -CGDebugInfo::getOrCreateStaticDataMemberDeclaration(const VarDecl *D, - llvm::DICompositeType Ctxt) { - llvm::DenseMap::iterator MI = - StaticDataMemberCache.find(D->getCanonicalDecl()); - if (MI != StaticDataMemberCache.end()) { - assert(MI->second && "Static data member declaration should still exist"); - return llvm::DIDerivedType(cast(MI->second)); - } - return CreateRecordStaticField(D, Ctxt); -} - /// EmitGlobalVariable - Emit information about a global variable. void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 6ecc7e5..4807b11 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -359,9 +359,6 @@ private: /// declaration for the given out-of-class definition. llvm::DIDerivedType getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D); - llvm::DIDerivedType - getOrCreateStaticDataMemberDeclaration(const VarDecl *D, - llvm::DICompositeType Ctxt); /// getFunctionName - Get function name for the given FunctionDecl. If the /// name is constructred on demand (e.g. C++ destructor) then the name -- 2.7.4