]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blobdiff - lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Debug info: Refactor DebugLocEntry's Merge function to make
[opencl/llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.cpp
index cad477be8efd0825cb0a61884f6db87564d8731b..3dc03d9fb19697ae6d8c74f791dd79c447f41ee6 100644 (file)
@@ -1144,6 +1144,7 @@ bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
   // arguments does the function have at source level.
   if (ArgNo > Size)
     CurrentFnArguments.resize(ArgNo * 2);
+  assert(!CurrentFnArguments[ArgNo - 1]);
   CurrentFnArguments[ArgNo - 1] = Var;
   return true;
 }
@@ -1271,18 +1272,36 @@ DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
 
     auto Value = getDebugLocValue(Begin);
     DebugLocEntry Loc(StartLabel, EndLabel, Value);
-    if (DebugLoc.empty() || !DebugLoc.back().Merge(Loc)) {
-      // Add all values from still valid non-overlapping pieces.
+    bool couldMerge = false;
+
+    // If this is a piece, it may belong to the current DebugLocEntry.
+    if (DIVar.isVariablePiece()) {
+      // Add this value to the list of open ranges.
+      OpenRanges.push_back(std::make_pair(DIVar, Value));
+
+      // Attempt to add the piece to the last entry.
+      if (!DebugLoc.empty())
+        if (DebugLoc.back().MergeValues(Loc))
+          couldMerge = true;
+    }
+
+    if (!couldMerge) {
+      // Need to add a new DebugLocEntry. Add all values from still
+      // valid non-overlapping pieces.
       for (auto Range : OpenRanges)
         Loc.addValue(Range.second);
       DebugLoc.push_back(std::move(Loc));
     }
-    // Add this value to the list of open ranges.
-    if (DIVar.isVariablePiece())
-      OpenRanges.push_back(std::make_pair(DIVar, Value));
+
+    // Attempt to coalesce the ranges of two otherwise identical
+    // DebugLocEntries.
+    auto CurEntry = DebugLoc.rbegin();
+    auto PrevEntry = std::next(CurEntry);
+    if (PrevEntry != DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
+      DebugLoc.pop_back();
 
     DEBUG(dbgs() << "Values:\n";
-          for (auto Value : DebugLoc.back().getValues())
+          for (auto Value : CurEntry->getValues())
             Value.getVariable()->dump();
           dbgs() << "-----\n");
   }