[PATCH] Use a single data structure to store all user variables in DwarfDebug

Alexey Samsonov samsonov at google.com
Wed Apr 30 15:50:25 PDT 2014


Hi dblaikie,

Get rid of UserVariables set, and turn DbgValues into MapVector
to get a fixed ordering, as suggested in review for http://reviews.llvm.org/D3573.

http://reviews.llvm.org/D3579

Files:
  lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/CodeGen/AsmPrinter/DwarfDebug.h

Index: lib/CodeGen/AsmPrinter/DwarfDebug.h
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -219,11 +219,8 @@
   // Maps instruction with label emitted after instruction.
   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
 
-  // Every user variable mentioned by a DBG_VALUE instruction in order of
-  // appearance.
-  SmallVector<const MDNode *, 8> UserVariables;
-
   // History of DBG_VALUE and clobber instructions for each user variable.
+  // Variables are listed in order of appearance.
   DbgValueHistoryMap DbgValues;
 
   // Previous instruction's location information. This is used to determine
Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1192,13 +1192,14 @@
   // Grab the variable info that was squirreled away in the MMI side-table.
   collectVariableInfoFromMMITable(Processed);
 
-  for (const MDNode *Var : UserVariables) {
+  for (const auto &I : DbgValues) {
+    const MDNode *Var = I.first;
     if (Processed.count(Var))
       continue;
 
     // History contains relevant DBG_VALUE instructions for Var and instructions
     // clobbering it.
-    SmallVectorImpl<const MachineInstr *> &History = DbgValues[Var];
+    const SmallVectorImpl<const MachineInstr *> &History = I.second;
     if (History.empty())
       continue;
     const MachineInstr *MInsn = History.front();
@@ -1417,7 +1418,7 @@
   if (LScopes.empty())
     return;
 
-  assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned");
+  assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
 
   // Make sure that each lexical scope will have a begin/end label.
   identifyScopeMarkers();
@@ -1444,13 +1445,13 @@
     for (const auto &MI : MBB) {
       if (MI.isDebugValue()) {
         assert(MI.getNumOperands() > 1 && "Invalid machine instruction!");
-        // Keep track of user variables in order of appearance. Store the set
-        // of variables we've already seen as a set of keys in DbgValues.
+        // Keep track of user variables in order of appearance. Create the
+        // empty history for each variable so that the order of keys in
+        // DbgValues is correct. Actual history will be populated in
+        // calculateDbgValueHistory() function.
         const MDNode *Var = MI.getDebugVariable();
-        auto IterPair = DbgValues.insert(
+        DbgValues.insert(
             std::make_pair(Var, SmallVector<const MachineInstr *, 4>()));
-        if (IterPair.second)
-          UserVariables.push_back(Var);
       } else if (!MI.getFlag(MachineInstr::FrameSetup) &&
                  PrologEndLoc.isUnknown() && !MI.getDebugLoc().isUnknown()) {
         // First known non-DBG_VALUE and non-frame setup location marks
@@ -1605,7 +1606,6 @@
     DeleteContainerPointers(I.second);
   ScopeVariables.clear();
   DeleteContainerPointers(CurrentFnArguments);
-  UserVariables.clear();
   DbgValues.clear();
   AbstractVariables.clear();
   LabelsBeforeInsn.clear();
Index: lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
===================================================================
--- lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
+++ lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
@@ -10,7 +10,7 @@
 #ifndef CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H_
 #define CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H_
 
-#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallVector.h"
 
 namespace llvm {
@@ -22,8 +22,8 @@
 
 // For each user variable, keep a list of DBG_VALUE instructions in order.
 // The list can also contain normal instructions that clobber the previous
-// DBG_VALUE.
-typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4>>
+// DBG_VALUE. The variables are listed in order of appearance.
+typedef MapVector<const MDNode *, SmallVector<const MachineInstr *, 4>>
 DbgValueHistoryMap;
 
 void calculateDbgValueHistory(const MachineFunction *MF,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3579.8997.patch
Type: text/x-patch
Size: 4155 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140430/390c8edc/attachment.bin>


More information about the llvm-commits mailing list