From c5b39af3291d81a41fc0b1bf65045170684f8194 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 18 Mar 2014 02:13:23 +0000 Subject: [PATCH] DebugInfo: Avoid emitting standard opcode lengths in debug_line.dwo headers where opcodes are never used anyway Introduce a slightly tighter wrapper around the header structure that handles this use case. (MCDwarfDwoLineTable) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204101 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCDwarf.h | 12 +++++++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 2 +- lib/CodeGen/AsmPrinter/DwarfDebug.h | 2 +- lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 2 +- lib/CodeGen/AsmPrinter/DwarfUnit.h | 4 +-- lib/MC/MCDwarf.cpp | 42 +++++++++++++++++-------- test/DebugInfo/X86/generate-odr-hash.ll | 2 ++ 7 files changed, 48 insertions(+), 18 deletions(-) diff --git a/include/llvm/MC/MCDwarf.h b/include/llvm/MC/MCDwarf.h index a578cb24dbd..508c8305bc0 100644 --- a/include/llvm/MC/MCDwarf.h +++ b/include/llvm/MC/MCDwarf.h @@ -15,6 +15,7 @@ #ifndef LLVM_MC_MCDWARF_H #define LLVM_MC_MCDWARF_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/MapVector.h" @@ -187,6 +188,17 @@ struct MCDwarfLineTableHeader { unsigned getFile(StringRef &Directory, StringRef &FileName, unsigned FileNumber = 0); std::pair Emit(MCStreamer *MCOS) const; + std::pair + Emit(MCStreamer *MCOS, ArrayRef SpecialOpcodeLengths) const; +}; + +class MCDwarfDwoLineTable { + MCDwarfLineTableHeader Header; +public: + unsigned getFile(StringRef Directory, StringRef FileName) { + return Header.getFile(Directory, FileName); + } + void Emit(MCStreamer &MCOS) const; }; class MCDwarfLineTable { diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index ab03753227d..8123834741a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2684,7 +2684,7 @@ void DwarfDebug::emitDebugLineDWO() { assert(useSplitDwarf() && "No split dwarf?"); Asm->OutStreamer.SwitchSection( Asm->getObjFileLowering().getDwarfLineDWOSection()); - Asm->OutStreamer.EmitLabel(SplitTypeUnitFileTable.Emit(&Asm->OutStreamer).second); + SplitTypeUnitFileTable.Emit(Asm->OutStreamer); } // Emit the .debug_str.dwo section for separated dwarf. This contains the diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 4756509d094..ba448ec9b29 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -489,7 +489,7 @@ class DwarfDebug : public AsmPrinterHandler { // Store file names for type units under fission in a line table header that // will be emitted into debug_line.dwo. - MCDwarfLineTableHeader SplitTypeUnitFileTable; + MCDwarfDwoLineTable SplitTypeUnitFileTable; void addScopeVariable(LexicalScope *LS, DbgVariable *Var); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 2a74d0552fe..2eda435f86e 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -57,7 +57,7 @@ DwarfCompileUnit::DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, DwarfTypeUnit::DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, - MCDwarfLineTableHeader *SplitLineTable) + MCDwarfDwoLineTable *SplitLineTable) : DwarfUnit(UID, D, CU.getCUNode(), A, DW, DWU), CU(CU), SplitLineTable(SplitLineTable) { if (SplitLineTable) diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 68954dc5548..a1c1fcc87a2 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -616,12 +616,12 @@ private: uint64_t TypeSignature; const DIE *Ty; DwarfCompileUnit &CU; - MCDwarfLineTableHeader *SplitLineTable; + MCDwarfDwoLineTable *SplitLineTable; public: DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, - MCDwarfLineTableHeader *SplitLineTable = nullptr); + MCDwarfDwoLineTable *SplitLineTable = nullptr); void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; } uint64_t getTypeSignature() const { return TypeSignature; } diff --git a/lib/MC/MCDwarf.cpp b/lib/MC/MCDwarf.cpp index f5260952c7a..c1e53d7bfe8 100644 --- a/lib/MC/MCDwarf.cpp +++ b/lib/MC/MCDwarf.cpp @@ -224,7 +224,33 @@ const MCSymbol *MCDwarfLineTable::Emit(MCStreamer *MCOS) { return LineStartSym; } +void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS) const { + MCOS.EmitLabel(Header.Emit(&MCOS, None).second); +} + std::pair MCDwarfLineTableHeader::Emit(MCStreamer *MCOS) const { + static const char StandardOpcodeLengths[] = { + 0, // length of DW_LNS_copy + 1, // length of DW_LNS_advance_pc + 1, // length of DW_LNS_advance_line + 1, // length of DW_LNS_set_file + 1, // length of DW_LNS_set_column + 0, // length of DW_LNS_negate_stmt + 0, // length of DW_LNS_set_basic_block + 0, // length of DW_LNS_const_add_pc + 1, // length of DW_LNS_fixed_advance_pc + 0, // length of DW_LNS_set_prologue_end + 0, // length of DW_LNS_set_epilogue_begin + 1 // DW_LNS_set_isa + }; + assert(array_lengthof(StandardOpcodeLengths) == (DWARF2_LINE_OPCODE_BASE - 1)); + return Emit(MCOS, StandardOpcodeLengths); +} + +std::pair +MCDwarfLineTableHeader::Emit(MCStreamer *MCOS, + ArrayRef StandardOpcodeLengths) const { + MCContext &context = MCOS->getContext(); // Create a symbol at the beginning of the line table. @@ -260,21 +286,11 @@ std::pair MCDwarfLineTableHeader::Emit(MCStreamer *MCOS) MCOS->EmitIntValue(DWARF2_LINE_DEFAULT_IS_STMT, 1); MCOS->EmitIntValue(DWARF2_LINE_BASE, 1); MCOS->EmitIntValue(DWARF2_LINE_RANGE, 1); - MCOS->EmitIntValue(DWARF2_LINE_OPCODE_BASE, 1); + MCOS->EmitIntValue(StandardOpcodeLengths.size() + 1, 1); // Standard opcode lengths - MCOS->EmitIntValue(0, 1); // length of DW_LNS_copy - MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_pc - MCOS->EmitIntValue(1, 1); // length of DW_LNS_advance_line - MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_file - MCOS->EmitIntValue(1, 1); // length of DW_LNS_set_column - MCOS->EmitIntValue(0, 1); // length of DW_LNS_negate_stmt - MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_basic_block - MCOS->EmitIntValue(0, 1); // length of DW_LNS_const_add_pc - MCOS->EmitIntValue(1, 1); // length of DW_LNS_fixed_advance_pc - MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_prologue_end - MCOS->EmitIntValue(0, 1); // length of DW_LNS_set_epilogue_begin - MCOS->EmitIntValue(1, 1); // DW_LNS_set_isa + for (char Length : StandardOpcodeLengths) + MCOS->EmitIntValue(Length, 1); // Put out the directory and file tables. diff --git a/test/DebugInfo/X86/generate-odr-hash.ll b/test/DebugInfo/X86/generate-odr-hash.ll index e01863d76c3..977016315c5 100644 --- a/test/DebugInfo/X86/generate-odr-hash.ll +++ b/test/DebugInfo/X86/generate-odr-hash.ll @@ -141,6 +141,8 @@ ; CHECK-LABEL: .debug_line.dwo contents: ; FISSION: Line table prologue +; FISSION: opcode_base: 1 +; FISSION-NOT: standard_opcode_lengths ; FISSION-NOT: file_names[ ; FISSION: file_names{{.*}} bar.h ; FISSION: file_names{{.*}} bar.cpp