| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/greedy-allocator.h" | 5 #include "src/compiler/greedy-allocator.h" |
| 6 #include "src/compiler/register-allocator.h" | 6 #include "src/compiler/register-allocator.h" |
| 7 | 7 |
| 8 namespace v8 { | 8 namespace v8 { |
| 9 namespace internal { | 9 namespace internal { |
| 10 namespace compiler { | 10 namespace compiler { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 void GreedyAllocator::TryAllocateGroup(LiveRangeGroup* group) { | 242 void GreedyAllocator::TryAllocateGroup(LiveRangeGroup* group) { |
| 243 float group_weight = 0.0; | 243 float group_weight = 0.0; |
| 244 for (LiveRange* member : group->ranges()) { | 244 for (LiveRange* member : group->ranges()) { |
| 245 EnsureValidRangeWeight(member); | 245 EnsureValidRangeWeight(member); |
| 246 group_weight = Max(group_weight, member->weight()); | 246 group_weight = Max(group_weight, member->weight()); |
| 247 } | 247 } |
| 248 | 248 |
| 249 float eviction_weight = group_weight; | 249 float eviction_weight = group_weight; |
| 250 int eviction_reg = -1; | 250 int eviction_reg = -1; |
| 251 int free_reg = -1; | 251 int free_reg = -1; |
| 252 for (int i = 0; i < num_allocatable_registers(); ++i) { | 252 for (int reg = 0; reg < num_registers(); ++reg) { |
| 253 int reg = allocatable_register_code(i); | |
| 254 float weight = GetMaximumConflictingWeight(reg, group, group_weight); | 253 float weight = GetMaximumConflictingWeight(reg, group, group_weight); |
| 255 if (weight == LiveRange::kInvalidWeight) { | 254 if (weight == LiveRange::kInvalidWeight) { |
| 256 free_reg = reg; | 255 free_reg = reg; |
| 257 break; | 256 break; |
| 258 } | 257 } |
| 259 if (weight < eviction_weight) { | 258 if (weight < eviction_weight) { |
| 260 eviction_weight = weight; | 259 eviction_weight = weight; |
| 261 eviction_reg = reg; | 260 eviction_reg = reg; |
| 262 } | 261 } |
| 263 } | 262 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 306 } |
| 308 } | 307 } |
| 309 | 308 |
| 310 if (free_reg < 0 && evictable_reg < 0) { | 309 if (free_reg < 0 && evictable_reg < 0) { |
| 311 // There was no hinted reg, or we cannot allocate there. | 310 // There was no hinted reg, or we cannot allocate there. |
| 312 float smallest_weight = LiveRange::kMaxWeight; | 311 float smallest_weight = LiveRange::kMaxWeight; |
| 313 | 312 |
| 314 // Seek either the first free register, or, from the set of registers | 313 // Seek either the first free register, or, from the set of registers |
| 315 // where the maximum conflict is lower than the candidate's weight, the one | 314 // where the maximum conflict is lower than the candidate's weight, the one |
| 316 // with the smallest such weight. | 315 // with the smallest such weight. |
| 317 for (int i = 0; i < num_allocatable_registers(); i++) { | 316 for (int i = 0; i < num_registers(); i++) { |
| 318 int reg = allocatable_register_code(i); | |
| 319 // Skip unnecessarily re-visiting the hinted register, if any. | 317 // Skip unnecessarily re-visiting the hinted register, if any. |
| 320 if (reg == hinted_reg) continue; | 318 if (i == hinted_reg) continue; |
| 321 float max_conflict_weight = | 319 float max_conflict_weight = |
| 322 GetMaximumConflictingWeight(reg, range, competing_weight); | 320 GetMaximumConflictingWeight(i, range, competing_weight); |
| 323 if (max_conflict_weight == LiveRange::kInvalidWeight) { | 321 if (max_conflict_weight == LiveRange::kInvalidWeight) { |
| 324 free_reg = reg; | 322 free_reg = i; |
| 325 break; | 323 break; |
| 326 } | 324 } |
| 327 if (max_conflict_weight < range->weight() && | 325 if (max_conflict_weight < range->weight() && |
| 328 max_conflict_weight < smallest_weight) { | 326 max_conflict_weight < smallest_weight) { |
| 329 smallest_weight = max_conflict_weight; | 327 smallest_weight = max_conflict_weight; |
| 330 evictable_reg = reg; | 328 evictable_reg = i; |
| 331 } | 329 } |
| 332 } | 330 } |
| 333 } | 331 } |
| 334 | 332 |
| 335 // We have a free register, so we use it. | 333 // We have a free register, so we use it. |
| 336 if (free_reg >= 0) { | 334 if (free_reg >= 0) { |
| 337 TRACE("Found free register %s for live range %d:%d.\n", | 335 TRACE("Found free register %s for live range %d:%d.\n", |
| 338 RegisterName(free_reg), range->TopLevel()->vreg(), | 336 RegisterName(free_reg), range->TopLevel()->vreg(), |
| 339 range->relative_id()); | 337 range->relative_id()); |
| 340 AssignRangeToRegister(free_reg, range); | 338 AssignRangeToRegister(free_reg, range); |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 668 |
| 671 | 669 |
| 672 bool GreedyAllocator::IsProgressPossible(const LiveRange* range) { | 670 bool GreedyAllocator::IsProgressPossible(const LiveRange* range) { |
| 673 return range->CanBeSpilled(range->Start()) || | 671 return range->CanBeSpilled(range->Start()) || |
| 674 GetLastResortSplitPosition(range).IsValid(); | 672 GetLastResortSplitPosition(range).IsValid(); |
| 675 } | 673 } |
| 676 | 674 |
| 677 } // namespace compiler | 675 } // namespace compiler |
| 678 } // namespace internal | 676 } // namespace internal |
| 679 } // namespace v8 | 677 } // namespace v8 |
| OLD | NEW |