Emit less labels for debug info and stop emitting .loc directives for DBG_VALUEs.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 25 Mar 2011 17:20:59 +0000 (17:20 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Fri, 25 Mar 2011 17:20:59 +0000 (17:20 +0000)
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

lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
test/CodeGen/X86/2010-05-26-DotDebugLoc.ll
test/CodeGen/X86/dbg-value-range.ll
test/CodeGen/X86/unknown-location.ll

index 1a84c1f23a1f405abe0b6b1a2d01674c4fd50339..b5a266dc6e918749fbb918ab7802b9b39bdd5804 100644 (file)
@@ -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<const MDNode*> 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;
 }
 
 //===----------------------------------------------------------------------===//
index 207542dfd3fce5683224fb6ec1f9f8ab2883b361..a4260fb5ac6c3d65dec71f2a751d9f0433f72541 100644 (file)
@@ -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);
index 60171eb62973bb94506317618c06409143c028de..0886c00f6346a5964c90d84ac40d4acddbe529d9 100644 (file)
@@ -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
index 665cedcb0b38e68f332a6d7709e148b141fe59f5..161681f3482722426f72f883a2ad8b7ee4e56f57 100644 (file)
@@ -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
index 7d101bf95cf88a349686c89a494c93a65e403025..b89c4738af125b89c6d051e746a41835807fcb47 100644 (file)
@@ -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: