From: Devang Patel Date: Fri, 29 Jan 2010 18:11:03 +0000 (+0000) Subject: Maintain a map of regions (lexical scopes) and use it to find context for a global... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3dd96a1489498deb03208f7011f48b9f3d7901db;p=clang Maintain a map of regions (lexical scopes) and use it to find context for a global variable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94817 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 3597098a60..ac3d5bd3b4 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -50,17 +50,13 @@ void CGDebugInfo::setLocation(SourceLocation Loc) { } /// getContextDescriptor - Get context info for the decl. -llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const VarDecl *Decl, +llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *D, llvm::DIDescriptor &CompileUnit) { - if (Decl->isFileVarDecl()) - return CompileUnit; - if (Decl->getDeclContext()->isFunctionOrMethod()) { - // Find the last subprogram in region stack. - for (unsigned RI = RegionStack.size(), RE = 0; RI != RE; --RI) { - llvm::DIDescriptor R(RegionStack[RI - 1]); - if (R.isSubprogram()) - return R; - } + if (const Decl *Parent = dyn_cast(D->getDeclContext())) { + llvm::DenseMap::iterator + I = RegionMap.find(Parent); + if (I != RegionMap.end()) + return llvm::DIDescriptor(dyn_cast_or_null(I->second)); } return CompileUnit; } @@ -1273,6 +1269,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, llvm::DISubprogram SP(dyn_cast_or_null(FI->second)); if (!SP.isNull() && SP.isSubprogram() && SP.isDefinition()) { RegionStack.push_back(SP.getNode()); + RegionMap[D] = llvm::WeakVH(SP.getNode()); return; } } @@ -1303,6 +1300,7 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, // Push function on region stack. RegionStack.push_back(SP.getNode()); + RegionMap[D] = llvm::WeakVH(SP.getNode()); } diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index a062b678f4..9a56a9ab5c 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -61,6 +61,7 @@ class CGDebugInfo { llvm::DIType BlockLiteralGeneric; std::vector > RegionStack; + llvm::DenseMap RegionMap; /// DebugInfoNames - This is a storage for names that are /// constructed on demand. For example, C++ destructors, C++ operators etc.. @@ -172,7 +173,7 @@ private: CGBuilderTy &Builder, CodeGenFunction *CGF); /// getContextDescriptor - Get context info for the decl. - llvm::DIDescriptor getContextDescriptor(const VarDecl *Decl, + llvm::DIDescriptor getContextDescriptor(const Decl *Decl, llvm::DIDescriptor &CU); /// getOrCreateCompileUnit - Get the compile unit from the cache or create a