Debug info: Refactor DebugLocEntry's Merge function to make

buildLocationLists easier to read.

The previous implementation conflated the merging of individual pieces
and the merging of entire DebugLocEntries.

By splitting this functionality into two separate functions the intention
of the code should be clearer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215383 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adrian Prantl
2014-08-11 20:59:28 +00:00
parent 6c2be4ff95
commit 0ca6b9f076
2 changed files with 37 additions and 14 deletions

View File

@ -1272,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");
}