[llvm-commits] [llvm] r144304 - in /llvm/trunk/lib/CodeGen/AsmPrinter: DwarfAccelTable.cpp DwarfCompileUnit.h DwarfDebug.cpp

Eric Christopher echristo at apple.com
Thu Nov 10 11:25:34 PST 2011


Author: echristo
Date: Thu Nov 10 13:25:34 2011
New Revision: 144304

URL: http://llvm.org/viewvc/llvm-project?rev=144304&view=rev
Log:
Rework adding function names to the dwarf accelerator tables, allow
multiple dies per function and support C++ basenames.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp?rev=144304&r1=144303&r2=144304&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp Thu Nov 10 13:25:34 2011
@@ -75,9 +75,15 @@
 
 void DwarfAccelTable::FinalizeTable(AsmPrinter *Asm, const char *Prefix) {
   // Create the individual hash data outputs.
-  for (StringMap<DIEArray>::const_iterator
+  for (StringMap<DIEArray>::iterator
          EI = Entries.begin(), EE = Entries.end(); EI != EE; ++EI) {
     struct HashData *Entry = new HashData((*EI).getKeyData());
+
+    // Unique the entries.
+    std::sort((*EI).second.begin(), (*EI).second.end());
+    (*EI).second.erase(std::unique((*EI).second.begin(), (*EI).second.end()),
+                       (*EI).second.end());
+
     for (DIEArray::const_iterator DI = (*EI).second.begin(),
            DE = (*EI).second.end();
          DI != DE; ++DI)

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=144304&r1=144303&r2=144304&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h Thu Nov 10 13:25:34 2011
@@ -62,7 +62,7 @@
 
   /// AccelNames - A map of names for the name accelerator table.
   ///
-  StringMap<DIE*> AccelNames;
+  StringMap<std::vector<DIE*> > AccelNames;
   StringMap<std::vector<DIE*> > AccelObjC;
   StringMap<DIE*> AccelNamespace;
   StringMap<DIE*> AccelTypes;
@@ -84,7 +84,9 @@
   DIE* getCUDie()                   const { return CUDie.get(); }
   const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
 
-  const StringMap<DIE*> &getAccelNames() const { return AccelNames; }
+  const StringMap<std::vector<DIE*> > &getAccelNames() const {
+    return AccelNames;
+  }
   const StringMap<std::vector<DIE*> > &getAccelObjC() const {
     return AccelObjC;
   }
@@ -101,7 +103,10 @@
 
 
   /// addAccelName - Add a new name to the name accelerator table.
-  void addAccelName(StringRef Name, DIE *Die) { AccelNames[Name] = Die; }
+  void addAccelName(StringRef Name, DIE *Die) {
+    std::vector<DIE*> &DIEs = AccelNames[Name];
+    DIEs.push_back(Die);
+  }
   void addAccelObjC(StringRef Name, DIE *Die) {
     std::vector<DIE*> &DIEs = AccelObjC[Name];
     DIEs.push_back(Die);

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=144304&r1=144303&r2=144304&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Nov 10 13:25:34 2011
@@ -198,6 +198,63 @@
   return LinkageName;
 }
 
+static bool isObjCClass(StringRef Name) {
+  return Name.startswith("+") || Name.startswith("-");
+}
+
+static bool hasObjCCategory(StringRef Name) {
+  if (!isObjCClass(Name)) return false;
+
+  size_t pos = Name.find(')');
+  if (pos != std::string::npos) {
+    if (Name[pos+1] != ' ') return false;
+    return true;
+  }
+  return false;
+}
+
+static void getObjCClassCategory(StringRef In, StringRef &Class,
+                                 StringRef &Category) {
+  if (!hasObjCCategory(In)) {
+    Class = In.slice(In.find('[') + 1, In.find(' '));
+    Category = "";
+    return;
+  }
+
+  Class = In.slice(In.find('[') + 1, In.find('('));
+  Category = In.slice(In.find('[') + 1, In.find(' '));
+  return;
+}
+
+static StringRef getObjCMethodName(StringRef In) {
+  return In.slice(In.find(' ') + 1, In.find(']'));
+}
+
+// Add the various names to the Dwarf accelerator table names.
+static void addSubprogramNames(CompileUnit *TheCU, DISubprogram SP,
+                               DIE* Die) {
+  if (!SP.isDefinition()) return;
+  
+  TheCU->addAccelName(SP.getName(), Die);
+
+  // If the linkage name is different than the name, go ahead and output
+  // that as well into the name table.
+  if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName())
+    TheCU->addAccelName(SP.getLinkageName(), Die);
+
+  // If this is an Objective-C selector name add it to the ObjC accelerator
+  // too.
+  if (isObjCClass(SP.getName())) {
+    StringRef Class, Category;
+    getObjCClassCategory(SP.getName(), Class, Category);
+    TheCU->addAccelObjC(Class, Die);
+    if (Category != "")
+      TheCU->addAccelObjC(Category, Die);
+    // Also add the base method name to the name table.
+    TheCU->addAccelName(getObjCMethodName(SP.getName()), Die);
+  }
+}
+
 /// updateSubprogramScopeDIE - Find DIE for the given subprogram and
 /// attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes.
 /// If there are global variables in this scope then create and insert
@@ -257,6 +314,10 @@
   MachineLocation Location(RI->getFrameRegister(*Asm->MF));
   SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
 
+  // Add name to the name table, we do this here because we're guaranteed
+  // to have concrete versions of our DW_TAG_subprogram nodes.
+  addSubprogramNames(SPCU, SP, SPDie);
+  
   return SPDie;
 }
 
@@ -384,6 +445,8 @@
   return ScopeDIE;
 }
 
+
+
 /// constructScopeDIE - Construct a DIE for this scope.
 DIE *DwarfDebug::constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope) {
   if (!Scope || !Scope->getScopeNode())
@@ -439,19 +502,9 @@
     ScopeDIE->addChild(*I);
 
   if (DS.isSubprogram())
-   TheCU->addPubTypes(DISubprogram(DS));
-
-  if (DS.isSubprogram() && !Scope->isAbstractScope()) {
-    DISubprogram SP = DISubprogram(DS);
-    TheCU->addAccelName(SP.getName(), ScopeDIE);
+    TheCU->addPubTypes(DISubprogram(DS));
 
-    // If the linkage name is different than the name, go ahead and output
-    // that as well into the name table.
-    if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName())
-      TheCU->addAccelName(SP.getLinkageName(), ScopeDIE);
-  }
-
- return ScopeDIE;
+  return ScopeDIE;
 }
 
 /// GetOrCreateSourceID - Look up the source id with the given directory and
@@ -531,38 +584,6 @@
   return NewCU;
 }
 
-static bool isObjCClass(StringRef Name) {
-  return Name.startswith("+") || Name.startswith("-");
-}
-
-static bool hasObjCCategory(StringRef Name) {
-  if (!isObjCClass(Name)) return false;
-
-  size_t pos = Name.find(')');
-  if (pos != std::string::npos) {
-    if (Name[pos+1] != ' ') return false;
-    return true;
-  }
-  return false;
-}
-
-static void getObjCClassCategory(StringRef In, StringRef &Class,
-                                 StringRef &Category) {
-  if (!hasObjCCategory(In)) {
-    Class = In.slice(In.find('[') + 1, In.find(' '));
-    Category = "";
-    return;
-  }
-
-  Class = In.slice(In.find('[') + 1, In.find('('));
-  Category = In.slice(In.find('[') + 1, In.find(' '));
-  return;
-}
-
-static StringRef getObjCMethodName(StringRef In) {
-  return In.slice(In.find(' ') + 1, In.find(']'));
-}
-
 /// construct SubprogramDIE - Construct subprogram DIE.
 void DwarfDebug::constructSubprogramDIE(CompileUnit *TheCU, 
                                         const MDNode *N) {
@@ -597,25 +618,6 @@
   // Add to context owner.
   TheCU->addToContextOwner(SubprogramDie, SP.getContext());
 
-  // Add to Accel Names
-  TheCU->addAccelName(SP.getName(), SubprogramDie);
-
-  // If the linkage name is different than the name, go ahead and output
-  // that as well into the name table.
-  if (SP.getLinkageName() != "" && SP.getName() != SP.getLinkageName())
-    TheCU->addAccelName(SP.getLinkageName(), SubprogramDie);
-
-  // If this is an Objective-C selector name add it to the ObjC accelerator too.
-  if (isObjCClass(SP.getName())) {
-    StringRef Class, Category;
-    getObjCClassCategory(SP.getName(), Class, Category);
-    TheCU->addAccelObjC(Class, SubprogramDie);
-    if (Category != "")
-      TheCU->addAccelObjC(Category, SubprogramDie);
-    // Also add the base method name to the name table.
-    TheCU->addAccelName(getObjCMethodName(SP.getName()), SubprogramDie);
-  }
-  
   return;
 }
 
@@ -1763,12 +1765,14 @@
   for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
          E = CUMap.end(); I != E; ++I) {
     CompileUnit *TheCU = I->second;
-    const StringMap<DIE*> &Names = TheCU->getAccelNames();
-    for (StringMap<DIE*>::const_iterator
+    const StringMap<std::vector<DIE*> > &Names = TheCU->getAccelNames();
+    for (StringMap<std::vector<DIE*> >::const_iterator
            GI = Names.begin(), GE = Names.end(); GI != GE; ++GI) {
       const char *Name = GI->getKeyData();
-      DIE *Entity = GI->second;
-      AT.AddName(Name, Entity);
+      std::vector<DIE *> Entities = GI->second;
+      for (std::vector<DIE *>::const_iterator DI = Entities.begin(),
+             DE = Entities.end(); DI != DE; ++DI)
+        AT.AddName(Name, (*DI));
     }
   }
 





More information about the llvm-commits mailing list