[cfe-commits] r94817 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h

Devang Patel dpatel at apple.com
Fri Jan 29 10:11:03 PST 2010


Author: dpatel
Date: Fri Jan 29 12:11:03 2010
New Revision: 94817

URL: http://llvm.org/viewvc/llvm-project?rev=94817&view=rev
Log:
Maintain a map of regions (lexical scopes) and use it to find context for a global variable.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=94817&r1=94816&r2=94817&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jan 29 12:11:03 2010
@@ -50,17 +50,13 @@
 }
 
 /// 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<Decl>(D->getDeclContext())) {
+   llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
+     I = RegionMap.find(Parent);
+   if (I != RegionMap.end())
+     return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second));
   }
   return CompileUnit;
 }
@@ -1273,6 +1269,7 @@
       llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(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 @@
 
   // Push function on region stack.
   RegionStack.push_back(SP.getNode());
+  RegionMap[D] = llvm::WeakVH(SP.getNode());
 }
 
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=94817&r1=94816&r2=94817&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri Jan 29 12:11:03 2010
@@ -61,6 +61,7 @@
   llvm::DIType BlockLiteralGeneric;
 
   std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack;
+  llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
 
   /// DebugInfoNames - This is a storage for names that are
   /// constructed on demand. For example, C++ destructors, C++ operators etc..
@@ -172,7 +173,7 @@
                    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





More information about the cfe-commits mailing list