[llvm] r205382 - DebugInfo: Introduce DebugLocList to encapsulate a list of DebugLocEntries and an MC Label to refer to them

David Blaikie dblaikie at gmail.com
Tue Apr 1 18:43:18 PDT 2014


Author: dblaikie
Date: Tue Apr  1 20:43:18 2014
New Revision: 205382

URL: http://llvm.org/viewvc/llvm-project?rev=205382&view=rev
Log:
DebugInfo: Introduce DebugLocList to encapsulate a list of DebugLocEntries and an MC Label to refer to them

This removes the magic-number-esque code creating/retrieving the same
label for a debug_loc entry from two places and removes the last small
piece of reusable logic from emitDebugLoc so that there will be less
duplication when refactoring it into two functions (one for debug_loc,
the other for debug_loc.dwo).

Added:
    llvm/trunk/lib/CodeGen/AsmPrinter/DebugLocList.h
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=205382&r1=205381&r2=205382&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Tue Apr  1 20:43:18 2014
@@ -560,7 +560,7 @@ unsigned DIELocList::SizeOf(AsmPrinter *
 ///
 void DIELocList::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
   DwarfDebug *DD = AP->getDwarfDebug();
-  MCSymbol *Label = AP->GetTempSymbol("debug_loc", Index);
+  MCSymbol *Label = DD->getDebugLocEntries()[Index].Label;
 
   if (AP->MAI->doesDwarfUseRelocationsAcrossSections() && !DD->useSplitDwarf())
     AP->EmitSectionOffset(Label, DD->getDebugLocSym());

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp?rev=205382&r1=205381&r2=205382&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp Tue Apr  1 20:43:18 2014
@@ -284,9 +284,10 @@ void DIEHash::hashBlockData(const SmallV
 // Hash the contents of a loclistptr class.
 void DIEHash::hashLocList(const DIELocList &LocList) {
   HashingByteStreamer Streamer(*this);
+  DwarfDebug &DD = *AP->getDwarfDebug();
   for (const auto &Entry :
-       AP->getDwarfDebug()->getDebugLocEntries()[LocList.getValue()])
-    AP->getDwarfDebug()->emitDebugLocEntry(Streamer, Entry);
+       DD.getDebugLocEntries()[LocList.getValue()].List)
+    DD.emitDebugLocEntry(Streamer, Entry);
 }
 
 // Hash an individual attribute \param Attr based on the type of attribute and

Added: llvm/trunk/lib/CodeGen/AsmPrinter/DebugLocList.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DebugLocList.h?rev=205382&view=auto
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DebugLocList.h (added)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DebugLocList.h Tue Apr  1 20:43:18 2014
@@ -0,0 +1,23 @@
+//===--- lib/CodeGen/DebugLocList.h - DWARF debug_loc list ------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CODEGEN_ASMPRINTER_DEBUGLOCLIST_H__
+#define CODEGEN_ASMPRINTER_DEBUGLOCLIST_H__
+
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/ADT/SmallVector.h"
+#include "DebugLocEntry.h"
+
+namespace llvm {
+struct DebugLocList {
+  MCSymbol *Label;
+  SmallVector<DebugLocEntry, 4> List;
+};
+}
+#endif

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=205382&r1=205381&r2=205382&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Apr  1 20:43:18 2014
@@ -1271,7 +1271,11 @@ DwarfDebug::collectVariableInfo(SmallPtr
     // Handle multiple DBG_VALUE instructions describing one variable.
     RegVar->setDotDebugLocOffset(DotDebugLocEntries.size());
 
-    SmallVector<DebugLocEntry, 4> DebugLoc;
+    DotDebugLocEntries.resize(DotDebugLocEntries.size() + 1);
+    DebugLocList &LocList = DotDebugLocEntries.back();
+    LocList.Label =
+        Asm->GetTempSymbol("debug_loc", DotDebugLocEntries.size() - 1);
+    SmallVector<DebugLocEntry, 4> &DebugLoc = LocList.List;
     for (SmallVectorImpl<const MachineInstr *>::const_iterator
              HI = History.begin(),
              HE = History.end();
@@ -1313,7 +1317,6 @@ DwarfDebug::collectVariableInfo(SmallPtr
       if (DebugLoc.empty() || !DebugLoc.back().Merge(Loc))
         DebugLoc.push_back(std::move(Loc));
     }
-    DotDebugLocEntries.push_back(std::move(DebugLoc));
   }
 
   // Collect info for variables that were optimized out.
@@ -2406,10 +2409,9 @@ void DwarfDebug::emitDebugLoc() {
       useSplitDwarf() ? Asm->getObjFileLowering().getDwarfLocDWOSection()
                       : Asm->getObjFileLowering().getDwarfLocSection());
   unsigned char Size = Asm->getDataLayout().getPointerSize();
-  unsigned index = 0;
   for (const auto &DebugLoc : DotDebugLocEntries) {
-    Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_loc", index));
-    for (const auto &Entry : DebugLoc) {
+    Asm->OutStreamer.EmitLabel(DebugLoc.Label);
+    for (const auto &Entry : DebugLoc.List) {
       // Set up the range. This range is relative to the entry point of the
       // compile unit. This is a hard coded 0 for low_pc when we're emitting
       // ranges, or the DW_AT_low_pc on the compile unit otherwise.
@@ -2440,7 +2442,6 @@ void DwarfDebug::emitDebugLoc() {
       Asm->OutStreamer.EmitIntValue(0, Size);
       Asm->OutStreamer.EmitIntValue(0, Size);
     }
-    ++index;
   }
 }
 

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=205382&r1=205381&r2=205382&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Apr  1 20:43:18 2014
@@ -17,6 +17,7 @@
 #include "AsmPrinterHandler.h"
 #include "DIE.h"
 #include "DebugLocEntry.h"
+#include "DebugLocList.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -288,8 +289,9 @@ class DwarfDebug : public AsmPrinterHand
   // Collection of abstract variables.
   DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
 
-  // Collection of DebugLocEntry.
-  SmallVector<SmallVector<DebugLocEntry, 4>, 4> DotDebugLocEntries;
+  // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
+  // can refer to them in spite of insertions into this list.
+  SmallVector<DebugLocList, 4> DotDebugLocEntries;
 
   // Collection of subprogram DIEs that are marked (at the end of the module)
   // as DW_AT_inline.
@@ -686,7 +688,7 @@ public:
   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
 
   /// Returns the entries for the .debug_loc section.
-  const SmallVectorImpl<SmallVector<DebugLocEntry, 4>> &
+  const SmallVectorImpl<DebugLocList> &
   getDebugLocEntries() const {
     return DotDebugLocEntries;
   }





More information about the llvm-commits mailing list