Use a single data structure to store all user variables in DwarfDebug
authorAlexey Samsonov <samsonov@google.com>
Wed, 30 Apr 2014 23:02:40 +0000 (23:02 +0000)
committerAlexey Samsonov <samsonov@google.com>
Wed, 30 Apr 2014 23:02:40 +0000 (23:02 +0000)
Summary:
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.

Test Plan: llvm regression tests

Reviewers: dblaikie

Reviewed By: dblaikie

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D3579

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207720 91177308-0d34-0410-b5e6-96231b3b80d8

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

index d919522f9bc2cd1bb0dca25cbeb32ce7d70917b4..2945c1522de3a20163a99a160bd6ae7bc2918fae 100644 (file)
@@ -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 @@ class TargetRegisterInfo;
 
 // 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,
index 91a7b6e53aac64f9f0105b190426c5a4cabfe039..cad669fbf35226b70f09165980b7cb7230475da0 100644 (file)
@@ -1196,18 +1196,18 @@ DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
   // Grab the variable info that was squirreled away in the MMI side-table.
   collectVariableInfoFromMMITable(Processed);
 
-  for (const MDNode *Var : UserVariables) {
-    if (Processed.count(Var))
+  for (const auto &I : DbgValues) {
+    DIVariable DV(I.first);
+    if (Processed.count(DV))
       continue;
 
-    // History contains relevant DBG_VALUE instructions for Var and instructions
+    // History contains relevant DBG_VALUE instructions for DV 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();
 
-    DIVariable DV(Var);
     LexicalScope *Scope = nullptr;
     if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
         DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
@@ -1421,7 +1421,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
   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();
@@ -1448,13 +1448,13 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
     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
@@ -1609,7 +1609,6 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
     DeleteContainerPointers(I.second);
   ScopeVariables.clear();
   DeleteContainerPointers(CurrentFnArguments);
-  UserVariables.clear();
   DbgValues.clear();
   AbstractVariables.clear();
   LabelsBeforeInsn.clear();
index f0472e93f55b668635fe8ee943f3d1074deeea18..5779a513c1ffcb9593dc071d525fd7d5744394b9 100644 (file)
@@ -219,11 +219,8 @@ class DwarfDebug : public AsmPrinterHandler {
   // 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