[llvm-branch-commits] [llvm-branch] r90471 - in /llvm/branches/Apple/Zoidberg: include/llvm/Analysis/DebugInfo.h lib/Analysis/DebugInfo.cpp lib/CodeGen/AsmPrinter/DIE.h lib/CodeGen/AsmPrinter/DwarfDebug.cpp lib/CodeGen/AsmPrinter/DwarfDebug.h

Devang Patel dpatel at apple.com
Thu Dec 3 11:01:22 PST 2009


Author: dpatel
Date: Thu Dec  3 13:01:22 2009
New Revision: 90471

URL: http://llvm.org/viewvc/llvm-project?rev=90471&view=rev
Log:
Merge debug info improvements from trunk.

$ svn merge -c 90281 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r90281 into '.':
U    lib/CodeGen/AsmPrinter/DwarfDebug.cpp
rajkot:llvm yash$ ~/bin/merge.bill 90282
$ svn merge -c 90282 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r90282 into '.':
U    include/llvm/Analysis/DebugInfo.h
U    lib/Analysis/DebugInfo.cpp
rajkot:llvm yash$ ~/bin/merge.bill 90318
$ svn merge -c 90318 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r90318 into '.':
U    lib/CodeGen/AsmPrinter/DIE.h
G    lib/CodeGen/AsmPrinter/DwarfDebug.cpp
rajkot:llvm yash$ ~/bin/merge.bill 90375
$ svn merge -c 90375 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r90375 into '.':
U    lib/CodeGen/AsmPrinter/DwarfDebug.h
G    lib/CodeGen/AsmPrinter/DwarfDebug.cpp



Modified:
    llvm/branches/Apple/Zoidberg/include/llvm/Analysis/DebugInfo.h
    llvm/branches/Apple/Zoidberg/lib/Analysis/DebugInfo.cpp
    llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DIE.h
    llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.h

Modified: llvm/branches/Apple/Zoidberg/include/llvm/Analysis/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/include/llvm/Analysis/DebugInfo.h?rev=90471&r1=90470&r2=90471&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/include/llvm/Analysis/DebugInfo.h (original)
+++ llvm/branches/Apple/Zoidberg/include/llvm/Analysis/DebugInfo.h Thu Dec  3 13:01:22 2009
@@ -567,6 +567,10 @@
                                   DIType Type, bool isLocalToUnit,
                                   bool isDefinition);
 
+    /// CreateSubprogramDefinition - Create new subprogram descriptor for the
+    /// given declaration. 
+    DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
+
     /// CreateGlobalVariable - Create a new descriptor for the specified global.
     DIGlobalVariable
     CreateGlobalVariable(DIDescriptor Context, StringRef Name,

Modified: llvm/branches/Apple/Zoidberg/lib/Analysis/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/Analysis/DebugInfo.cpp?rev=90471&r1=90470&r2=90471&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/Analysis/DebugInfo.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/Analysis/DebugInfo.cpp Thu Dec  3 13:01:22 2009
@@ -884,6 +884,29 @@
   return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
 }
 
+/// CreateSubprogramDefinition - Create new subprogram descriptor for the
+/// given declaration. 
+DISubprogram DIFactory::CreateSubprogramDefinition(DISubprogram &SPDeclaration) {
+  if (SPDeclaration.isDefinition())
+    return DISubprogram(SPDeclaration.getNode());
+
+  MDNode *DeclNode = SPDeclaration.getNode();
+  Value *Elts[] = {
+    GetTagConstant(dwarf::DW_TAG_subprogram),
+    llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
+    DeclNode->getElement(2), // Context
+    DeclNode->getElement(3), // Name
+    DeclNode->getElement(4), // DisplayName
+    DeclNode->getElement(5), // LinkageName
+    DeclNode->getElement(6), // CompileUnit
+    DeclNode->getElement(7), // LineNo
+    DeclNode->getElement(8), // Type
+    DeclNode->getElement(9), // isLocalToUnit
+    ConstantInt::get(Type::getInt1Ty(VMContext), true)
+  };
+  return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
+}
+
 /// CreateGlobalVariable - Create a new descriptor for the specified global.
 DIGlobalVariable
 DIFactory::CreateGlobalVariable(DIDescriptor Context, StringRef Name,

Modified: llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DIE.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DIE.h?rev=90471&r1=90470&r2=90471&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DIE.h (original)
+++ llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DIE.h Thu Dec  3 13:01:22 2009
@@ -274,7 +274,7 @@
   };
 
   //===--------------------------------------------------------------------===//
-  /// DIEString - A string value DIE.
+  /// DIEString - A string value DIE. This DIE keeps string reference only.
   ///
   class DIEString : public DIEValue {
     const StringRef Str;

Modified: llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=90471&r1=90470&r2=90471&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Dec  3 13:01:22 2009
@@ -329,8 +329,8 @@
   Die->addValue(Attribute, Form, Value);
 }
 
-/// addString - Add a string attribute data and value.
-///
+/// addString - Add a string attribute data and value. DIEString only
+/// keeps string reference. 
 void DwarfDebug::addString(DIE *Die, unsigned Attribute, unsigned Form,
                            const StringRef String) {
   DIEValue *Value = new DIEString(String);
@@ -890,8 +890,8 @@
         continue;
       DIE *ElemDie = NULL;
       if (Element.getTag() == dwarf::DW_TAG_subprogram)
-        ElemDie = createSubprogramDIE(DW_Unit,
-                                      DISubprogram(Element.getNode()));
+        ElemDie = createMemberSubprogramDIE(DW_Unit,
+                                            DISubprogram(Element.getNode()));
       else
         ElemDie = createMemberDIE(DW_Unit,
                                   DIDerivedType(Element.getNode()));
@@ -1080,11 +1080,11 @@
   return MemberDie;
 }
 
-/// createSubprogramDIE - Create new DIE using SP.
-DIE *DwarfDebug::createSubprogramDIE(CompileUnit *DW_Unit,
-                                     const DISubprogram &SP,
-                                     bool IsConstructor,
-                                     bool IsInlined) {
+/// createRawSubprogramDIE - Create new partially incomplete DIE. This is
+/// a helper routine used by createMemberSubprogramDIE and 
+/// createSubprogramDIE.
+DIE *DwarfDebug::createRawSubprogramDIE(CompileUnit *DW_Unit,
+                                        const DISubprogram &SP) {
   DIE *SPDie = new DIE(dwarf::DW_TAG_subprogram);
   addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName());
 
@@ -1100,9 +1100,6 @@
   }
   addSourceLine(SPDie, &SP);
 
-  DICompositeType SPTy = SP.getType();
-  DIArray Args = SPTy.getTypeArray();
-
   // Add prototyped tag, if C or ObjC.
   unsigned Lang = SP.getCompileUnit().getLanguage();
   if (Lang == dwarf::DW_LANG_C99 || Lang == dwarf::DW_LANG_C89 ||
@@ -1110,19 +1107,70 @@
     addUInt(SPDie, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
 
   // Add Return Type.
+  DICompositeType SPTy = SP.getType();
+  DIArray Args = SPTy.getTypeArray();
   unsigned SPTag = SPTy.getTag();
-  if (!IsConstructor) {
-    if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
-      addType(DW_Unit, SPDie, SPTy);
-    else
-      addType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode()));
-  }
+  if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
+    addType(DW_Unit, SPDie, SPTy);
+  else
+    addType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode()));
+
+  return SPDie;
+}
+
+/// createMemberSubprogramDIE - Create new member DIE using SP. This routine
+/// always returns a die with DW_AT_declaration attribute.
+DIE *DwarfDebug::createMemberSubprogramDIE(CompileUnit *DW_Unit,
+                                           const DISubprogram &SP) {
+  DIE *SPDie = ModuleCU->getDIE(SP.getNode());
+  if (!SPDie)
+    SPDie = createSubprogramDIE(DW_Unit, SP);
+
+  // If SPDie has DW_AT_declaration then reuse it.
+  if (!SP.isDefinition())
+    return SPDie;
+
+  // Otherwise create new DIE for the declaration. First push definition
+  // DIE at the top level.
+  if (TopLevelDIEs.insert(SPDie))
+    TopLevelDIEsVector.push_back(SPDie);
+
+  SPDie = createRawSubprogramDIE(DW_Unit, SP);
+
+  // Add arguments. 
+  DICompositeType SPTy = SP.getType();
+  DIArray Args = SPTy.getTypeArray();
+  unsigned SPTag = SPTy.getTag();
+  if (SPTag == dwarf::DW_TAG_subroutine_type)
+    for (unsigned i = 1, N =  Args.getNumElements(); i < N; ++i) {
+      DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
+      addType(DW_Unit, Arg, DIType(Args.getElement(i).getNode()));
+      addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
+      SPDie->addChild(Arg);
+    }
+
+  addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
+  return SPDie;
+}
+
+/// createSubprogramDIE - Create new DIE using SP.
+DIE *DwarfDebug::createSubprogramDIE(CompileUnit *DW_Unit,
+                                     const DISubprogram &SP) {
+  DIE *SPDie = ModuleCU->getDIE(SP.getNode());
+  if (SPDie)
+    return SPDie;
+
+  SPDie = createRawSubprogramDIE(DW_Unit, SP);
 
   if (!SP.isDefinition()) {
     addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
 
     // Add arguments. Do not add arguments for subprogram definition. They will
-    // be handled through RecordVariable.
+    // be handled while processing variables.
+    DICompositeType SPTy = SP.getType();
+    DIArray Args = SPTy.getTypeArray();
+    unsigned SPTag = SPTy.getTag();
+
     if (SPTag == dwarf::DW_TAG_subroutine_type)
       for (unsigned i = 1, N =  Args.getNumElements(); i < N; ++i) {
         DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
@@ -1633,7 +1681,8 @@
   ModuleCU->insertDIE(N, VariableDie);
 
   // Add to context owner.
-  ModuleCU->getCUDie()->addChild(VariableDie);
+  if (TopLevelDIEs.insert(VariableDie))
+    TopLevelDIEsVector.push_back(VariableDie);
 
   // Expose as global. FIXME - need to check external flag.
   ModuleCU->addGlobal(DI_GV.getName(), VariableDie);
@@ -1665,7 +1714,9 @@
   ModuleCU->insertDIE(N, SubprogramDie);
 
   // Add to context owner.
-  ModuleCU->getCUDie()->addChild(SubprogramDie);
+  if (SP.getContext().getNode() == SP.getCompileUnit().getNode())
+    if (TopLevelDIEs.insert(SubprogramDie))
+      TopLevelDIEsVector.push_back(SubprogramDie);
 
   // Expose as global.
   ModuleCU->addGlobal(SP.getName(), SubprogramDie);
@@ -1766,6 +1817,11 @@
     addUInt(ISP, dwarf::DW_AT_inline, 0, dwarf::DW_INL_inlined);
   }
 
+  // Insert top level DIEs.
+  for (SmallVector<DIE *, 4>::iterator TI = TopLevelDIEsVector.begin(),
+         TE = TopLevelDIEsVector.end(); TI != TE; ++TI)
+    ModuleCU->getCUDie()->addChild(*TI);
+
   // Standard sections final addresses.
   Asm->OutStreamer.SwitchSection(Asm->getObjFileLowering().getTextSection());
   EmitLabel("text_end", 0);

Modified: llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=90471&r1=90470&r2=90471&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/branches/Apple/Zoidberg/lib/CodeGen/AsmPrinter/DwarfDebug.h Thu Dec  3 13:01:22 2009
@@ -157,6 +157,10 @@
   /// AbstractSubprogramDIEs - Collection of abstruct subprogram DIEs.
   SmallPtrSet<DIE *, 4> AbstractSubprogramDIEs;
 
+  /// TopLevelDIEs - Collection of top level DIEs. 
+  SmallPtrSet<DIE *, 4> TopLevelDIEs;
+  SmallVector<DIE *, 4> TopLevelDIEsVector;
+
   /// ScopedGVs - Tracks global variables that are not at file scope.
   /// For example void f() { static int b = 42; }
   SmallVector<WeakVH, 4> ScopedGVs;
@@ -342,10 +346,17 @@
   DIE *createMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT);
 
   /// createSubprogramDIE - Create new DIE using SP.
-  DIE *createSubprogramDIE(CompileUnit *DW_Unit,
-                           const DISubprogram &SP,
-                           bool IsConstructor = false,
-                           bool IsInlined = false);
+  DIE *createSubprogramDIE(CompileUnit *DW_Unit, const DISubprogram &SP);
+
+  /// createMemberSubprogramDIE - Create new member DIE using SP. This
+  /// routine always returns a die with DW_AT_declaration attribute.
+
+  DIE *createMemberSubprogramDIE(CompileUnit *DW_Unit, const DISubprogram &SP);
+
+  /// createRawSubprogramDIE - Create new partially incomplete DIE. This is
+  /// a helper routine used by createMemberSubprogramDIE and 
+  /// createSubprogramDIE.
+  DIE *createRawSubprogramDIE(CompileUnit *DW_Unit, const DISubprogram &SP);
 
   /// findCompileUnit - Get the compile unit for the given descriptor. 
   ///





More information about the llvm-branch-commits mailing list