diff options
author | Fangrui Song <maskray@google.com> | 2019-04-10 07:44:23 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-04-10 07:44:23 +0000 |
commit | b3be23d3342dbeef2d1b2a2a230c3debdc538c97 (patch) | |
tree | b4c5d86b4f9872f32e299c3a678ec4bbcd942b03 /llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | |
parent | 09020ec2a7199fca2835e6dbbac9d89f9222a843 (diff) | |
download | bcm5719-llvm-b3be23d3342dbeef2d1b2a2a230c3debdc538c97.tar.gz bcm5719-llvm-b3be23d3342dbeef2d1b2a2a230c3debdc538c97.zip |
[DWARF] Simplify LineTable::findRowInSeq
We want the last row whose address is less than or equal to Address.
This can be computed as upper_bound - 1, which is simpler than
lower_bound followed by skipping equal rows in a loop.
Since FirstRow (LowPC) does not satisfy the predicate (OrderByAddress)
while LastRow-1 (HighPC) satisfies the predicate. We can decrease the
search range by two, i.e.
upper_bound [FirstRow,LastRow) = upper_bound [FirstRow+1,LastRow-1)
llvm-svn: 358053
Diffstat (limited to 'llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp index a5513e87aac..9a720651ebb 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -860,46 +860,22 @@ uint32_t DWARFDebugLine::LineTable::findRowInSeq( if (!Seq.containsPC(Address)) return UnknownRowIndex; assert(Seq.SectionIndex == Address.SectionIndex); - // Search for instruction address in the rows describing the sequence. - // Rows are stored in a vector, so we may use arithmetical operations with - // iterators. + // In some cases, e.g. first instruction in a function, the compiler generates + // two entries, both with the same address. We want the last one. + // + // In general we want a non-empty range: the last row whose address is less + // than or equal to Address. This can be computed as upper_bound - 1. DWARFDebugLine::Row Row; Row.Address = Address; RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex; RowIter LastRow = Rows.begin() + Seq.LastRowIndex; - LineTable::RowIter RowPos = std::lower_bound( - FirstRow, LastRow, Row, DWARFDebugLine::Row::orderByAddress); - // Since Address is in Seq, FirstRow <= RowPos < LastRow. - assert(FirstRow <= RowPos && RowPos < LastRow); + assert(FirstRow->Address.Address <= Row.Address.Address && + Row.Address.Address < LastRow[-1].Address.Address); + RowIter RowPos = std::upper_bound(FirstRow + 1, LastRow - 1, Row, + DWARFDebugLine::Row::orderByAddress) - + 1; assert(Seq.SectionIndex == RowPos->Address.SectionIndex); - if (RowPos->Address.Address != Address.Address) { - // lower_bound either lands on the RowPos with the same Address - // as the queried one, or on the first that's larger. - assert(RowPos->Address.Address > Address.Address); - // We know RowPos can't be FirstRow, in this case, - // because the queried Address is in Seq. So if it were - // FirstRow, then RowPos->Address.Address == Address.Address, - // and we wouldn't be here. - assert(RowPos != FirstRow); - --RowPos; - } - // In some cases, e.g. first instruction in a function, the compiler generates - // two entries, both with the same address. We want the last one. - // There are 2 cases wrt. RowPos and the addresses in records before/after it: - // 1) RowPos's address is the one we looked for. In this case, we want to - // skip any potential empty ranges. - // 2) RowPos's address is less than the one we looked for. In that case, we - // arrived here by finding the first range with a greater address, - // then decrementing 1. If the address of this range is part of a sequence of - // empty ones, it is the last one. - // In either case, the loop below lands on the correct RowPos. - while (RowPos->Address.Address == (RowPos + 1)->Address.Address) { - ++RowPos; - } - - assert(RowPos < LastRow); - uint32_t Index = Seq.FirstRowIndex + (RowPos - FirstRow); - return Index; + return RowPos - Rows.begin(); } uint32_t DWARFDebugLine::LineTable::lookupAddress( |