[turbofan] Greedy: faster compile time.
Avoiding unnecessarily traversing conflicts when doing weight comparisons. This reduced compile time regressions from a few multiples to under 10% - at least for zlib. Review URL: https://codereview.chromium.org/1346263004 Cr-Commit-Position: refs/heads/master@{#30783}
This commit is contained in:
parent
7a88581351
commit
1145090ad5
@ -338,12 +338,14 @@ void GreedyAllocator::TryAllocateLiveRange(LiveRange* range) {
|
||||
int hinted_reg = -1;
|
||||
|
||||
EnsureValidRangeWeight(range);
|
||||
DCHECK(range->weight() != LiveRange::kInvalidWeight);
|
||||
float competing_weight = range->weight();
|
||||
DCHECK(competing_weight != LiveRange::kInvalidWeight);
|
||||
|
||||
// Can we allocate at the hinted register?
|
||||
if (range->FirstHintPosition(&hinted_reg) != nullptr) {
|
||||
DCHECK(hinted_reg >= 0);
|
||||
float max_conflict_weight = GetMaximumConflictingWeight(hinted_reg, range);
|
||||
float max_conflict_weight =
|
||||
GetMaximumConflictingWeight(hinted_reg, range, competing_weight);
|
||||
if (max_conflict_weight == LiveRange::kInvalidWeight) {
|
||||
free_reg = hinted_reg;
|
||||
} else if (max_conflict_weight < range->weight()) {
|
||||
@ -361,7 +363,8 @@ void GreedyAllocator::TryAllocateLiveRange(LiveRange* range) {
|
||||
for (int i = 0; i < num_registers(); i++) {
|
||||
// Skip unnecessarily re-visiting the hinted register, if any.
|
||||
if (i == hinted_reg) continue;
|
||||
float max_conflict_weight = GetMaximumConflictingWeight(i, range);
|
||||
float max_conflict_weight =
|
||||
GetMaximumConflictingWeight(i, range, competing_weight);
|
||||
if (max_conflict_weight == LiveRange::kInvalidWeight) {
|
||||
free_reg = i;
|
||||
break;
|
||||
@ -482,15 +485,16 @@ void GreedyAllocator::AllocateRegisters() {
|
||||
|
||||
|
||||
float GreedyAllocator::GetMaximumConflictingWeight(
|
||||
unsigned reg_id, const LiveRange* range) const {
|
||||
unsigned reg_id, const LiveRange* range, float competing_weight) const {
|
||||
float ret = LiveRange::kInvalidWeight;
|
||||
|
||||
auto conflicts = current_allocations(reg_id)->GetConflicts(range);
|
||||
for (LiveRange* conflict = conflicts.Current(); conflict != nullptr;
|
||||
conflict = conflicts.GetNext()) {
|
||||
DCHECK_NE(conflict->weight(), LiveRange::kInvalidWeight);
|
||||
if (competing_weight <= conflict->weight()) return LiveRange::kMaxWeight;
|
||||
ret = Max(ret, conflict->weight());
|
||||
if (ret == LiveRange::kMaxWeight) return ret;
|
||||
DCHECK(ret < LiveRange::kMaxWeight);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -503,7 +507,8 @@ float GreedyAllocator::GetMaximumConflictingWeight(unsigned reg_id,
|
||||
float ret = LiveRange::kInvalidWeight;
|
||||
|
||||
for (LiveRange* member : group->ranges()) {
|
||||
float member_conflict_weight = GetMaximumConflictingWeight(reg_id, member);
|
||||
float member_conflict_weight =
|
||||
GetMaximumConflictingWeight(reg_id, member, group_weight);
|
||||
if (member_conflict_weight == LiveRange::kMaxWeight) {
|
||||
return LiveRange::kMaxWeight;
|
||||
}
|
||||
|
@ -148,8 +148,8 @@ class GreedyAllocator final : public RegisterAllocator {
|
||||
|
||||
// Returns kInvalidWeight if there are no conflicts, or the largest weight of
|
||||
// a range conflicting with the given range, at the given register.
|
||||
float GetMaximumConflictingWeight(unsigned reg_id,
|
||||
const LiveRange* range) const;
|
||||
float GetMaximumConflictingWeight(unsigned reg_id, const LiveRange* range,
|
||||
float competing_weight) const;
|
||||
|
||||
// Returns kInvalidWeight if there are no conflicts, or the largest weight of
|
||||
// a range conflicting with the given range, at the given register.
|
||||
|
Loading…
Reference in New Issue
Block a user