strength reduce MMI::MappedLabel to MMI::isLabelDeleted,
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.cpp
index 602145bbddd1d5b4ddbc335dc04a231084541703..1b17a9964fd1bb8f1339e798c197e13b96085cca 100644 (file)
@@ -10,6 +10,7 @@
 // This file contains support for writing dwarf debug info into asm files.
 //
 //===----------------------------------------------------------------------===//
+
 #define DEBUG_TYPE "dwarfdebug"
 #include "DwarfDebug.h"
 #include "llvm/Module.h"
@@ -288,7 +289,7 @@ DbgScope::~DbgScope() {
 } // end llvm namespace
 
 DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T)
-  : DwarfPrinter(OS, A, T, "dbg"), ModuleCU(0),
+  : DwarfPrinter(OS, A, T), ModuleCU(0),
     AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
     DIEValues(), StringPool(),
     SectionSourceLines(), didInitial(false), shouldEmit(false),
@@ -376,8 +377,8 @@ void DwarfDebug::addLabel(DIE *Die, unsigned Attribute, unsigned Form,
 ///
 void DwarfDebug::addSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
                                   const MCSymbol *Label,const MCSymbol *Section,
-                                  bool isEH, bool useSet) {
-  DIEValue *Value = new DIESectionOffset(Label, Section, isEH, useSet);
+                                  bool isEH) {
+  DIEValue *Value = new DIESectionOffset(Label, Section, isEH);
   DIEValues.push_back(Value);
   Die->addValue(Attribute, Form, Value);
 }
@@ -1361,9 +1362,14 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(MDNode *SPNode) {
 /// constructLexicalScope - Construct new DW_TAG_lexical_block
 /// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
 DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
-  unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
-  unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
+  unsigned StartID = Scope->getStartLabelID();
+  unsigned EndID = Scope->getEndLabelID();
 
+  assert(!MMI->isLabelDeleted(StartID) &&
+         "Invalid starting label for an inlined scope!");
+  assert(!MMI->isLabelDeleted(EndID) &&
+         "Invalid end label for an inlined scope!");
+  
   // Ignore empty scopes.
   if (StartID == EndID && StartID != 0)
     return NULL;
@@ -1386,12 +1392,14 @@ DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
 /// a function. Construct DIE to represent this concrete inlined copy
 /// of the function.
 DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
-  unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
-  unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
-  assert (StartID && "Invalid starting label for an inlined scope!");
-  assert (EndID && "Invalid end label for an inlined scope!");
+  unsigned StartID = Scope->getStartLabelID();
+  unsigned EndID = Scope->getEndLabelID();
+  assert(!MMI->isLabelDeleted(StartID) &&
+         "Invalid starting label for an inlined scope!");
+  assert(!MMI->isLabelDeleted(EndID) &&
+         "Invalid end label for an inlined scope!");
   // Ignore empty scopes.
-  if (StartID == EndID && StartID != 0)
+  if (StartID == EndID)
     return NULL;
   if (!Scope->getScopeNode())
     return NULL;
@@ -1404,8 +1412,9 @@ DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
   addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
               dwarf::DW_FORM_ref4, OriginDIE);
 
-  addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
-           getDWLabel("label", StartID));
+  MCSymbol *StartLabel = getDWLabel("label", StartID);
+  
+  addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel);
   addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
            getDWLabel("label", EndID));
 
@@ -1416,11 +1425,11 @@ DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
     I = InlineInfo.find(InlinedSP.getNode());
 
   if (I == InlineInfo.end()) {
-    InlineInfo[InlinedSP.getNode()].push_back(std::make_pair(StartID,
+    InlineInfo[InlinedSP.getNode()].push_back(std::make_pair(StartLabel,
                                                              ScopeDIE));
     InlinedSPNodes.push_back(InlinedSP.getNode());
   } else
-    I->second.push_back(std::make_pair(StartID, ScopeDIE));
+    I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
 
   StringPool.insert(InlinedSP.getName());
   StringPool.insert(getRealLinkageName(InlinedSP.getLinkageName()));
@@ -1970,7 +1979,6 @@ void DwarfDebug::endScope(const MachineInstr *MI) {
 
   unsigned Label = MMI->NextLabelID();
   Asm->printLabel(Label);
-  O << '\n';
 
   SmallVector<DbgScope *, 2> &SD = I->second;
   for (SmallVector<DbgScope *, 2>::iterator SDI = SD.begin(), SDE = SD.end();
@@ -2129,7 +2137,6 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
                                  DLT.getColumnNumber(), 
                                  DLT.getScope().getNode());
     Asm->printLabel(LabelID);
-    O << '\n';
   }
   if (TimePassesIsEnabled)
     DebugTimer->stopTimer();
@@ -2589,8 +2596,8 @@ void DwarfDebug::emitDebugLines() {
     // Construct rows of the address, source, line, column matrix.
     for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
       const SrcLineInfo &LineInfo = LineInfos[i];
-      unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
-      if (!LabelID) continue;
+      unsigned LabelID = LineInfo.getLabelID();
+      if (MMI->isLabelDeleted(LabelID)) continue;
 
       if (LineInfo.getLine() == 0) continue;
 
@@ -2672,8 +2679,8 @@ void DwarfDebug::emitCommonDebugFrame() {
                               Asm->getObjFileLowering().getDwarfFrameSection());
 
   Asm->OutStreamer.EmitLabel(getTempLabel("debug_frame_common"));
-  EmitDifference("debug_frame_common_end", 0,
-                 "debug_frame_common_begin", 0, true);
+  EmitDifference(getTempLabel("debug_frame_common_end"),
+                 getTempLabel("debug_frame_common_begin"), true);
   EOL("Length of Common Information Entry");
 
   Asm->OutStreamer.EmitLabel(getTempLabel("debug_frame_common_begin"));
@@ -2708,8 +2715,8 @@ DwarfDebug::emitFunctionDebugFrame(const FunctionDebugFrameInfo&DebugFrameInfo){
   Asm->OutStreamer.SwitchSection(
                               Asm->getObjFileLowering().getDwarfFrameSection());
 
-  EmitDifference("debug_frame_end", DebugFrameInfo.Number,
-                 "debug_frame_begin", DebugFrameInfo.Number, true);
+  EmitDifference(getDWLabel("debug_frame_end", DebugFrameInfo.Number),
+                 getDWLabel("debug_frame_begin", DebugFrameInfo.Number), true);
   EOL("Length of Frame Information Entry");
 
   Asm->OutStreamer.EmitLabel(getDWLabel("debug_frame_begin",
@@ -2740,8 +2747,8 @@ void DwarfDebug::emitDebugPubNames() {
   Asm->OutStreamer.SwitchSection(
                           Asm->getObjFileLowering().getDwarfPubNamesSection());
 
-  EmitDifference("pubnames_end", ModuleCU->getID(),
-                 "pubnames_begin", ModuleCU->getID(), true);
+  EmitDifference(getDWLabel("pubnames_end", ModuleCU->getID()),
+                 getDWLabel("pubnames_begin", ModuleCU->getID()), true);
   EOL("Length of Public Names Info");
 
   Asm->OutStreamer.EmitLabel(getDWLabel("pubnames_begin", ModuleCU->getID()));
@@ -2753,7 +2760,8 @@ void DwarfDebug::emitDebugPubNames() {
                     true, false);
   EOL("Offset of Compilation Unit Info");
 
-  EmitDifference("info_end", ModuleCU->getID(), "info_begin", ModuleCU->getID(),
+  EmitDifference(getDWLabel("info_end", ModuleCU->getID()),
+                 getDWLabel("info_begin", ModuleCU->getID()),
                  true);
   EOL("Compilation Unit Length");
 
@@ -2778,8 +2786,8 @@ void DwarfDebug::emitDebugPubTypes() {
   // Start the dwarf pubnames section.
   Asm->OutStreamer.SwitchSection(
                           Asm->getObjFileLowering().getDwarfPubTypesSection());
-  EmitDifference("pubtypes_end", ModuleCU->getID(),
-                 "pubtypes_begin", ModuleCU->getID(), true);
+  EmitDifference(getDWLabel("pubtypes_end", ModuleCU->getID()),
+                 getDWLabel("pubtypes_begin", ModuleCU->getID()), true);
   EOL("Length of Public Types Info");
 
   Asm->OutStreamer.EmitLabel(getDWLabel("pubtypes_begin", ModuleCU->getID()));
@@ -2791,7 +2799,8 @@ void DwarfDebug::emitDebugPubTypes() {
                     getTempLabel("section_info"), true, false);
   EOL("Offset of Compilation ModuleCU Info");
 
-  EmitDifference("info_end", ModuleCU->getID(), "info_begin", ModuleCU->getID(),
+  EmitDifference(getDWLabel("info_end", ModuleCU->getID()),
+                 getDWLabel("info_begin", ModuleCU->getID()),
                  true);
   EOL("Compilation ModuleCU Length");
 
@@ -2872,7 +2881,8 @@ void DwarfDebug::EmitDebugARanges() {
 
   // Range 1
   EmitReference("text_begin", 0); EOL("Address");
-  EmitDifference("text_end", 0, "text_begin", 0, true); EOL("Length");
+  EmitDifference(getTempLabel("text_end"), getTempLabel("text_begin"),
+                 true); EOL("Length");
 
   Asm->EmitInt32(0); EOL("EOM (1)");
   Asm->EmitInt32(0); EOL("EOM (2)");
@@ -2925,8 +2935,8 @@ void DwarfDebug::emitDebugInlineInfo() {
   Asm->OutStreamer.SwitchSection(
                         Asm->getObjFileLowering().getDwarfDebugInlineSection());
 
-  EmitDifference("debug_inlined_end", 1,
-                 "debug_inlined_begin", 1, true);
+  EmitDifference(getDWLabel("debug_inlined_end", 1),
+                 getDWLabel("debug_inlined_begin", 1), true);
   EOL("Length of Debug Inlined Information Entry");
 
   Asm->OutStreamer.EmitLabel(getDWLabel("debug_inlined_begin", 1));
@@ -2961,15 +2971,11 @@ void DwarfDebug::emitDebugInlineInfo() {
 
     for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(),
            LE = Labels.end(); LI != LE; ++LI) {
-      DIE *SP = LI->second;
-      Asm->EmitInt32(SP->getOffset()); EOL("DIE offset");
-
-      if (TD->getPointerSize() == sizeof(int32_t))
-        O << MAI->getData32bitsDirective();
-      else
-        O << MAI->getData64bitsDirective();
+      if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("DIE offset");
+      Asm->EmitInt32(LI->second->getOffset());
 
-      PrintLabelName("label", LI->first); EOL("low_pc");
+      if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("low_pc");
+      Asm->OutStreamer.EmitSymbolValue(LI->first, TD->getPointerSize(), 0);
     }
   }