DebugInfo: Avoid creating unnecessary/empty line tables and remove the special case...
authorDavid Blaikie <dblaikie@gmail.com>
Tue, 1 Apr 2014 08:07:52 +0000 (08:07 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Tue, 1 Apr 2014 08:07:52 +0000 (08:07 +0000)
This moves one case of raw text checking down into the MCStreamer
interfaces in the form of a virtual function, even if we ultimately end
up consolidating on the one-or-many line tables issue one day, this is
nicer in the interim. This just generally streamlines a bunch of use
cases into a common code path.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205287 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
include/llvm/MC/MCStreamer.h
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
lib/MC/MCAsmStreamer.cpp
lib/MC/MCDwarf.cpp
lib/MC/MCStreamer.cpp
test/CodeGen/ARM/2011-01-19-MergedGlobalDbg.ll
test/CodeGen/ARM/2011-08-02-MergedGlobalDbg.ll
test/DebugInfo/X86/stmt-list-multiple-compile-units.ll
test/DebugInfo/X86/stmt-list.ll
test/MC/ELF/gen-dwarf.s

index b276b1f83e84f3b52c6141c7aa8be2ec63401ac1..9091ed93e58df8f0d18047d704f95951eadf4d75 100644 (file)
@@ -345,12 +345,6 @@ namespace llvm {
     void setDwarfCompileUnitID(unsigned CUIndex) {
       DwarfCompileUnitID = CUIndex;
     }
-    MCSymbol *getMCLineTableSymbol(unsigned ID) const {
-      return getMCDwarfLineTable(ID).getLabel();
-    }
-    void setMCLineTableSymbol(MCSymbol *Sym, unsigned ID) {
-      getMCDwarfLineTable(ID).setLabel(Sym);
-    }
     void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
       getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
     }
index 33437bda80ecf8207f802891ca1acd1e7cf56b07..8ee60c18513580ae2a0f76716a679c51274f0c19 100644 (file)
@@ -658,6 +658,8 @@ public:
   virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
                                          const MCSymbol *Label) {}
 
+  virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
+
   void EmitDwarfSetLineAddr(int64_t LineDelta, const MCSymbol *Label,
                             int PointerSize);
 
index eaf0a17f052629bda841f97f724e1f77ccd7fe95..dc3917b585754b41753bb12065ed5fe2d99b2839 100644 (file)
@@ -2070,13 +2070,7 @@ void DwarfUnit::addRange(RangeSpan Range) {
 void DwarfCompileUnit::initStmtList(MCSymbol *DwarfLineSectionSym) {
   // Define start line table label for each Compile Unit.
   MCSymbol *LineTableStartSym =
-      Asm->GetTempSymbol("line_table_start", getUniqueID());
-  Asm->OutStreamer.getContext().setMCLineTableSymbol(LineTableStartSym,
-                                                     getUniqueID());
-
-  // Use a single line table if we are generating assembly.
-  bool UseTheFirstCU =
-      Asm->OutStreamer.hasRawTextSupport() || (getUniqueID() == 0);
+      Asm->OutStreamer.getDwarfLineTableSymbol(getUniqueID());
 
   stmtListIndex = UnitDie->getValues().size();
 
@@ -2086,10 +2080,7 @@ void DwarfCompileUnit::initStmtList(MCSymbol *DwarfLineSectionSym) {
   // The line table entries are not always emitted in assembly, so it
   // is not okay to use line_table_start here.
   if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
-    addSectionLabel(UnitDie.get(), dwarf::DW_AT_stmt_list,
-                    UseTheFirstCU ? DwarfLineSectionSym : LineTableStartSym);
-  else if (UseTheFirstCU)
-    addSectionOffset(UnitDie.get(), dwarf::DW_AT_stmt_list, 0);
+    addSectionLabel(UnitDie.get(), dwarf::DW_AT_stmt_list, LineTableStartSym);
   else
     addSectionDelta(UnitDie.get(), dwarf::DW_AT_stmt_list, LineTableStartSym,
                     DwarfLineSectionSym);
index fa54c1a8da1964c20d81a70f5939f445b595d797..884ccf9299a133adbebb43f2ebd8b2085fd5335e 100644 (file)
@@ -207,6 +207,7 @@ public:
                              unsigned Column, unsigned Flags,
                              unsigned Isa, unsigned Discriminator,
                              StringRef FileName) override;
+  MCSymbol *getDwarfLineTableSymbol(unsigned CUID) override;
 
   void EmitIdent(StringRef IdentString) override;
   void EmitCFISections(bool EH, bool Debug) override;
@@ -957,6 +958,12 @@ void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
   EmitEOL();
 }
 
+MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(unsigned CUID) {
+  // Always use the zeroth line table, since asm syntax only supports one line
+  // table for now.
+  return MCStreamer::getDwarfLineTableSymbol(0);
+}
+
 void MCAsmStreamer::EmitIdent(StringRef IdentString) {
   assert(MAI->hasIdentDirective() && ".ident directive not supported");
   OS << "\t.ident\t";
@@ -1442,8 +1449,7 @@ void MCAsmStreamer::FinishImpl() {
   // directly, the label is the only work required here.
   auto &Tables = getContext().getMCDwarfLineTables();
   if (!Tables.empty()) {
-    // FIXME: assert Tables.size() == 1 here, except that's not currently true
-    // due to DwarfUnit.cpp:2074.
+    assert(Tables.size() == 1 && "asm output only supports one line table");
     if (auto *Label = Tables.begin()->second.getLabel()) {
       SwitchSection(getContext().getObjectFileInfo()->getDwarfLineSection());
       EmitLabel(Label);
index 231948eaff5626b62886a2e5902b40e57bb89d80..72836ff32ecef6a0a619e63d8a8431bce19f90a7 100644 (file)
@@ -788,10 +788,8 @@ void MCGenDwarfInfo::Emit(MCStreamer *MCOS) {
   bool CreateDwarfSectionSymbols =
       AsmInfo->doesDwarfUseRelocationsAcrossSections();
   MCSymbol *LineSectionSymbol = nullptr;
-  if (CreateDwarfSectionSymbols) {
-    LineSectionSymbol = context.CreateTempSymbol();
-    context.setMCLineTableSymbol(LineSectionSymbol, 0);
-  }
+  if (CreateDwarfSectionSymbols)
+    LineSectionSymbol = MCOS->getDwarfLineTableSymbol(0);
   MCSymbol *AbbrevSectionSymbol = NULL;
   MCSymbol *InfoSectionSymbol = NULL;
   MCOS->SwitchSection(context.getObjectFileInfo()->getDwarfInfoSection());
index 0558a58abfd129904005ff5b2d782d7e9de245e7..8fa55aa59e2d807dc178ed0eb09e8e8fbbe633f2 100644 (file)
@@ -191,6 +191,16 @@ void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
                                   Discriminator);
 }
 
+MCSymbol *MCStreamer::getDwarfLineTableSymbol(unsigned CUID) {
+  MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
+  if (!Table.getLabel()) {
+    StringRef Prefix = Context.getAsmInfo()->getPrivateGlobalPrefix();
+    Table.setLabel(
+        Context.GetOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID)));
+  }
+  return Table.getLabel();
+}
+
 MCDwarfFrameInfo *MCStreamer::getCurrentFrameInfo() {
   if (FrameInfos.empty())
     return 0;
index 93f9bffe8617dbdc4fc558e8f2b73217c4f2cb82..b1d59aa0fde82d0735af77e248434d77a82e6561 100644 (file)
@@ -17,7 +17,7 @@ target triple = "thumbv7-apple-darwin10"
 ; DW_OP_constu
 ; offset
 
-;CHECK: .long Lset6
+;CHECK: .long Lset7
 ;CHECK-NEXT:        @ DW_AT_type
 ;CHECK-NEXT:        @ DW_AT_decl_file
 ;CHECK-NEXT:        @ DW_AT_decl_line
index 0100f2af4f10367cbc4f02b546b7e89feb386a6a..ed2840bbff596a7e7a1e38cb04be64089fe234ed 100644 (file)
@@ -8,7 +8,7 @@
 ; DW_OP_constu
 ; offset
 
-;CHECK: .long Lset8
+;CHECK: .long Lset9
 ;CHECK-NEXT:        @ DW_AT_type
 ;CHECK-NEXT:        @ DW_AT_decl_file
 ;CHECK-NEXT:        @ DW_AT_decl_line
index 344d063266b6c22cfc97bc1cc157bbd8bca08a42..8816fe77cf011b30257cf68846127e6faba09aca 100644 (file)
 
 ; PR15408
 ; ASM: L__DWARF__debug_info_begin0:
-; ASM: .long   0                       ## DW_AT_stmt_list
+; ASM: Lset3 = Lline_table_start0-Lsection_line ## DW_AT_stmt_list
+; ASM-NEXT: .long   Lset3
 ; ASM: L__DWARF__debug_info_begin1:
-; ASM: .long   0                       ## DW_AT_stmt_list
+; ASM: Lset13 = Lline_table_start0-Lsection_line ## DW_AT_stmt_list
+; ASM-NEXT: .long   Lset13
 define i32 @test(i32 %a) nounwind uwtable ssp {
 entry:
   %a.addr = alloca i32, align 4
index 6f846c1589a317c5e117b6b2ce1396812c2ca05b..99bd0fc1b580c937999cb087066a6a0a535d9189 100644 (file)
@@ -3,7 +3,7 @@
 ; CHECK:      .section        .debug_line,"",@progbits
 ; CHECK-NEXT: .Lsection_line:
 
-; CHECK:      .long   .Lsection_line          # DW_AT_stmt_list
+; CHECK:      .long   .Lline_table_start0          # DW_AT_stmt_list
 
 define void @f() {
 entry:
index e83b14c4e388917a03cb277ec927f5be81757f7c..946119bb2483de1df7478ebac645e4a6ded95d64 100644 (file)
@@ -39,7 +39,7 @@ foo:
 // ASM-NEXT: .long [[ABBREV_LABEL]]
 // First .byte 1 is the abbreviation number for the compile_unit abbrev
 // ASM: .byte 1
-// ASM-NEXT: .long [[LINE_LABEL:.Ltmp[0-9]+]]
+// ASM-NEXT: .long [[LINE_LABEL:.L[a-z0-9]+]]
 
 // ASM: .section .debug_line
 // ASM-NEXT: [[LINE_LABEL]]