reg_alloc: Add IsLastUse optimization for UseScratch

This commit is contained in:
MerryMage 2017-11-27 19:41:22 +00:00
parent 6b122751fe
commit 639f7cfd2d

View file

@ -81,7 +81,7 @@ bool HostLocInfo::IsEmpty() const {
} }
bool HostLocInfo::IsLastUse() const { bool HostLocInfo::IsLastUse() const {
return !is_being_used && current_references == 1; return !is_being_used && current_references == 1 && accumulated_uses + 1 == total_uses;
} }
bool HostLocInfo::ContainsValue(const IR::Inst* inst) const { bool HostLocInfo::ContainsValue(const IR::Inst* inst) const {
@ -283,7 +283,9 @@ HostLoc RegAlloc::UseScratchImpl(IR::Value use_value, HostLocList desired_locati
const bool can_use_current_location = std::find(desired_locations.begin(), desired_locations.end(), current_location) != desired_locations.end(); const bool can_use_current_location = std::find(desired_locations.begin(), desired_locations.end(), current_location) != desired_locations.end();
if (can_use_current_location && !LocInfo(current_location).IsLocked()) { if (can_use_current_location && !LocInfo(current_location).IsLocked()) {
if (!LocInfo(current_location).IsLastUse()) {
MoveOutOfTheWay(current_location); MoveOutOfTheWay(current_location);
}
LocInfo(current_location).WriteLock(); LocInfo(current_location).WriteLock();
return current_location; return current_location;
} }