[llvm-commits] [llvm-gcc-4.2] r90256 - in /llvm-gcc-4.2/trunk/gcc: llvm-debug.cpp llvm-debug.h

Devang Patel dpatel at apple.com
Tue Dec 1 12:06:39 PST 2009


Author: dpatel
Date: Tue Dec  1 14:06:38 2009
New Revision: 90256

URL: http://llvm.org/viewvc/llvm-project?rev=90256&view=rev
Log:
Do not ignore nameless records while emitting debug info. Keep track of scope for nested records.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-debug.h

Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp?rev=90256&r1=90255&r2=90256&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.cpp Tue Dec  1 14:06:38 2009
@@ -251,8 +251,8 @@
                                   true /*definition*/);
 
   // Push function on region stack.
-  RegionStack.push_back(SP);
-  RegionMap[FnDecl] = SP;
+  RegionStack.push_back(WeakVH(SP.getNode()));
+  RegionMap[FnDecl] = WeakVH(SP.getNode());
 }
 
   /// findRegion - Find tree_node N's region.
@@ -260,9 +260,10 @@
   if (Node == NULL_TREE)
     return getOrCreateCompileUnit(main_input_filename);
 
-  std::map<tree_node *, DIDescriptor>::iterator I = RegionMap.find(Node);
+  std::map<tree_node *, WeakVH>::iterator I = RegionMap.find(Node);
   if (I != RegionMap.end())
-    return I->second;
+    if (MDNode *R = dyn_cast_or_null<MDNode>(I->second))
+      return DIDescriptor(R);
 
   if (TYPE_P (Node)) {
     if (TYPE_CONTEXT (Node))
@@ -317,20 +318,21 @@
   expanded_location Loc = GetNodeLocation(decl, false);
 
   // Construct variable.
+  DIScope VarScope = DIScope(cast<MDNode>(RegionStack.back()));
   llvm::DIVariable D =
-    DebugFactory.CreateVariable(Tag, RegionStack.back(), Name, 
-                                getOrCreateCompileUnit(Loc.file),
+    DebugFactory.CreateVariable(Tag, VarScope,
+                                Name, getOrCreateCompileUnit(Loc.file),
                                 Loc.line, getOrCreateType(type));
 
   // Insert an llvm.dbg.declare into the current block.
   Instruction *Call = DebugFactory.InsertDeclare(AI, D, 
                                                  Builder.GetInsertBlock());
 
-  llvm::DIDescriptor DR = RegionStack.back();
-  llvm::DIScope DS = llvm::DIScope(DR.getNode());
+//  llvm::DIDescriptor DR = RegionStack.back();
+//  llvm::DIScope DS = llvm::DIScope(DR.getNode());
   llvm::DILocation DO(NULL);
   llvm::DILocation DL = 
-    DebugFactory.CreateLocation(CurLineNo, 0 /* column */, DS, DO);
+    DebugFactory.CreateLocation(CurLineNo, 0 /* column */, VarScope, DO);
   Builder.SetDebugLocation(Call, DL.getNode());
 }
 
@@ -381,7 +383,7 @@
     
     if (RegionStack.empty())
       return;
-    llvm::DIDescriptor DR = RegionStack.back();
+    llvm::DIDescriptor DR(cast<MDNode>(RegionStack.back()));
     llvm::DIScope DS = llvm::DIScope(DR.getNode());
     llvm::DILocation DO(NULL);
     llvm::DILocation DL = 
@@ -685,6 +687,10 @@
   // Insert into the TypeCache so that recursive uses will find it.
   llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode();
   TypeCache[type] =  WeakVH(FwdDecl.getNode());
+
+  // Push the struct on region stack.
+  RegionStack.push_back(WeakVH(FwdDecl.getNode()));
+  RegionMap[type] = WeakVH(FwdDecl.getNode());
   
   // Convert all the elements.
   llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
@@ -720,7 +726,9 @@
         continue;
       
       /* Ignore nameless fields.  */
-      if (DECL_NAME (Member) == NULL_TREE)
+      if (DECL_NAME (Member) == NULL_TREE
+          && !(TREE_CODE (TREE_TYPE (Member)) == UNION_TYPE
+               || TREE_CODE (TREE_TYPE (Member)) == RECORD_TYPE))
         continue;
       
       // Get the location of the member.
@@ -775,6 +783,11 @@
   llvm::DIArray Elements =
     DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
 
+  RegionStack.pop_back();
+  std::map<tree_node *, WeakVH>::iterator RI = RegionMap.find(type);
+  if (RI != RegionMap.end())
+    RegionMap.erase(RI);
+
   llvm::DICompositeType RealDecl =
     DebugFactory.CreateCompositeType(Tag, findRegion(type),
                                      GetNodeName(type),
@@ -787,6 +800,7 @@
   // 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::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl);
+
   return RealDecl;
 }
 

Modified: llvm-gcc-4.2/trunk/gcc/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-debug.h?rev=90256&r1=90255&r2=90256&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-debug.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-debug.h Tue Dec  1 14:06:38 2009
@@ -65,10 +65,10 @@
   std::map<tree_node *, WeakVH > TypeCache;
                                         // Cache of previously constructed 
                                         // Types.
-  std::vector<DIDescriptor> RegionStack;
+  SmallVector<WeakVH, 4> RegionStack;
                                         // Stack to track declarative scopes.
   
-  std::map<tree_node *, DIDescriptor> RegionMap;
+  std::map<tree_node *, WeakVH> RegionMap;
 public:
   DebugInfo(Module *m);
 





More information about the llvm-commits mailing list