Index: src/compiler/greedy-allocator.cc |
diff --git a/src/compiler/greedy-allocator.cc b/src/compiler/greedy-allocator.cc |
index 8d658c39ff4203bb420e7f184dd46f8634b1900f..2b82269d716a53a98d08eb59a9cd250f55b9b241 100644 |
--- a/src/compiler/greedy-allocator.cc |
+++ b/src/compiler/greedy-allocator.cc |
@@ -15,6 +15,9 @@ namespace compiler { |
} while (false) |
+const float GreedyAllocator::kAllocatedRangeMultiplier = 10.0; |
+ |
+ |
namespace { |
@@ -131,12 +134,10 @@ void GreedyAllocator::AssignRangeToRegister(int reg_id, LiveRange* range) { |
DCHECK(!range->HasRegisterAssigned()); |
- current_allocations(reg_id)->AllocateRange(range); |
+ AllocateRegisterToRange(reg_id, range); |
TRACE("Assigning %s to range %d\n", RegisterName(reg_id), range->id()); |
range->set_assigned_register(reg_id); |
- |
- DCHECK(current_allocations(reg_id)->VerifyAllocationsAreValid()); |
} |
@@ -153,7 +154,7 @@ void GreedyAllocator::PreallocateFixedRanges() { |
int reg_nr = fixed_range->assigned_register(); |
EnsureValidRangeWeight(fixed_range); |
- current_allocations(reg_nr)->AllocateRange(fixed_range); |
+ AllocateRegisterToRange(reg_nr, fixed_range); |
} |
} |
} |
@@ -190,8 +191,7 @@ void GreedyAllocator::TryAllocateLiveRange(LiveRange* range) { |
// where the maximum conflict is lower than the candidate's weight, the one |
// with the smallest such weight. |
for (int i = 0; i < num_registers(); i++) { |
- float max_conflict_weight = |
- current_allocations(i)->GetMaximumConflictingWeight(range); |
+ float max_conflict_weight = GetMaximumConflictingWeight(i, range); |
if (max_conflict_weight == LiveRange::kInvalidWeight) { |
free_reg = i; |
break; |
@@ -216,8 +216,7 @@ void GreedyAllocator::TryAllocateLiveRange(LiveRange* range) { |
if (evictable_reg >= 0) { |
TRACE("Found evictable register %s for live range %d\n", |
RegisterName(free_reg), range->id()); |
- current_allocations(evictable_reg) |
- ->EvictAndRescheduleConflicts(range, &scheduler()); |
+ EvictAndRescheduleConflicts(evictable_reg, range); |
AssignRangeToRegister(evictable_reg, range); |
return; |
} |
@@ -227,6 +226,19 @@ void GreedyAllocator::TryAllocateLiveRange(LiveRange* range) { |
} |
+void GreedyAllocator::EvictAndRescheduleConflicts(unsigned reg_id, |
+ const LiveRange* range) { |
+ current_allocations(reg_id)->RemoveConflicts(range, [this](LiveRange* range) { |
+ DCHECK(range->HasRegisterAssigned()); |
+ CHECK(!range->IsFixed()); |
+ range->UnsetAssignedRegister(); |
+ UpdateWeightAtEviction(range); |
+ scheduler().Schedule(range); |
+ TRACE("Evicted range %d.\n", range->id()); |
+ }); |
+} |
+ |
+ |
void GreedyAllocator::SplitAndSpillRangesDefinedByMemoryOperand() { |
size_t initial_range_count = data()->live_ranges().size(); |
for (size_t i = 0; i < initial_range_count; ++i) { |
@@ -298,6 +310,21 @@ void GreedyAllocator::AllocateRegisters() { |
} |
+float GreedyAllocator::GetMaximumConflictingWeight( |
+ unsigned reg_id, const LiveRange* range) const { |
+ float ret = LiveRange::kInvalidWeight; |
+ |
+ current_allocations(reg_id) |
+ ->VisitConflicts(range, [&ret](const LiveRange* conflict) { |
+ DCHECK_NE(conflict->weight(), LiveRange::kInvalidWeight); |
+ ret = Max(ret, conflict->weight()); |
+ return (ret != LiveRange::kMaxWeight); |
+ }); |
+ |
+ return ret; |
+} |
+ |
+ |
void GreedyAllocator::EnsureValidRangeWeight(LiveRange* range) { |
// The live range weight will be invalidated when ranges are created or split. |
// Otherwise, it is consistently updated when the range is allocated or |