Commit 969a0775 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by Commit Bot

[regalloc] Optimize FindFreeRegistersForRange

Sort inactive live ranges by their assigned register and by their next
start. This allows {FindFreeRegistersForRange} to stop the search earlier
and significantly reduces compile time for some test cases.

R=sigurds@chromium.org
CC=neis@chromium.org

Bug: chromium:974804, v8:9529
Change-Id: I85e2ff8acf2c02ea0539c89daae5a427da775c2c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1795350
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63722}
parent afd83c07
This diff is collapsed.
......@@ -626,9 +626,10 @@ class V8_EXPORT_PRIVATE LiveRange : public NON_EXPORTED_BASE(ZoneObject) {
bool ShouldBeAllocatedBefore(const LiveRange* other) const;
bool CanCover(LifetimePosition position) const;
bool Covers(LifetimePosition position) const;
LifetimePosition NextStartAfter(LifetimePosition position) const;
LifetimePosition NextStartAfter(LifetimePosition position);
LifetimePosition NextEndAfter(LifetimePosition position) const;
LifetimePosition FirstIntersection(LiveRange* other) const;
LifetimePosition NextStart() const { return next_start_; }
void VerifyChildStructure() const {
VerifyIntervals();
......@@ -689,6 +690,8 @@ class V8_EXPORT_PRIVATE LiveRange : public NON_EXPORTED_BASE(ZoneObject) {
// Cache the last position splintering stopped at.
mutable UsePosition* splitting_pointer_;
LiveRangeBundle* bundle_ = nullptr;
// Next interval start, relative to the current linear scan position.
LifetimePosition next_start_;
DISALLOW_COPY_AND_ASSIGN(LiveRange);
};
......@@ -1309,16 +1312,28 @@ class LinearScanAllocator final : public RegisterAllocator {
const InstructionBlock* block);
bool HasNonDeferredPredecessor(InstructionBlock* block);
struct LiveRangeOrdering {
struct UnhandledLiveRangeOrdering {
bool operator()(const LiveRange* a, const LiveRange* b) const {
return a->ShouldBeAllocatedBefore(b);
}
};
using LiveRangeQueue = ZoneMultiset<LiveRange*, LiveRangeOrdering>;
LiveRangeQueue& unhandled_live_ranges() { return unhandled_live_ranges_; }
struct InactiveLiveRangeOrdering {
bool operator()(const LiveRange* a, const LiveRange* b) const {
return a->NextStart() < b->NextStart();
}
};
using UnhandledLiveRangeQueue =
ZoneMultiset<LiveRange*, UnhandledLiveRangeOrdering>;
using InactiveLiveRangeQueue =
ZoneMultiset<LiveRange*, InactiveLiveRangeOrdering>;
UnhandledLiveRangeQueue& unhandled_live_ranges() {
return unhandled_live_ranges_;
}
ZoneVector<LiveRange*>& active_live_ranges() { return active_live_ranges_; }
ZoneVector<LiveRange*>& inactive_live_ranges() {
return inactive_live_ranges_;
InactiveLiveRangeQueue& inactive_live_ranges(int reg) {
return inactive_live_ranges_[reg];
}
void SetLiveRangeAssignedRegister(LiveRange* range, int reg);
......@@ -1331,10 +1346,10 @@ class LinearScanAllocator final : public RegisterAllocator {
ZoneVector<LiveRange*>::iterator it);
ZoneVector<LiveRange*>::iterator ActiveToInactive(
ZoneVector<LiveRange*>::iterator it, LifetimePosition position);
ZoneVector<LiveRange*>::iterator InactiveToHandled(
ZoneVector<LiveRange*>::iterator it);
ZoneVector<LiveRange*>::iterator InactiveToActive(
ZoneVector<LiveRange*>::iterator it, LifetimePosition position);
InactiveLiveRangeQueue::iterator InactiveToHandled(
InactiveLiveRangeQueue::iterator it);
InactiveLiveRangeQueue::iterator InactiveToActive(
InactiveLiveRangeQueue::iterator it, LifetimePosition position);
void ForwardStateTo(LifetimePosition position);
......@@ -1384,9 +1399,9 @@ class LinearScanAllocator final : public RegisterAllocator {
void PrintRangeOverview(std::ostream& os);
LiveRangeQueue unhandled_live_ranges_;
UnhandledLiveRangeQueue unhandled_live_ranges_;
ZoneVector<LiveRange*> active_live_ranges_;
ZoneVector<LiveRange*> inactive_live_ranges_;
ZoneVector<InactiveLiveRangeQueue> inactive_live_ranges_;
// Approximate at what position the set of ranges will change next.
// Used to avoid scanning for updates even if none are present.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment