| Index: src/compiler/register-allocator.cc
|
| diff --git a/src/compiler/register-allocator.cc b/src/compiler/register-allocator.cc
|
| index 3e1ac629417d6f5c8a66ccd425fc5f323df8730c..5970e97ec19737ba18da10d4e471cbedf5f0b304 100644
|
| --- a/src/compiler/register-allocator.cc
|
| +++ b/src/compiler/register-allocator.cc
|
| @@ -547,6 +547,7 @@ RegisterAllocator::RegisterAllocator(const RegisterConfiguration* config,
|
| spill_ranges_(8, local_zone()),
|
| mode_(UNALLOCATED_REGISTERS),
|
| num_registers_(-1),
|
| + first_register_to_try_(0),
|
| allocation_ok_(true) {
|
| DCHECK(this->config()->num_general_registers() <=
|
| RegisterConfiguration::kMaxGeneralRegisters);
|
| @@ -2061,6 +2062,20 @@ void RegisterAllocator::InactiveToActive(LiveRange* range) {
|
| }
|
|
|
|
|
| +// Pick the index of the maximum position, starting at offset start.
|
| +static int MaximalIndex(const LifetimePosition* positions, const uint8_t start,
|
| + const int count) {
|
| + int reg = start % count;
|
| + for (int i = 1; i < count; ++i) {
|
| + int index = (i + start) % count;
|
| + if (positions[index].Value() > positions[reg].Value()) {
|
| + reg = index;
|
| + }
|
| + }
|
| + return reg;
|
| +}
|
| +
|
| +
|
| bool RegisterAllocator::TryAllocateFreeReg(LiveRange* current) {
|
| LifetimePosition free_until_pos[RegisterConfiguration::kMaxDoubleRegisters];
|
|
|
| @@ -2102,13 +2117,8 @@ bool RegisterAllocator::TryAllocateFreeReg(LiveRange* current) {
|
| }
|
|
|
| // Find the register which stays free for the longest time.
|
| - int reg = 0;
|
| - for (int i = 1; i < RegisterCount(); ++i) {
|
| - if (free_until_pos[i].Value() > free_until_pos[reg].Value()) {
|
| - reg = i;
|
| - }
|
| - }
|
| -
|
| + int reg =
|
| + MaximalIndex(free_until_pos, first_register_to_try_++, RegisterCount());
|
| LifetimePosition pos = free_until_pos[reg];
|
|
|
| if (pos.Value() <= current->Start().Value()) {
|
| @@ -2183,13 +2193,7 @@ void RegisterAllocator::AllocateBlockedReg(LiveRange* current) {
|
| }
|
| }
|
|
|
| - int reg = 0;
|
| - for (int i = 1; i < RegisterCount(); ++i) {
|
| - if (use_pos[i].Value() > use_pos[reg].Value()) {
|
| - reg = i;
|
| - }
|
| - }
|
| -
|
| + int reg = MaximalIndex(use_pos, first_register_to_try_++, RegisterCount());
|
| LifetimePosition pos = use_pos[reg];
|
|
|
| if (pos.Value() < register_use->pos().Value()) {
|
|
|