[llvm-commits] [llvm] r74449 - /llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Devang Patel dpatel at apple.com
Mon Jun 29 13:38:14 PDT 2009


Author: dpatel
Date: Mon Jun 29 15:38:13 2009
New Revision: 74449

URL: http://llvm.org/viewvc/llvm-project?rev=74449&view=rev
Log:
Multiple DW_TAG_compile_unit is not used, afaict, on any target.

Update dwarf writer to only emit one DW_TAG_compile_unit per .o file. 

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=74449&r1=74448&r2=74449&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Jun 29 15:38:13 2009
@@ -1093,13 +1093,8 @@
   // Get the subprogram debug information entry.
   DISubprogram SPD(Desc.getGV());
 
-  // Get the compile unit context.
-  CompileUnit *Unit = MainCU;
-  if (!Unit)
-    Unit = &FindCompileUnit(SPD.getCompileUnit());
-
   // Get the subprogram die.
-  DIE *SPDie = Unit->getDieMapSlotFor(SPD.getGV());
+  DIE *SPDie = MainCU->getDieMapSlotFor(SPD.getGV());
   assert(SPDie && "Missing subprogram descriptor");
 
   if (!AbstractScope) {
@@ -1112,55 +1107,27 @@
     AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
   }
 
-  ConstructDbgScope(RootScope, 0, 0, SPDie, Unit);
+  ConstructDbgScope(RootScope, 0, 0, SPDie, MainCU);
 }
 
 /// ConstructDefaultDbgScope - Construct a default scope for the subprogram.
 ///
 void DwarfDebug::ConstructDefaultDbgScope(MachineFunction *MF) {
   const char *FnName = MF->getFunction()->getNameStart();
-  if (MainCU) {
-    StringMap<DIE*> &Globals = MainCU->getGlobals();
-    StringMap<DIE*>::iterator GI = Globals.find(FnName);
-    if (GI != Globals.end()) {
-      DIE *SPDie = GI->second;
-
-      // Add the function bounds.
-      AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-               DWLabel("func_begin", SubprogramCount));
-      AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
-               DWLabel("func_end", SubprogramCount));
-
-      MachineLocation Location(RI->getFrameRegister(*MF));
-      AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
-      return;
-    }
-  } else {
-    for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i) {
-      CompileUnit *Unit = CompileUnits[i];
-      StringMap<DIE*> &Globals = Unit->getGlobals();
-      StringMap<DIE*>::iterator GI = Globals.find(FnName);
-      if (GI != Globals.end()) {
-        DIE *SPDie = GI->second;
-
-        // Add the function bounds.
-        AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-                 DWLabel("func_begin", SubprogramCount));
-        AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
-                 DWLabel("func_end", SubprogramCount));
-
-        MachineLocation Location(RI->getFrameRegister(*MF));
-        AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
-        return;
-      }
-    }
+  StringMap<DIE*> &Globals = MainCU->getGlobals();
+  StringMap<DIE*>::iterator GI = Globals.find(FnName);
+  if (GI != Globals.end()) {
+    DIE *SPDie = GI->second;
+    
+    // Add the function bounds.
+    AddLabel(SPDie, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
+             DWLabel("func_begin", SubprogramCount));
+    AddLabel(SPDie, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
+             DWLabel("func_end", SubprogramCount));
+    
+    MachineLocation Location(RI->getFrameRegister(*MF));
+    AddAddress(SPDie, dwarf::DW_AT_frame_base, Location);
   }
-
-#if 0
-  // FIXME: This is causing an abort because C++ mangled names are compared with
-  // their unmangled counterparts. See PR2885. Don't do this assert.
-  assert(0 && "Couldn't find DIE for machine function!");
-#endif
 }
 
 /// GetOrCreateSourceID - Look up the source id with the given directory and
@@ -1233,10 +1200,11 @@
             dwarf::DW_FORM_data1, RVer);
 
   CompileUnit *Unit = new CompileUnit(ID, Die);
-  if (DIUnit.isMain()) {
-    assert(!MainCU && "Multiple main compile units are found!");
+  if (!MainCU && DIUnit.isMain()) {
+    // Use first compile unit marked as isMain as the compile unit
+    // for this module.
     MainCU = Unit;
-    }
+  }
 
   CompileUnitMap[DIUnit.getGV()] = Unit;
   CompileUnits.push_back(Unit);
@@ -1244,16 +1212,13 @@
 
 void DwarfDebug::ConstructGlobalVariableDIE(GlobalVariable *GV) {
   DIGlobalVariable DI_GV(GV);
-  CompileUnit *DW_Unit = MainCU;
-  if (!DW_Unit)
-    DW_Unit = &FindCompileUnit(DI_GV.getCompileUnit());
 
   // Check for pre-existence.
-  DIE *&Slot = DW_Unit->getDieMapSlotFor(DI_GV.getGV());
+  DIE *&Slot = MainCU->getDieMapSlotFor(DI_GV.getGV());
   if (Slot)
     return;
 
-  DIE *VariableDie = CreateGlobalVariableDIE(DW_Unit, DI_GV);
+  DIE *VariableDie = CreateGlobalVariableDIE(MainCU, DI_GV);
 
   // Add address.
   DIEBlock *Block = new DIEBlock();
@@ -1267,22 +1232,19 @@
   Slot = VariableDie;
 
   // Add to context owner.
-  DW_Unit->getDie()->AddChild(VariableDie);
+  MainCU->getDie()->AddChild(VariableDie);
 
   // Expose as global. FIXME - need to check external flag.
   std::string Name;
-  DW_Unit->AddGlobal(DI_GV.getName(Name), VariableDie);
+  MainCU->AddGlobal(DI_GV.getName(Name), VariableDie);
   return;
 }
 
 void DwarfDebug::ConstructSubprogram(GlobalVariable *GV) {
   DISubprogram SP(GV);
-  CompileUnit *Unit = MainCU;
-  if (!Unit)
-    Unit = &FindCompileUnit(SP.getCompileUnit());
 
   // Check for pre-existence.
-  DIE *&Slot = Unit->getDieMapSlotFor(GV);
+  DIE *&Slot = MainCU->getDieMapSlotFor(GV);
   if (Slot)
     return;
 
@@ -1291,17 +1253,17 @@
     // class type.
     return;
 
-  DIE *SubprogramDie = CreateSubprogramDIE(Unit, SP);
+  DIE *SubprogramDie = CreateSubprogramDIE(MainCU, SP);
 
   // Add to map.
   Slot = SubprogramDie;
 
   // Add to context owner.
-  Unit->getDie()->AddChild(SubprogramDie);
+  MainCU->getDie()->AddChild(SubprogramDie);
 
   // Expose as global.
   std::string Name;
-  Unit->AddGlobal(SP.getName(Name), SubprogramDie);
+  MainCU->AddGlobal(SP.getName(Name), SubprogramDie);
   return;
 }
 
@@ -1331,6 +1293,11 @@
     return;
   }
 
+  // If main compile unit for this module is not seen than randomly
+  // select first compile unit.
+  if (!MainCU)
+    MainCU = CompileUnits[0];
+
   // If there is not any debug info available for any global variables and any
   // subprograms then there is not any debug info to emit.
   if (GVs.empty() && SPs.empty()) {
@@ -1707,9 +1674,6 @@
   if (TimePassesIsEnabled)
     DebugTimer->startTimer();
 
-  CompileUnit *Unit = MainCU;
-  if (!Unit)
-    Unit = &FindCompileUnit(SP.getCompileUnit());
   GlobalVariable *GV = SP.getGV();
   DenseMap<const GlobalVariable *, DbgScope *>::iterator
     II = AbstractInstanceRootMap.find(GV);
@@ -1720,9 +1684,9 @@
     DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
 
     // Get the compile unit context.
-    DIE *SPDie = Unit->getDieMapSlotFor(GV);
+    DIE *SPDie = MainCU->getDieMapSlotFor(GV);
     if (!SPDie)
-      SPDie = CreateSubprogramDIE(Unit, SP, false, true);
+      SPDie = CreateSubprogramDIE(MainCU, SP, false, true);
 
     // Mark as being inlined. This makes this subprogram entry an abstract
     // instance root.
@@ -1741,12 +1705,12 @@
   // Create a concrete inlined instance for this inlined function.
   DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
   DIE *ScopeDie = new DIE(dwarf::DW_TAG_inlined_subroutine);
-  ScopeDie->setAbstractCompileUnit(Unit);
+  ScopeDie->setAbstractCompileUnit(MainCU);
 
-  DIE *Origin = Unit->getDieMapSlotFor(GV);
+  DIE *Origin = MainCU->getDieMapSlotFor(GV);
   AddDIEEntry(ScopeDie, dwarf::DW_AT_abstract_origin,
               dwarf::DW_FORM_ref4, Origin);
-  AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, Unit->getID());
+  AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, MainCU->getID());
   AddUInt(ScopeDie, dwarf::DW_AT_call_line, 0, Line);
   AddUInt(ScopeDie, dwarf::DW_AT_call_column, 0, Col);
 
@@ -1907,22 +1871,8 @@
     sizeof(int32_t) + // Offset Into Abbrev. Section
     sizeof(int8_t);   // Pointer Size (in bytes)
 
-  // Process base compile unit.
-  if (MainCU) {
-    SizeAndOffsetDie(MainCU->getDie(), Offset, true);
-    CompileUnitOffsets[MainCU] = 0;
-    return;
-  }
-
-  // Process all compile units.
-  unsigned PrevOffset = 0;
-
-  for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i) {
-    CompileUnit *Unit = CompileUnits[i];
-    CompileUnitOffsets[Unit] = PrevOffset;
-    PrevOffset += SizeAndOffsetDie(Unit->getDie(), Offset, true)
-      + sizeof(int32_t);  // FIXME - extra pad for gdb bug.
-  }
+  SizeAndOffsetDie(MainCU->getDie(), Offset, true);
+  CompileUnitOffsets[MainCU] = 0;
 }
 
 /// EmitInitial - Emit initial Dwarf declarations.  This is necessary for cc
@@ -2067,13 +2017,7 @@
   // Start debug info section.
   Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
 
-  if (MainCU) {
-    EmitDebugInfoPerCU(MainCU);
-    return;
-  }
-
-  for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i)
-    EmitDebugInfoPerCU(CompileUnits[i]);
+  EmitDebugInfoPerCU(MainCU);
 }
 
 /// EmitAbbreviations - Emit the abbreviation section.
@@ -2405,13 +2349,7 @@
   // Start the dwarf pubnames section.
   Asm->SwitchToDataSection(TAI->getDwarfPubNamesSection());
 
-  if (MainCU) {
-    EmitDebugPubNamesPerCU(MainCU);
-    return;
-  }
-
-  for (unsigned i = 0, e = CompileUnits.size(); i != e; ++i)
-    EmitDebugPubNamesPerCU(CompileUnits[i]);
+  EmitDebugPubNamesPerCU(MainCU);
 }
 
 /// EmitDebugStr - Emit visible names into a debug str section.





More information about the llvm-commits mailing list