From 7da34b965090a298d65fbf610e28f65e061dd4db Mon Sep 17 00:00:00 2001 From: Tobias Tebbi Date: Mon, 2 Jul 2018 14:53:44 +0200 Subject: [PATCH] [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 Commit-Queue: Tobias Tebbi Cr-Commit-Position: refs/heads/master@{#54142} --- src/compiler/register-allocator.cc | 17 ++++------------- src/compiler/register-allocator.h | 6 ++---- src/zone/zone-containers.h | 11 +++++++++++ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/compiler/register-allocator.cc b/src/compiler/register-allocator.cc index d1d67fee2a..7c78567b08 100644 --- a/src/compiler/register-allocator.cc +++ b/src/compiler/register-allocator.cc @@ -2742,19 +2742,10 @@ const char* RegisterAllocator::RegisterName(int register_code) const { } } -// static -LinearScanAllocator::LiveRangeQueue LinearScanAllocator::MakeLiveRangeQueue( - size_t capacity, Zone* local_zone) { - ZoneVector 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(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); } diff --git a/src/compiler/register-allocator.h b/src/compiler/register-allocator.h index 8612a967a3..b5286e8e95 100644 --- a/src/compiler/register-allocator.h +++ b/src/compiler/register-allocator.h @@ -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, - LiveRangeOrdering>; - static LiveRangeQueue MakeLiveRangeQueue(size_t capacity, Zone* local_zone); + using LiveRangeQueue = ZoneMultiset; LiveRangeQueue& unhandled_live_ranges() { return unhandled_live_ranges_; } ZoneVector& active_live_ranges() { return active_live_ranges_; } ZoneVector& inactive_live_ranges() { diff --git a/src/zone/zone-containers.h b/src/zone/zone-containers.h index c899bf340d..1988826779 100644 --- a/src/zone/zone-containers.h +++ b/src/zone/zone-containers.h @@ -129,6 +129,17 @@ class ZoneSet : public std::set> { ZoneAllocator(zone)) {} }; +// A wrapper subclass for std::multiset to make it easy to construct one that +// uses a zone allocator. +template > +class ZoneMultiset : public std::multiset> { + public: + // Constructs an empty set. + explicit ZoneMultiset(Zone* zone) + : std::multiset>(Compare(), + ZoneAllocator(zone)) {} +}; + // A wrapper subclass for std::map to make it easy to construct one that uses // a zone allocator. template >