From: Jakob Stoklund Olesen Date: Fri, 25 Mar 2011 17:20:59 +0000 (+0000) Subject: Emit less labels for debug info and stop emitting .loc directives for DBG_VALUEs. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=15a3ea0628d2e961cecd70b4e284149524aa3019;p=oota-llvm.git Emit less labels for debug info and stop emitting .loc directives for DBG_VALUEs. The .dot directives don't need labels, that is a leftover from when we created line number info manually. Instructions following a DBG_VALUE can share its label since the DBG_VALUE doesn't produce any code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128284 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 1a84c1f23a1..b5a266dc6e9 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2538,47 +2538,46 @@ const MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) { /// beginInstruction - Process beginning of an instruction. void DwarfDebug::beginInstruction(const MachineInstr *MI) { - if (InsnNeedsLabel.count(MI) == 0) { - LabelsBeforeInsn[MI] = PrevLabel; - return; + // Check if source location changes, but ignore DBG_VALUE locations. + if (!MI->isDebugValue()) { + DebugLoc DL = MI->getDebugLoc(); + if (DL != PrevInstLoc && (!DL.isUnknown() || UnknownLocations)) { + PrevInstLoc = DL; + if (!DL.isUnknown()) { + const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); + recordSourceLine(DL.getLine(), DL.getCol(), Scope); + } else + recordSourceLine(0, 0, 0); + } } - // Check location. - DebugLoc DL = MI->getDebugLoc(); - if (!DL.isUnknown()) { - const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext()); - PrevLabel = recordSourceLine(DL.getLine(), DL.getCol(), Scope); - PrevInstLoc = DL; - LabelsBeforeInsn[MI] = PrevLabel; + // Insert labels where requested. + if (!InsnNeedsLabel.count(MI)) return; - } - // If location is unknown then use temp label for this DBG_VALUE - // instruction. - if (MI->isDebugValue()) { + if (!PrevLabel) { PrevLabel = MMI->getContext().CreateTempSymbol(); Asm->OutStreamer.EmitLabel(PrevLabel); - LabelsBeforeInsn[MI] = PrevLabel; - return; } - - if (UnknownLocations) { - PrevLabel = recordSourceLine(0, 0, 0); - LabelsBeforeInsn[MI] = PrevLabel; - return; - } - - assert (0 && "Instruction is not processed!"); + LabelsBeforeInsn[MI] = PrevLabel; } /// endInstruction - Process end of an instruction. void DwarfDebug::endInstruction(const MachineInstr *MI) { - if (InsnsNeedsLabelAfter.count(MI) != 0) { - // Emit a label if this instruction ends a scope. - MCSymbol *Label = MMI->getContext().CreateTempSymbol(); - Asm->OutStreamer.EmitLabel(Label); - LabelsAfterInsn[MI] = Label; + // Don't create a new label after DBG_VALUE instructions. + // They don't generate code. + if (!MI->isDebugValue()) + PrevLabel = 0; + + if (!InsnsNeedsLabelAfter.count(MI)) + return; + + // We need a label after this instruction. + if (!PrevLabel) { + PrevLabel = MMI->getContext().CreateTempSymbol(); + Asm->OutStreamer.EmitLabel(PrevLabel); } + LabelsAfterInsn[MI] = PrevLabel; } /// getOrCreateDbgScope - Create DbgScope for the scope. @@ -2838,6 +2837,7 @@ void DwarfDebug::identifyScopeMarkers() { RE = Ranges.end(); RI != RE; ++RI) { assert(RI->first && "DbgRange does not have first instruction!"); assert(RI->second && "DbgRange does not have second instruction!"); + InsnNeedsLabel.insert(RI->first); InsnsNeedsLabelAfter.insert(RI->second); } } @@ -2927,7 +2927,6 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { /// LiveUserVar - Map physreg numbers to the MDNode they contain. std::vector LiveUserVar(TRI->getNumRegs()); - DebugLoc PrevLoc; for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E; ++I) for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); @@ -2957,15 +2956,6 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { else if (!ProcessedArgs.insert(DV)) InsnNeedsLabel.insert(MI); } else { - // If location is unknown then instruction needs a location only if - // UnknownLocations flag is set. - if (DL.isUnknown()) { - if (UnknownLocations && !PrevLoc.isUnknown()) - InsnNeedsLabel.insert(MI); - } else if (DL != PrevLoc) - // Otherwise, instruction needs a location only if it is new location. - InsnNeedsLabel.insert(MI); - // Check if the instruction clobbers any registers with debug vars. for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(), MOE = MI->operands_end(); MOI != MOE; ++MOI) { @@ -2992,11 +2982,9 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) { } } } - - if (!DL.isUnknown() || UnknownLocations) - PrevLoc = DL; } + PrevInstLoc = DebugLoc(); PrevLabel = FunctionBeginSym; } @@ -3112,8 +3100,7 @@ DbgScope *DwarfDebug::findDbgScope(const MachineInstr *MInsn) { /// recordSourceLine - Register a source line with debug info. Returns the /// unique label that was emitted and which provides correspondence to /// the source line list. -MCSymbol *DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, - const MDNode *S) { +void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S){ StringRef Fn; StringRef Dir; unsigned Src = 1; @@ -3144,10 +3131,6 @@ MCSymbol *DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, Asm->OutStreamer.EmitDwarfLocDirective(Src, Line, Col, DWARF2_FLAG_IS_STMT, 0, 0); - - MCSymbol *Label = MMI->getContext().CreateTempSymbol(); - Asm->OutStreamer.EmitLabel(Label); - return Label; } //===----------------------------------------------------------------------===// diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 207542dfd3f..a4260fb5ac6 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -536,7 +536,7 @@ private: /// recordSourceLine - Register a source line with debug info. Returns the /// unique label that was emitted and which provides correspondence to /// the source line list. - MCSymbol *recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope); + void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope); /// recordVariableFrameIndex - Record a variable's index. void recordVariableFrameIndex(const DbgVariable *V, int Index); diff --git a/test/CodeGen/X86/2010-05-26-DotDebugLoc.ll b/test/CodeGen/X86/2010-05-26-DotDebugLoc.ll index 60171eb6297..0886c00f634 100644 --- a/test/CodeGen/X86/2010-05-26-DotDebugLoc.ll +++ b/test/CodeGen/X86/2010-05-26-DotDebugLoc.ll @@ -55,12 +55,21 @@ declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone !29 = metadata !{i32 524299, metadata !9, i32 17, i32 0} ; [ DW_TAG_lexical_block ] !30 = metadata !{i32 19, i32 0, metadata !29, null} +; The variable bar:myvar changes registers after the first movq. +; It is cobbered by popq %rbx +; CHECK: movq +; CHECK-NEXT: [[LABEL:Ltmp[0-9]*]] +; CHECK: .loc 1 19 0 +; CHECK: popq +; CHECK-NEXT: [[CLOBBER:Ltmp[0-9]*]] + + ; CHECK: Ldebug_loc0: ; CHECK-NEXT: .quad Lfunc_begin0 -; CHECK-NEXT: .quad Ltmp3 +; CHECK-NEXT: .quad [[LABEL]] ; CHECK-NEXT: .short 1 ; CHECK-NEXT: .byte 85 -; CHECK-NEXT: .quad Ltmp3 -; CHECK-NEXT: .quad Ltmp6 +; CHECK-NEXT: .quad [[LABEL]] +; CHECK-NEXT: .quad [[CLOBBER]] ; CHECK-NEXT: .short 1 ; CHECK-NEXT: .byte 83 diff --git a/test/CodeGen/X86/dbg-value-range.ll b/test/CodeGen/X86/dbg-value-range.ll index 665cedcb0b3..161681f3482 100644 --- a/test/CodeGen/X86/dbg-value-range.ll +++ b/test/CodeGen/X86/dbg-value-range.ll @@ -45,13 +45,13 @@ declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone ; The variable is in %rdi which is clobbered by 'movl %ebx, %edi' ; Here Ltmp7 is the end of the location range. -;CHECK:Ltmp6 -;CHECK-NEXT: movl -;CHECK-NEXT: Ltmp7 +;CHECK: .loc 1 7 2 +;CHECK: movl +;CHECK-NEXT: [[CLOBBER:Ltmp[0-9]*]] ;CHECK:Ldebug_loc0: -;CHECK-NEXT: .quad Ltmp -;CHECK-NEXT: .quad Ltmp7 +;CHECK-NEXT: .quad +;CHECK-NEXT: .quad [[CLOBBER]] ;CHECK-NEXT: .short 1 ;CHECK-NEXT: .byte 85 ;CHECK-NEXT: .quad 0 diff --git a/test/CodeGen/X86/unknown-location.ll b/test/CodeGen/X86/unknown-location.ll index 7d101bf95cf..b89c4738af1 100644 --- a/test/CodeGen/X86/unknown-location.ll +++ b/test/CodeGen/X86/unknown-location.ll @@ -4,16 +4,11 @@ ; represent this in the debug information. This is done by setting line ; and column to 0 -; CHECK: leal (%rdi,%rsi), %eax +; CHECK: leal ; CHECK-NEXT: .loc 1 0 0 -; CHECK-NEXT: Ltmp -; CHECK-NEXT: cltd -; CHECK-NEXT: idivl %r8d +; CHECK: cltd +; CHECK-NEXT: idivl ; CHECK-NEXT: .loc 2 4 3 -; CHECK-NEXT: Ltmp -; CHECK-NEXT: addl %ecx, %eax -; CHECK-NEXT: ret -; CHECK-NEXT: Ltmp define i32 @foo(i32 %w, i32 %x, i32 %y, i32 %z) nounwind { entry: