[llvm-branch-commits] [llvm-gcc-branch] r92845 - in /llvm-gcc-4.2/branches/Apple/Zoidberg/gcc: llvm-debug.cpp llvm-debug.h

Devang Patel dpatel at apple.com
Wed Jan 6 09:59:31 PST 2010


Author: dpatel
Date: Wed Jan  6 11:59:31 2010
New Revision: 92845

URL: http://llvm.org/viewvc/llvm-project?rev=92845&view=rev
Log:
Merge debug info changes from mainline.

91074
91353
91441


Modified:
    llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.cpp
    llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.h

Modified: llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.cpp?rev=92845&r1=92844&r2=92845&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.cpp (original)
+++ llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.cpp Wed Jan  6 11:59:31 2010
@@ -263,10 +263,20 @@
     Virtuality = dwarf::DW_VIRTUALITY_virtual;
     ContainingType = getOrCreateType(DECL_CONTEXT (FnDecl));
   }
+  bool UseModuleContext = false;
+  // If this artificial function has abstract origin then put this function
+  // at module scope. The abstract copy will be placed in appropriate region.
+  if (DECL_ABSTRACT_ORIGIN (FnDecl) != FnDecl
+      && DECL_ARTIFICIAL(FnDecl))
+    UseModuleContext = true;
+  
+  const char *FnName = lang_hooks.dwarf_name(FnDecl, 0);
   DISubprogram SP = 
-    DebugFactory.CreateSubprogram(findRegion(FnDecl),
-                                  lang_hooks.dwarf_name(FnDecl, 0),
-                                  lang_hooks.dwarf_name(FnDecl, 0),
+    DebugFactory.CreateSubprogram((UseModuleContext ?
+                                   getOrCreateCompileUnit(main_input_filename) :
+                                   findRegion(DECL_CONTEXT(FnDecl))),
+                                  (UseModuleContext ? FnName : StringRef()), 
+                                  (UseModuleContext ? FnName : StringRef()), 
                                   LinkageName,
                                   getOrCreateCompileUnit(Loc.file), lineno,
                                   FNType,
@@ -282,7 +292,23 @@
   RegionMap[FnDecl] = WeakVH(SP.getNode());
 }
 
-  /// findRegion - Find tree_node N's region.
+/// getOrCreateNameSpace - Get name space descriptor for the tree node.
+DINameSpace DebugInfo::getOrCreateNameSpace(tree Node, DIDescriptor Context) {
+  std::map<tree_node *, WeakVH >::iterator I = 
+    NameSpaceCache.find(Node);
+  if (I != NameSpaceCache.end())
+    return DINameSpace(cast<MDNode>(I->second));
+
+  expanded_location Loc = GetNodeLocation(Node, false);
+  DINameSpace DNS =
+    DebugFactory.CreateNameSpace(Context, GetNodeName(Node),
+                                 getOrCreateCompileUnit(Loc.file), Loc.line);
+
+  NameSpaceCache[Node] = WeakVH(DNS.getNode());
+  return DNS;
+}
+
+/// findRegion - Find tree_node N's region.
 DIDescriptor DebugInfo::findRegion(tree Node) {
   if (Node == NULL_TREE)
     return getOrCreateCompileUnit(main_input_filename);
@@ -293,19 +319,15 @@
       return DIDescriptor(R);
 
   if (TYPE_P (Node)) {
-    if (TYPE_CONTEXT (Node))
-      return findRegion (TYPE_CONTEXT(Node));
+    DIType Ty = getOrCreateType(Node);
+    return DIDescriptor(Ty.getNode());
   } else if (DECL_P (Node)) {
-    tree decl = Node;
-    tree context = NULL_TREE;
-    if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
-      context = DECL_CONTEXT (decl);
-    else
-      context = TYPE_MAIN_VARIANT
-        (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
-    
-    if (context != NULL_TREE)
-      return findRegion(context);
+    if (TREE_CODE (Node) == NAMESPACE_DECL) {
+      DIDescriptor NSContext = findRegion(DECL_CONTEXT(Node));
+      DINameSpace NS = getOrCreateNameSpace(Node, NSContext);
+      return DIDescriptor(NS.getNode());
+    }
+    return findRegion (DECL_CONTEXT (Node));
   }
 
   // Otherwise main compile unit covers everything.
@@ -422,6 +444,8 @@
 /// EmitGlobalVariable - Emit information about a global variable.
 ///
 void DebugInfo::EmitGlobalVariable(GlobalVariable *GV, tree decl) {
+  if (DECL_ARTIFICIAL(decl))
+    return;
   // Gather location information.
   expanded_location Loc = expand_location(DECL_SOURCE_LOCATION(decl));
   DIType TyD = getOrCreateType(TREE_TYPE(decl));
@@ -431,7 +455,7 @@
       DispName = IDENTIFIER_POINTER(DECL_NAME(decl));
   }
     
-  DebugFactory.CreateGlobalVariable(findRegion(decl),
+  DebugFactory.CreateGlobalVariable(findRegion(DECL_CONTEXT(decl)),
                                     DispName, DispName,
                                     getLinkageName(decl), 
                                     getOrCreateCompileUnit(Loc.file), Loc.line,
@@ -507,7 +531,8 @@
     DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
 
   return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
-                                          findRegion(type), StringRef(),
+                                          findRegion(TYPE_CONTEXT(type)), 
+                                          StringRef(),
                                           getOrCreateCompileUnit(NULL), 
                                           0, 0, 0, 0, 0,
                                           llvm::DIType(), EltTypeArray);
@@ -533,28 +558,30 @@
   if (tree TyName = TYPE_NAME(type)) 
     if (TREE_CODE(TyName) == TYPE_DECL && !DECL_ORIGINAL_TYPE(TyName)) {
       expanded_location TypeNameLoc = GetNodeLocation(TyName);
-      DIType Ty = DebugFactory.CreateDerivedType(Tag, findRegion(TyName),
-                                                 GetNodeName(TyName), 
-                                                 getOrCreateCompileUnit(TypeNameLoc.file),
-                                                 TypeNameLoc.line,
-                                                 0 /*size*/,
-                                                 0 /*align*/,
-                                                 0 /*offset */, 
-                                                 0 /*flags*/, 
-                                                 FromTy);
+      DIType Ty = 
+        DebugFactory.CreateDerivedType(Tag, findRegion(DECL_CONTEXT(TyName)),
+                                       GetNodeName(TyName), 
+                                       getOrCreateCompileUnit(TypeNameLoc.file),
+                                       TypeNameLoc.line,
+                                       0 /*size*/,
+                                       0 /*align*/,
+                                       0 /*offset */, 
+                                       0 /*flags*/, 
+                                       FromTy);
       TypeCache[TyName] = WeakVH(Ty.getNode());
       return Ty;
     }
   
   StringRef PName = FromTy.getName();
-  DIType PTy = DebugFactory.CreateDerivedType(Tag, findRegion(type), PName,
-                                              getOrCreateCompileUnit(NULL), 
-                                              0 /*line no*/, 
-                                              NodeSizeInBits(type),
-                                              NodeAlignInBits(type),
-                                              0 /*offset */, 
-                                              Flags, 
-                                              FromTy);
+  DIType PTy = 
+    DebugFactory.CreateDerivedType(Tag, findRegion(TYPE_CONTEXT(type)), PName,
+                                   getOrCreateCompileUnit(NULL), 
+                                   0 /*line no*/, 
+                                   NodeSizeInBits(type),
+                                   NodeAlignInBits(type),
+                                   0 /*offset */, 
+                                   Flags, 
+                                   FromTy);
   return PTy;
 }
 
@@ -604,7 +631,8 @@
     DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size());
   expanded_location Loc = GetNodeLocation(type);
   return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type,
-                                          findRegion(type), StringRef(),
+                                          findRegion(TYPE_CONTEXT(type)), 
+                                          StringRef(),
                                           getOrCreateCompileUnit(Loc.file), 0, 
                                           NodeSizeInBits(type), 
                                           NodeAlignInBits(type), 0, 0,
@@ -635,7 +663,8 @@
     Loc = GetNodeLocation(TREE_CHAIN(type), false);
 
   return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type,
-                                          findRegion(type), GetNodeName(type), 
+                                          findRegion(TYPE_CONTEXT(type)), 
+                                          GetNodeName(type), 
                                           getOrCreateCompileUnit(Loc.file), 
                                           Loc.line,
                                           NodeSizeInBits(type), 
@@ -692,18 +721,27 @@
   StringRef TypeName = GetNodeName(type);
   if (!TypeName.empty())
     FwdName = FwdName + TypeName.data();
-  unsigned Flags = llvm::DIType::FlagFwdDecl;
+  unsigned SFlags = 0;
   if (TYPE_BLOCK_IMPL_STRUCT(type))
-    Flags |= llvm::DIType::FlagAppleBlock;
+    SFlags |= llvm::DIType::FlagAppleBlock;
   if (type_is_block_byref_struct(type))
-    Flags |= llvm::DIType::FlagBlockByrefStruct;
+    SFlags |= llvm::DIType::FlagBlockByrefStruct;
+  DIDescriptor TyContext =  findRegion(TYPE_CONTEXT(type));
+
+  // Check if this type is created while creating context information 
+  // descriptor. 
+  std::map<tree_node *, WeakVH >::iterator I = TypeCache.find(type);
+  if (I != TypeCache.end())
+    if (MDNode *TN = dyn_cast_or_null<MDNode>(I->second))
+      return DIType(TN);
+  
   llvm::DICompositeType FwdDecl =
     DebugFactory.CreateCompositeType(Tag, 
-                                     findRegion(type),
+                                     TyContext,
                                      FwdName.c_str(),
                                      getOrCreateCompileUnit(Loc.file), 
                                      Loc.line, 
-                                     0, 0, 0, Flags,
+                                     0, 0, 0, SFlags | llvm::DIType::FlagFwdDecl,
                                      llvm::DIType(), llvm::DIArray(),
                                      RunTimeLang);
   
@@ -729,24 +767,24 @@
       tree BInfo = BINFO_BASE_BINFO(binfo, i);
       tree BInfoType = BINFO_TYPE (BInfo);
       DIType BaseClass = getOrCreateType(BInfoType);
-      unsigned Flags = 0;
+      unsigned BFlags = 0;
       if (BINFO_VIRTUAL_P (BInfo))
-        Flags = llvm::DIType::FlagVirtual;
+        BFlags = llvm::DIType::FlagVirtual;
       if (accesses) {
         tree access = VEC_index (tree, accesses, i);
         if (access == access_protected_node)
-          Flags |= llvm::DIType::FlagProtected;
+          BFlags |= llvm::DIType::FlagProtected;
         else if (access == access_private_node)
-          Flags |= llvm::DIType::FlagPrivate;
+          BFlags |= llvm::DIType::FlagPrivate;
       }
 
       // FIXME : name, size, align etc...
       DIType DTy = 
         DebugFactory.CreateDerivedType(DW_TAG_inheritance, 
-                                       findRegion(type), StringRef(),
+                                       findRegion(TYPE_CONTEXT(type)), StringRef(),
                                        llvm::DICompileUnit(), 0,0,0, 
                                        getINTEGER_CSTVal(BINFO_OFFSET(BInfo))*8,
-                                       Flags, BaseClass);
+                                       BFlags, BaseClass);
       EltTys.push_back(DTy);
     }
   }
@@ -777,20 +815,21 @@
       tree FieldNodeType = FieldType(Member);
       DIType MemberType = getOrCreateType(FieldNodeType);
       StringRef MemberName = GetNodeName(Member);
-      unsigned Flags = 0;
+      unsigned MFlags = 0;
       if (TREE_PROTECTED(Member))
-        Flags = llvm::DIType::FlagProtected;
+        MFlags = llvm::DIType::FlagProtected;
       else if (TREE_PRIVATE(Member))
-        Flags = llvm::DIType::FlagPrivate;
+        MFlags = llvm::DIType::FlagPrivate;
       
       DIType DTy =
-        DebugFactory.CreateDerivedType(DW_TAG_member, findRegion(Member),
+        DebugFactory.CreateDerivedType(DW_TAG_member, 
+                                       findRegion(DECL_CONTEXT(Member)),
                                        MemberName, 
                                        getOrCreateCompileUnit(MemLoc.file),
                                        MemLoc.line, NodeSizeInBits(Member),
                                        NodeAlignInBits(FieldNodeType),
                                        int_bit_position(Member), 
-                                       Flags, MemberType);
+                                       MFlags, MemberType);
       EltTys.push_back(DTy);
     } else {
       DEBUGASSERT(0 && "Unsupported member tree code!");
@@ -822,7 +861,8 @@
         ContainingType = getOrCreateType(DECL_CONTEXT(Member));
       }
       DISubprogram SP = 
-        DebugFactory.CreateSubprogram(findRegion(Member), MemberName, MemberName,
+        DebugFactory.CreateSubprogram(findRegion(DECL_CONTEXT(Member)), 
+                                      MemberName, MemberName,
                                       LinkageName, 
                                       getOrCreateCompileUnit(MemLoc.file),
                                       MemLoc.line, SPTy, false, false,
@@ -841,14 +881,15 @@
     RegionMap.erase(RI);
 
   llvm::DICompositeType RealDecl =
-    DebugFactory.CreateCompositeType(Tag, findRegion(type),
+    DebugFactory.CreateCompositeType(Tag, findRegion(TYPE_CONTEXT(type)),
                                      GetNodeName(type),
                                      getOrCreateCompileUnit(Loc.file),
                                      Loc.line, 
                                      NodeSizeInBits(type), NodeAlignInBits(type),
-                                     0, Flags, llvm::DIType(), Elements,
+                                     0, SFlags, llvm::DIType(), Elements,
                                      RunTimeLang);
-  
+  RegionMap[type] = WeakVH(RealDecl.getNode());
+
   // 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);
@@ -867,7 +908,8 @@
 	  return DIType(cast<MDNode>(M));
     if (TREE_CODE(TyDef) == TYPE_DECL &&  DECL_ORIGINAL_TYPE(TyDef)) {
       expanded_location TypeDefLoc = GetNodeLocation(TyDef);
-      Ty = DebugFactory.CreateDerivedType(DW_TAG_typedef, findRegion(TyDef),
+      Ty = DebugFactory.CreateDerivedType(DW_TAG_typedef, 
+                                          findRegion(DECL_CONTEXT(TyDef)),
                                           GetNodeName(TyDef), 
                                           getOrCreateCompileUnit(TypeDefLoc.file),
                                           TypeDefLoc.line,
@@ -883,7 +925,8 @@
 
   if (TYPE_VOLATILE(type)) {
     Ty = DebugFactory.CreateDerivedType(DW_TAG_volatile_type, 
-                                        findRegion(type), StringRef(),
+                                        findRegion(TYPE_CONTEXT(type)), 
+                                        StringRef(),
                                         getOrCreateCompileUnit(NULL), 
                                         0 /*line no*/, 
                                         NodeSizeInBits(type),
@@ -896,7 +939,8 @@
 
   if (TYPE_READONLY(type)) 
     Ty =  DebugFactory.CreateDerivedType(DW_TAG_const_type, 
-                                         findRegion(type), StringRef(),
+                                         findRegion(TYPE_CONTEXT(type)), 
+                                         StringRef(),
                                          getOrCreateCompileUnit(NULL), 
                                          0 /*line no*/, 
                                          NodeSizeInBits(type),

Modified: llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.h?rev=92845&r1=92844&r2=92845&view=diff

==============================================================================
--- llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.h (original)
+++ llvm-gcc-4.2/branches/Apple/Zoidberg/gcc/llvm-debug.h Wed Jan  6 11:59:31 2010
@@ -68,6 +68,9 @@
   std::map<tree_node *, WeakVH > SPCache;
                                         // Cache of previously constructed 
                                         // Subprograms.
+  std::map<tree_node *, WeakVH> NameSpaceCache;
+                                        // Cache of previously constructed name 
+                                        // spaces.
   SmallVector<WeakVH, 4> RegionStack;
                                         // Stack to track declarative scopes.
   
@@ -136,6 +139,9 @@
 
   /// findRegion - Find tree_node N's region.
   DIDescriptor findRegion(tree_node *n);
+  
+  /// getOrCreateNameSpace - Get name space descriptor for the tree node.
+  DINameSpace getOrCreateNameSpace(tree_node *Node, DIDescriptor Context);
 };
 
 } // end namespace llvm





More information about the llvm-branch-commits mailing list