[compiler] register allocator: Replace std::priority_queue with std::multiset

This should restore the old behavior of giving low priority to
newly-added live ranges.

Bug: chromium:859021
Change-Id: If22c9a1d0897d82623eb141fa03c30110e68bfc4
Reviewed-on: https://chromium-review.googlesource.com/1122402
Reviewed-by: Stephan Herhut <herhut@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54142}
This commit is contained in:
Tobias Tebbi 2018-07-02 14:53:44 +02:00 committed by Commit Bot
parent f52f66e541
commit 7da34b9650
3 changed files with 17 additions and 17 deletions

View File

@ -2742,19 +2742,10 @@ const char* RegisterAllocator::RegisterName(int register_code) const {
}
}
// static
LinearScanAllocator::LiveRangeQueue LinearScanAllocator::MakeLiveRangeQueue(
size_t capacity, Zone* local_zone) {
ZoneVector<LiveRange*> backing_store(local_zone);
backing_store.reserve(capacity);
return LiveRangeQueue(LiveRangeOrdering(), std::move(backing_store));
}
LinearScanAllocator::LinearScanAllocator(RegisterAllocationData* data,
RegisterKind kind, Zone* local_zone)
: RegisterAllocator(data, kind),
unhandled_live_ranges_(MakeLiveRangeQueue(
static_cast<size_t>(code()->VirtualRegisterCount() * 2), local_zone)),
unhandled_live_ranges_(local_zone),
active_live_ranges_(local_zone),
inactive_live_ranges_(local_zone) {
active_live_ranges().reserve(8);
@ -2805,8 +2796,8 @@ void LinearScanAllocator::AllocateRegisters() {
}
while (!unhandled_live_ranges().empty()) {
LiveRange* current = unhandled_live_ranges().top();
unhandled_live_ranges().pop();
LiveRange* current = *unhandled_live_ranges().begin();
unhandled_live_ranges().erase(unhandled_live_ranges().begin());
LifetimePosition position = current->Start();
#ifdef DEBUG
allocation_finger_ = position;
@ -2897,7 +2888,7 @@ void LinearScanAllocator::AddToUnhandled(LiveRange* range) {
TRACE("Add live range %d:%d to unhandled\n", range->TopLevel()->vreg(),
range->relative_id());
unhandled_live_ranges().push(range);
unhandled_live_ranges().insert(range);
}

View File

@ -1042,12 +1042,10 @@ class LinearScanAllocator final : public RegisterAllocator {
private:
struct LiveRangeOrdering {
bool operator()(LiveRange* a, LiveRange* b) {
return b->ShouldBeAllocatedBefore(a);
return a->ShouldBeAllocatedBefore(b);
}
};
using LiveRangeQueue = std::priority_queue<LiveRange*, ZoneVector<LiveRange*>,
LiveRangeOrdering>;
static LiveRangeQueue MakeLiveRangeQueue(size_t capacity, Zone* local_zone);
using LiveRangeQueue = ZoneMultiset<LiveRange*, LiveRangeOrdering>;
LiveRangeQueue& unhandled_live_ranges() { return unhandled_live_ranges_; }
ZoneVector<LiveRange*>& active_live_ranges() { return active_live_ranges_; }
ZoneVector<LiveRange*>& inactive_live_ranges() {

View File

@ -129,6 +129,17 @@ class ZoneSet : public std::set<K, Compare, ZoneAllocator<K>> {
ZoneAllocator<K>(zone)) {}
};
// A wrapper subclass for std::multiset to make it easy to construct one that
// uses a zone allocator.
template <typename K, typename Compare = std::less<K>>
class ZoneMultiset : public std::multiset<K, Compare, ZoneAllocator<K>> {
public:
// Constructs an empty set.
explicit ZoneMultiset(Zone* zone)
: std::multiset<K, Compare, ZoneAllocator<K>>(Compare(),
ZoneAllocator<K>(zone)) {}
};
// A wrapper subclass for std::map to make it easy to construct one that uses
// a zone allocator.
template <typename K, typename V, typename Compare = std::less<K>>