[llvm-commits] [llvm] r104720 - in /llvm/trunk/lib/CodeGen/AsmPrinter: DwarfDebug.cpp DwarfDebug.h

Devang Patel dpatel at apple.com
Wed May 26 12:37:24 PDT 2010


Author: dpatel
Date: Wed May 26 14:37:24 2010
New Revision: 104720

URL: http://llvm.org/viewvc/llvm-project?rev=104720&view=rev
Log:
Identify instructions, that needs a label to mark debug info entity, in advance. This simplifies beginScope().

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=104720&r1=104719&r2=104720&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed May 26 14:37:24 2010
@@ -2274,50 +2274,38 @@
 
 /// beginScope - Process beginning of a scope.
 void DwarfDebug::beginScope(const MachineInstr *MI) {
+  if (InsnNeedsLabel.count(MI) == 0) {
+    LabelsBeforeInsn[MI] = PrevLabel;
+    return;
+  }
+
   // Check location.
   DebugLoc DL = MI->getDebugLoc();
-  if (DL.isUnknown() && !UnknownLocations) {
-    if (MI->isDebugValue() && PrevLabel)
-      LabelsBeforeInsn[MI] = PrevLabel;
+  if (!DL.isUnknown()) {
+    const MDNode *Scope = DL.getScope(Asm->MF->getFunction()->getContext());
+    PrevLabel = recordSourceLine(DL.getLine(), DL.getCol(), Scope);
+    PrevInstLoc = DL;
+    LabelsBeforeInsn[MI] = PrevLabel;
     return;
   }
- 
-  bool LocalVar = false;
+
+  // If location is unknown then Use last known location for this DBG_VALUE 
+  // instruction.
   if (MI->isDebugValue()) {
-    assert (MI->getNumOperands() > 1 && "Invalid machine instruction!");
-    DIVariable DV(MI->getOperand(MI->getNumOperands() - 1).getMetadata());
-    if (!DV.Verify()) return;
-    if (DV.getTag() != dwarf::DW_TAG_arg_variable
-        && !isDbgValueInUndefinedReg(MI))
-      LocalVar = true;
-  }
-
-  MCSymbol *Label = NULL;
-  if (DL == PrevInstLoc)
-    Label = PrevLabel;
-  // Do not emit line number entry for arguments.
-  else if (!MI->isDebugValue() || LocalVar) {
-    const MDNode *Scope = 0;
-    if (DL.isUnknown() == false) {
-      Scope = DL.getScope(Asm->MF->getFunction()->getContext());
-      // FIXME: Should only verify each scope once!
-      if (!DIScope(Scope).Verify())
-        return;
-    } 
-    // else ...
-    // This instruction has no debug location. If the preceding instruction
-    // did, emit debug location information to indicate that the debug
-    // location is now unknown.
-    
-    Label = recordSourceLine(DL.getLine(), DL.getCol(), Scope);
-    PrevInstLoc = DL;
-    PrevLabel = Label;
+    const MDNode *Scope = 
+      PrevInstLoc.getScope(Asm->MF->getFunction()->getContext());
+    PrevLabel = recordSourceLine(PrevInstLoc.getLine(), PrevInstLoc.getCol(), Scope);
+    LabelsBeforeInsn[MI] = PrevLabel;
+    return;
+  }
+
+  if (UnknownLocations) {
+    PrevLabel = recordSourceLine(0, 0, 0);
+    LabelsBeforeInsn[MI] = PrevLabel;
+    return;
   }
 
-  // If this instruction begins a scope then note down corresponding label
-  // even if previous label is reused.
-  if (Label && (InsnsBeginScopeSet.count(MI) != 0 || MI->isDebugValue()))
-    LabelsBeforeInsn[MI] = Label;
+  assert (0 && "Instruction is not processed!");
 }
 
 /// endScope - Process end of a scope.
@@ -2627,6 +2615,40 @@
   }
   
   recordSourceLine(Line, Col, Scope);
+
+  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();
+         II != IE; ++II) {
+      const MachineInstr *MI = II;
+      DebugLoc DL = MI->getDebugLoc();
+      if (MI->isDebugValue()) {
+        // DBG_VALUE needs a label if the variable is local variable or
+        // an argument whose location is changing.
+        assert (MI->getNumOperands() > 1 && "Invalid machine instruction!");
+        DIVariable DV(MI->getOperand(MI->getNumOperands() - 1).getMetadata());
+        if (!DV.Verify()) continue;
+        if (DV.getTag() != dwarf::DW_TAG_arg_variable)
+          InsnNeedsLabel.insert(MI);
+        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);
+      }
+      
+      if (!DL.isUnknown() || UnknownLocations)
+        PrevLoc = DL;
+    }
+
+  PrevLabel = FunctionBeginSym;
 }
 
 /// endFunction - Gather and emit post-function debug information.
@@ -2673,6 +2695,8 @@
 
   // Clear debug info
   CurrentFnDbgScope = NULL;
+  InsnNeedsLabel.clear();
+  ProcessedArgs.clear();
   DbgVariableToFrameIndexMap.clear();
   VarToAbstractVarMap.clear();
   DbgVariableToDbgInstMap.clear();

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=104720&r1=104719&r2=104720&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Wed May 26 14:37:24 2010
@@ -227,6 +227,13 @@
   /// instruction.
   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
 
+  /// insnNeedsLabel - Collection of instructions that need a label to mark
+  /// a debuggging information entity.
+  SmallPtrSet<const MachineInstr *, 8> InsnNeedsLabel;
+
+  /// ProcessedArgs - Collection of arguments already processed.
+  SmallPtrSet<const MDNode *, 8> ProcessedArgs;
+
   SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
 
   /// Previous instruction's location information. This is used to determine





More information about the llvm-commits mailing list