Commit 157c64f5 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] make live ranges stateless

this is necessary for the greedy allocator to use the relevant functions, as well as the sanity of someone looking at the code

BUG=

Review URL: https://codereview.chromium.org/1056063004

Cr-Commit-Position: refs/heads/master@{#28006}
parent f3ee83b6
...@@ -251,9 +251,11 @@ void LiveRange::CommitSpillOperand(AllocatedOperand* operand) { ...@@ -251,9 +251,11 @@ void LiveRange::CommitSpillOperand(AllocatedOperand* operand) {
} }
UsePosition* LiveRange::NextUsePosition(LifetimePosition start) { UsePosition* LiveRange::NextUsePosition(LifetimePosition start) const {
UsePosition* use_pos = last_processed_use_; UsePosition* use_pos = last_processed_use_;
if (use_pos == nullptr) use_pos = first_pos(); if (use_pos == nullptr || use_pos->pos().Value() > start.Value()) {
use_pos = first_pos();
}
while (use_pos != nullptr && use_pos->pos().Value() < start.Value()) { while (use_pos != nullptr && use_pos->pos().Value() < start.Value()) {
use_pos = use_pos->next(); use_pos = use_pos->next();
} }
...@@ -263,7 +265,7 @@ UsePosition* LiveRange::NextUsePosition(LifetimePosition start) { ...@@ -263,7 +265,7 @@ UsePosition* LiveRange::NextUsePosition(LifetimePosition start) {
UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial( UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial(
LifetimePosition start) { LifetimePosition start) const {
UsePosition* pos = NextUsePosition(start); UsePosition* pos = NextUsePosition(start);
while (pos != nullptr && !pos->RegisterIsBeneficial()) { while (pos != nullptr && !pos->RegisterIsBeneficial()) {
pos = pos->next(); pos = pos->next();
...@@ -273,7 +275,7 @@ UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial( ...@@ -273,7 +275,7 @@ UsePosition* LiveRange::NextUsePositionRegisterIsBeneficial(
UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial( UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial(
LifetimePosition start) { LifetimePosition start) const {
auto pos = first_pos(); auto pos = first_pos();
UsePosition* prev = nullptr; UsePosition* prev = nullptr;
while (pos != nullptr && pos->pos().Value() < start.Value()) { while (pos != nullptr && pos->pos().Value() < start.Value()) {
...@@ -284,7 +286,7 @@ UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial( ...@@ -284,7 +286,7 @@ UsePosition* LiveRange::PreviousUsePositionRegisterIsBeneficial(
} }
UsePosition* LiveRange::NextRegisterPosition(LifetimePosition start) { UsePosition* LiveRange::NextRegisterPosition(LifetimePosition start) const {
UsePosition* pos = NextUsePosition(start); UsePosition* pos = NextUsePosition(start);
while (pos != nullptr && pos->type() != UsePositionType::kRequiresRegister) { while (pos != nullptr && pos->type() != UsePositionType::kRequiresRegister) {
pos = pos->next(); pos = pos->next();
...@@ -293,7 +295,7 @@ UsePosition* LiveRange::NextRegisterPosition(LifetimePosition start) { ...@@ -293,7 +295,7 @@ UsePosition* LiveRange::NextRegisterPosition(LifetimePosition start) {
} }
bool LiveRange::CanBeSpilled(LifetimePosition pos) { bool LiveRange::CanBeSpilled(LifetimePosition pos) const {
// We cannot spill a live range that has a use requiring a register // We cannot spill a live range that has a use requiring a register
// at the current or the immediate next position. // at the current or the immediate next position.
auto use_pos = NextRegisterPosition(pos); auto use_pos = NextRegisterPosition(pos);
...@@ -571,7 +573,7 @@ bool LiveRange::CanCover(LifetimePosition position) const { ...@@ -571,7 +573,7 @@ bool LiveRange::CanCover(LifetimePosition position) const {
} }
bool LiveRange::Covers(LifetimePosition position) { bool LiveRange::Covers(LifetimePosition position) const {
if (!CanCover(position)) return false; if (!CanCover(position)) return false;
auto start_search = FirstSearchIntervalForPosition(position); auto start_search = FirstSearchIntervalForPosition(position);
for (auto interval = start_search; interval != nullptr; for (auto interval = start_search; interval != nullptr;
...@@ -586,7 +588,7 @@ bool LiveRange::Covers(LifetimePosition position) { ...@@ -586,7 +588,7 @@ bool LiveRange::Covers(LifetimePosition position) {
} }
LifetimePosition LiveRange::FirstIntersection(LiveRange* other) { LifetimePosition LiveRange::FirstIntersection(LiveRange* other) const {
auto b = other->first_interval(); auto b = other->first_interval();
if (b == nullptr) return LifetimePosition::Invalid(); if (b == nullptr) return LifetimePosition::Invalid();
auto advance_last_processed_up_to = b->start(); auto advance_last_processed_up_to = b->start();
......
...@@ -246,25 +246,24 @@ class LiveRange final : public ZoneObject { ...@@ -246,25 +246,24 @@ class LiveRange final : public ZoneObject {
// Returns use position in this live range that follows both start // Returns use position in this live range that follows both start
// and last processed use position. // and last processed use position.
// Modifies internal state of live range! UsePosition* NextUsePosition(LifetimePosition start) const;
UsePosition* NextUsePosition(LifetimePosition start);
// Returns use position for which register is required in this live // Returns use position for which register is required in this live
// range and which follows both start and last processed use position // range and which follows both start and last processed use position
// Modifies internal state of live range! UsePosition* NextRegisterPosition(LifetimePosition start) const;
UsePosition* NextRegisterPosition(LifetimePosition start);
// Returns use position for which register is beneficial in this live // Returns use position for which register is beneficial in this live
// range and which follows both start and last processed use position // range and which follows both start and last processed use position
// Modifies internal state of live range! UsePosition* NextUsePositionRegisterIsBeneficial(
UsePosition* NextUsePositionRegisterIsBeneficial(LifetimePosition start); LifetimePosition start) const;
// Returns use position for which register is beneficial in this live // Returns use position for which register is beneficial in this live
// range and which precedes start. // range and which precedes start.
UsePosition* PreviousUsePositionRegisterIsBeneficial(LifetimePosition start); UsePosition* PreviousUsePositionRegisterIsBeneficial(
LifetimePosition start) const;
// Can this live range be spilled at this position. // Can this live range be spilled at this position.
bool CanBeSpilled(LifetimePosition pos); bool CanBeSpilled(LifetimePosition pos) const;
// Split this live range at the given position which must follow the start of // Split this live range at the given position which must follow the start of
// the range. // the range.
...@@ -330,8 +329,8 @@ class LiveRange final : public ZoneObject { ...@@ -330,8 +329,8 @@ class LiveRange final : public ZoneObject {
bool ShouldBeAllocatedBefore(const LiveRange* other) const; bool ShouldBeAllocatedBefore(const LiveRange* other) const;
bool CanCover(LifetimePosition position) const; bool CanCover(LifetimePosition position) const;
bool Covers(LifetimePosition position); bool Covers(LifetimePosition position) const;
LifetimePosition FirstIntersection(LiveRange* other); LifetimePosition FirstIntersection(LiveRange* other) const;
// Add a new interval or a new use position to this live range. // Add a new interval or a new use position to this live range.
void EnsureInterval(LifetimePosition start, LifetimePosition end, Zone* zone); void EnsureInterval(LifetimePosition start, LifetimePosition end, Zone* zone);
...@@ -373,9 +372,10 @@ class LiveRange final : public ZoneObject { ...@@ -373,9 +372,10 @@ class LiveRange final : public ZoneObject {
LiveRange* next_; LiveRange* next_;
// This is used as a cache, it doesn't affect correctness. // This is used as a cache, it doesn't affect correctness.
mutable UseInterval* current_interval_; mutable UseInterval* current_interval_;
UsePosition* last_processed_use_; // This is used as a cache, it doesn't affect correctness.
mutable UsePosition* last_processed_use_;
// This is used as a cache, it's invalid outside of BuildLiveRanges. // This is used as a cache, it's invalid outside of BuildLiveRanges.
InstructionOperand* current_hint_operand_; mutable InstructionOperand* current_hint_operand_;
int spill_start_index_; int spill_start_index_;
SpillType spill_type_; SpillType spill_type_;
union { union {
......
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