[llvm] r348806 - debuginfo: Use symbol difference for CU length to simplify assembly reading/editing
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 10 14:44:48 PST 2018
Author: dblaikie
Date: Mon Dec 10 14:44:48 2018
New Revision: 348806
URL: http://llvm.org/viewvc/llvm-project?rev=348806&view=rev
Log:
debuginfo: Use symbol difference for CU length to simplify assembly reading/editing
Mucking about simplifying a test case ( https://reviews.llvm.org/D55261 ) I stumbled across something I've hit before - that LLVM's (GCC's does too, FWIW) assembly output includes a hardcode length for a DWARF unit in its header. Instead we could emit a label difference - making the assembly easier to read/edit (though potentially at a slight (I haven't tried to observe it) performance cost of delaying/sinking the length computation into the MC layer).
Reviewers: JDevlieghere, probinson, ABataev
Differential Revision: https://reviews.llvm.org/D55281
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=348806&r1=348805&r2=348806&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp Mon Dec 10 14:44:48 2018
@@ -46,6 +46,8 @@ void DwarfFile::emitUnit(DwarfUnit *TheU
TheU->emitHeader(UseOffsets);
Asm->emitDwarfDIE(Die);
+
+ Asm->OutStreamer->EmitLabel(TheU->getEndLabel());
}
// Compute the size and offset for each DIE.
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=348806&r1=348805&r2=348806&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Mon Dec 10 14:44:48 2018
@@ -38,6 +38,7 @@
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
+#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cstdint>
#include <string>
@@ -1553,7 +1554,17 @@ DIE *DwarfUnit::getOrCreateStaticMemberD
void DwarfUnit::emitCommonHeader(bool UseOffsets, dwarf::UnitType UT) {
// Emit size of content not including length itself
Asm->OutStreamer->AddComment("Length of Unit");
- Asm->emitInt32(getHeaderSize() + getUnitDie().getSize());
+ StringRef Prefix = isDwoUnit() ? "debug_info_dwo_" : "debug_info_";
+ MCSymbol *BeginLabel = Asm->createTempSymbol(Prefix + "start");
+ EndLabel = Asm->createTempSymbol(Prefix + "end");
+
+ // Use a label difference for the convenience of legible/easily modified
+ // assembly - except on NVPTX where label differences aren't supported.
+ if (Asm->TM.getTargetTriple().isNVPTX())
+ Asm->emitInt32(getHeaderSize() + getUnitDie().getSize());
+ else
+ Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
+ Asm->OutStreamer->EmitLabel(BeginLabel);
Asm->OutStreamer->AddComment("DWARF version number");
unsigned Version = DD->getDwarfVersion();
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=348806&r1=348805&r2=348806&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Mon Dec 10 14:44:48 2018
@@ -48,6 +48,7 @@ protected:
/// Target of Dwarf emission.
AsmPrinter *Asm;
+ MCSymbol *EndLabel;
// Holders for some common dwarf information.
DwarfDebug *DD;
@@ -82,6 +83,7 @@ protected:
public:
// Accessors.
AsmPrinter* getAsmPrinter() const { return Asm; }
+ MCSymbol *getEndLabel() const { return EndLabel; }
uint16_t getLanguage() const { return CUNode->getSourceLanguage(); }
const DICompileUnit *getCUNode() const { return CUNode; }
Modified: llvm/trunk/test/DebugInfo/X86/sections_as_references.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/sections_as_references.ll?rev=348806&r1=348805&r2=348806&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/sections_as_references.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/sections_as_references.ll Mon Dec 10 14:44:48 2018
@@ -9,13 +9,19 @@
; CHECK-NOT: .L
; CHECK: .section .debug_info
-; CHECK-NOT: .L
-; CHECK: .short 2 # DWARF version number
+; CHECK-NEXT: .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
+; CHECK-NEXT: .Ldebug_info_start0:
+; CHECK-NEXT: .short 2 # DWARF version number
; CHECK-NOT: .L
; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section
; CHECK-NOT: .L
; CHECK: .long .debug_line # DW_AT_stmt_list
; CHECK-NOT: .L
+; CHECK: .Ldebug_info_end0:
+; CHECK-NOT: .L
+; CHECK: .long .Ldebug_info_end1-.Ldebug_info_start1 # Length of Unit
+; CHECK-NEXT: .Ldebug_info_start1:
+; CHECK-NOT: .L
; CHECK: .long .debug_abbrev # Offset Into Abbrev. Section
; CHECK-NOT: .L
; CHECK: .long .debug_line # DW_AT_stmt_list
@@ -23,6 +29,7 @@
; CHECK: .quad .debug_info+{{[0-9]+}} # DW_AT_type
; CHECK-NOT: .L
; CHECK: .byte 0 # End Of Children Mark
+; CHECK-NEXT: .Ldebug_info_end1:
; CHECK-NOT: .L
source_filename = "test/DebugInfo/X86/sections_as_references.ll"
More information about the llvm-commits
mailing list