Commit 1145090a authored by mtrofin's avatar mtrofin Committed by Commit bot

[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}
parent 7a885813
......@@ -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.
......
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