mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 22:24:07 +00:00
[DebugInfo] Further simplify DWARFDebugAranges. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191779 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -16,12 +16,6 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// Compare function DWARFDebugAranges::Range structures
|
|
||||||
static bool RangeLessThan(const DWARFDebugAranges::Range &range1,
|
|
||||||
const DWARFDebugAranges::Range &range2) {
|
|
||||||
return range1.LoPC < range2.LoPC;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class CountArangeDescriptors {
|
class CountArangeDescriptors {
|
||||||
public:
|
public:
|
||||||
@ -40,20 +34,20 @@ namespace {
|
|||||||
CUOffsetCollection(CUOffsets) {}
|
CUOffsetCollection(CUOffsets) {}
|
||||||
void operator()(const DWARFDebugArangeSet &Set) {
|
void operator()(const DWARFDebugArangeSet &Set) {
|
||||||
DWARFDebugAranges::Range Range;
|
DWARFDebugAranges::Range Range;
|
||||||
Range.Offset = Set.getCompileUnitDIEOffset();
|
Range.CUOffset = Set.getCompileUnitDIEOffset();
|
||||||
CUOffsetCollection.insert(Range.Offset);
|
CUOffsetCollection.insert(Range.CUOffset);
|
||||||
|
|
||||||
for (uint32_t i = 0, n = Set.getNumDescriptors(); i < n; ++i) {
|
for (uint32_t i = 0, n = Set.getNumDescriptors(); i < n; ++i) {
|
||||||
const DWARFDebugArangeSet::Descriptor *ArangeDescPtr =
|
const DWARFDebugArangeSet::Descriptor *ArangeDescPtr =
|
||||||
Set.getDescriptor(i);
|
Set.getDescriptor(i);
|
||||||
Range.LoPC = ArangeDescPtr->Address;
|
Range.LowPC = ArangeDescPtr->Address;
|
||||||
Range.Length = ArangeDescPtr->Length;
|
Range.Length = ArangeDescPtr->Length;
|
||||||
|
|
||||||
// Insert each item in increasing address order so binary searching
|
// Insert each item in increasing address order so binary searching
|
||||||
// can later be done!
|
// can later be done!
|
||||||
DWARFDebugAranges::RangeColl::iterator InsertPos =
|
DWARFDebugAranges::RangeColl::iterator InsertPos =
|
||||||
std::lower_bound(RangeCollection.begin(), RangeCollection.end(),
|
std::lower_bound(RangeCollection.begin(), RangeCollection.end(),
|
||||||
Range, RangeLessThan);
|
Range);
|
||||||
RangeCollection.insert(InsertPos, Range);
|
RangeCollection.insert(InsertPos, Range);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +92,7 @@ void DWARFDebugAranges::generate(DWARFContext *CTX) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort(true, /* overlap size */ 0);
|
sortAndMinimize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWARFDebugAranges::dump(raw_ostream &OS) const {
|
void DWARFDebugAranges::dump(raw_ostream &OS) const {
|
||||||
@ -109,30 +103,28 @@ void DWARFDebugAranges::dump(raw_ostream &OS) const {
|
|||||||
|
|
||||||
void DWARFDebugAranges::Range::dump(raw_ostream &OS) const {
|
void DWARFDebugAranges::Range::dump(raw_ostream &OS) const {
|
||||||
OS << format("{0x%8.8x}: [0x%8.8" PRIx64 " - 0x%8.8" PRIx64 ")\n",
|
OS << format("{0x%8.8x}: [0x%8.8" PRIx64 " - 0x%8.8" PRIx64 ")\n",
|
||||||
Offset, LoPC, HiPC());
|
CUOffset, LowPC, HighPC());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWARFDebugAranges::appendRange(uint32_t CUOffset, uint64_t LowPC,
|
void DWARFDebugAranges::appendRange(uint32_t CUOffset, uint64_t LowPC,
|
||||||
uint64_t HighPC) {
|
uint64_t HighPC) {
|
||||||
if (!Aranges.empty()) {
|
if (!Aranges.empty()) {
|
||||||
if (Aranges.back().Offset == CUOffset && Aranges.back().HiPC() == LowPC) {
|
if (Aranges.back().CUOffset == CUOffset &&
|
||||||
Aranges.back().setHiPC(HighPC);
|
Aranges.back().HighPC() == LowPC) {
|
||||||
|
Aranges.back().setHighPC(HighPC);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Aranges.push_back(Range(LowPC, HighPC, CUOffset));
|
Aranges.push_back(Range(LowPC, HighPC, CUOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DWARFDebugAranges::sort(bool Minimize, uint32_t OverlapSize) {
|
void DWARFDebugAranges::sortAndMinimize() {
|
||||||
const size_t orig_arange_size = Aranges.size();
|
const size_t orig_arange_size = Aranges.size();
|
||||||
// Size of one? If so, no sorting is needed
|
// Size of one? If so, no sorting is needed
|
||||||
if (orig_arange_size <= 1)
|
if (orig_arange_size <= 1)
|
||||||
return;
|
return;
|
||||||
// Sort our address range entries
|
// Sort our address range entries
|
||||||
std::stable_sort(Aranges.begin(), Aranges.end(), RangeLessThan);
|
std::stable_sort(Aranges.begin(), Aranges.end());
|
||||||
|
|
||||||
if (!Minimize)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Most address ranges are contiguous from function to function
|
// Most address ranges are contiguous from function to function
|
||||||
// so our new ranges will likely be smaller. We calculate the size
|
// so our new ranges will likely be smaller. We calculate the size
|
||||||
@ -146,7 +138,7 @@ void DWARFDebugAranges::sort(bool Minimize, uint32_t OverlapSize) {
|
|||||||
// copy the new minimal stuff over to the new collection.
|
// copy the new minimal stuff over to the new collection.
|
||||||
size_t minimal_size = 1;
|
size_t minimal_size = 1;
|
||||||
for (size_t i = 1; i < orig_arange_size; ++i) {
|
for (size_t i = 1; i < orig_arange_size; ++i) {
|
||||||
if (!Range::SortedOverlapCheck(Aranges[i-1], Aranges[i], OverlapSize))
|
if (!Range::SortedOverlapCheck(Aranges[i-1], Aranges[i]))
|
||||||
++minimal_size;
|
++minimal_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,15 +153,14 @@ void DWARFDebugAranges::sort(bool Minimize, uint32_t OverlapSize) {
|
|||||||
uint32_t j = 0;
|
uint32_t j = 0;
|
||||||
minimal_aranges[j] = Aranges[0];
|
minimal_aranges[j] = Aranges[0];
|
||||||
for (size_t i = 1; i < orig_arange_size; ++i) {
|
for (size_t i = 1; i < orig_arange_size; ++i) {
|
||||||
if (Range::SortedOverlapCheck(minimal_aranges[j], Aranges[i],
|
if (Range::SortedOverlapCheck(minimal_aranges[j], Aranges[i])) {
|
||||||
OverlapSize)) {
|
minimal_aranges[j].setHighPC(Aranges[i].HighPC());
|
||||||
minimal_aranges[j].setHiPC (Aranges[i].HiPC());
|
|
||||||
} else {
|
} else {
|
||||||
// Only increment j if we aren't merging
|
// Only increment j if we aren't merging
|
||||||
minimal_aranges[++j] = Aranges[i];
|
minimal_aranges[++j] = Aranges[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert (j+1 == minimal_size);
|
assert(j+1 == minimal_size);
|
||||||
|
|
||||||
// Now swap our new minimal aranges into place. The local
|
// Now swap our new minimal aranges into place. The local
|
||||||
// minimal_aranges will then contian the old big collection
|
// minimal_aranges will then contian the old big collection
|
||||||
@ -182,14 +173,15 @@ uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const {
|
|||||||
Range range(Address);
|
Range range(Address);
|
||||||
RangeCollIterator begin = Aranges.begin();
|
RangeCollIterator begin = Aranges.begin();
|
||||||
RangeCollIterator end = Aranges.end();
|
RangeCollIterator end = Aranges.end();
|
||||||
RangeCollIterator pos = std::lower_bound(begin, end, range, RangeLessThan);
|
RangeCollIterator pos =
|
||||||
|
std::lower_bound(begin, end, range);
|
||||||
|
|
||||||
if (pos != end && pos->LoPC <= Address && Address < pos->HiPC()) {
|
if (pos != end && pos->containsAddress(Address)) {
|
||||||
return pos->Offset;
|
return pos->CUOffset;
|
||||||
} else if (pos != begin) {
|
} else if (pos != begin) {
|
||||||
--pos;
|
--pos;
|
||||||
if (pos->LoPC <= Address && Address < pos->HiPC())
|
if (pos->containsAddress(Address))
|
||||||
return (*pos).Offset;
|
return pos->CUOffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1U;
|
return -1U;
|
||||||
|
@ -21,44 +21,39 @@ class DWARFContext;
|
|||||||
class DWARFDebugAranges {
|
class DWARFDebugAranges {
|
||||||
public:
|
public:
|
||||||
struct Range {
|
struct Range {
|
||||||
explicit Range(uint64_t lo = -1ULL, uint64_t hi = -1ULL,
|
explicit Range(uint64_t LowPC = -1ULL, uint64_t HighPC = -1ULL,
|
||||||
uint32_t off = -1U)
|
uint32_t CUOffset = -1U)
|
||||||
: LoPC(lo), Length(hi-lo), Offset(off) {}
|
: LowPC(LowPC), Length(HighPC - LowPC), CUOffset(CUOffset) {}
|
||||||
|
|
||||||
void clear() {
|
void setHighPC(uint64_t HighPC) {
|
||||||
LoPC = -1ULL;
|
if (HighPC == -1ULL || HighPC <= LowPC)
|
||||||
Length = 0;
|
|
||||||
Offset = -1U;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHiPC(uint64_t HiPC) {
|
|
||||||
if (HiPC == -1ULL || HiPC <= LoPC)
|
|
||||||
Length = 0;
|
Length = 0;
|
||||||
else
|
else
|
||||||
Length = HiPC - LoPC;
|
Length = HighPC - LowPC;
|
||||||
}
|
}
|
||||||
uint64_t HiPC() const {
|
uint64_t HighPC() const {
|
||||||
if (Length)
|
if (Length)
|
||||||
return LoPC + Length;
|
return LowPC + Length;
|
||||||
return -1ULL;
|
return -1ULL;
|
||||||
}
|
}
|
||||||
bool isValidRange() const { return Length > 0; }
|
bool containsAddress(uint64_t Address) const {
|
||||||
|
return LowPC <= Address && Address < HighPC();
|
||||||
static bool SortedOverlapCheck(const Range &curr_range,
|
|
||||||
const Range &next_range, uint32_t n) {
|
|
||||||
if (curr_range.Offset != next_range.Offset)
|
|
||||||
return false;
|
|
||||||
return curr_range.HiPC() + n >= next_range.LoPC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool contains(const Range &range) const {
|
bool operator <(const Range &other) const {
|
||||||
return LoPC <= range.LoPC && range.HiPC() <= HiPC();
|
return LowPC < other.LowPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool SortedOverlapCheck(const Range &Left, const Range &Right) {
|
||||||
|
if (Left.CUOffset != Right.CUOffset)
|
||||||
|
return false;
|
||||||
|
return Left.HighPC() >= Right.LowPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS) const;
|
||||||
uint64_t LoPC; // Start of address range
|
uint64_t LowPC; // Start of address range.
|
||||||
uint32_t Length; // End of address range (not including this address)
|
uint32_t Length; // End of address range (not including this address).
|
||||||
uint32_t Offset; // Offset of the compile unit or die
|
uint32_t CUOffset; // Offset of the compile unit or die.
|
||||||
};
|
};
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
@ -68,9 +63,9 @@ public:
|
|||||||
void extract(DataExtractor DebugArangesData);
|
void extract(DataExtractor DebugArangesData);
|
||||||
void generate(DWARFContext *CTX);
|
void generate(DWARFContext *CTX);
|
||||||
|
|
||||||
// Use appendRange multiple times and then call sort.
|
// Use appendRange multiple times and then call sortAndMinimize.
|
||||||
void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
|
void appendRange(uint32_t CUOffset, uint64_t LowPC, uint64_t HighPC);
|
||||||
void sort(bool Minimize, uint32_t OverlapSize);
|
void sortAndMinimize();
|
||||||
|
|
||||||
void dump(raw_ostream &OS) const;
|
void dump(raw_ostream &OS) const;
|
||||||
uint32_t findAddress(uint64_t Address) const;
|
uint32_t findAddress(uint64_t Address) const;
|
||||||
|
Reference in New Issue
Block a user