reg_alloc: Differentiate between ReadLock and WriteLock
This commit is contained in:
parent
6c3df057fa
commit
13ac0c234e
2 changed files with 15 additions and 11 deletions
|
@ -124,7 +124,7 @@ HostLoc RegAlloc::UseHostLocReg(IR::Inst* use_inst, HostLocList desired_location
|
||||||
|
|
||||||
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) {
|
if (can_use_current_location) {
|
||||||
LocInfo(current_location).Lock();
|
LocInfo(current_location).ReadLock();
|
||||||
return current_location;
|
return current_location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ HostLoc RegAlloc::UseHostLocReg(IR::Inst* use_inst, HostLocList desired_location
|
||||||
MoveOutOfTheWay(destination_location);
|
MoveOutOfTheWay(destination_location);
|
||||||
Move(destination_location, current_location);
|
Move(destination_location, current_location);
|
||||||
}
|
}
|
||||||
LocInfo(destination_location).Lock();
|
LocInfo(destination_location).ReadLock();
|
||||||
return destination_location;
|
return destination_location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,21 +169,21 @@ HostLoc RegAlloc::UseScratchHostLocReg(IR::Inst* use_inst, HostLocList desired_l
|
||||||
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()) {
|
||||||
MoveOutOfTheWay(current_location);
|
MoveOutOfTheWay(current_location);
|
||||||
LocInfo(current_location).Lock();
|
LocInfo(current_location).WriteLock();
|
||||||
return current_location;
|
return current_location;
|
||||||
}
|
}
|
||||||
|
|
||||||
const HostLoc destination_location = SelectARegister(desired_locations);
|
const HostLoc destination_location = SelectARegister(desired_locations);
|
||||||
MoveOutOfTheWay(destination_location);
|
MoveOutOfTheWay(destination_location);
|
||||||
CopyToScratch(destination_location, current_location);
|
CopyToScratch(destination_location, current_location);
|
||||||
LocInfo(destination_location).Lock();
|
LocInfo(destination_location).WriteLock();
|
||||||
return destination_location;
|
return destination_location;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostLoc RegAlloc::ScratchHostLocReg(HostLocList desired_locations) {
|
HostLoc RegAlloc::ScratchHostLocReg(HostLocList desired_locations) {
|
||||||
HostLoc location = SelectARegister(desired_locations);
|
HostLoc location = SelectARegister(desired_locations);
|
||||||
MoveOutOfTheWay(location);
|
MoveOutOfTheWay(location);
|
||||||
LocInfo(location).Lock();
|
LocInfo(location).WriteLock();
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,11 +261,7 @@ void RegAlloc::SpillRegister(HostLoc loc) {
|
||||||
ASSERT_MSG(!LocInfo(loc).IsLocked(), "Registers that have been allocated must not be spilt");
|
ASSERT_MSG(!LocInfo(loc).IsLocked(), "Registers that have been allocated must not be spilt");
|
||||||
|
|
||||||
HostLoc new_loc = FindFreeSpill();
|
HostLoc new_loc = FindFreeSpill();
|
||||||
|
Move(new_loc, loc);
|
||||||
EmitMove(code, new_loc, loc);
|
|
||||||
|
|
||||||
LocInfo(new_loc) = LocInfo(loc);
|
|
||||||
LocInfo(loc) = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HostLoc RegAlloc::FindFreeSpill() const {
|
HostLoc RegAlloc::FindFreeSpill() const {
|
||||||
|
|
|
@ -38,9 +38,15 @@ public:
|
||||||
return std::find(values.begin(), values.end(), inst) != values.end();
|
return std::find(values.begin(), values.end(), inst) != values.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lock() {
|
void ReadLock() {
|
||||||
|
ASSERT(!is_scratch);
|
||||||
is_being_used = true;
|
is_being_used = true;
|
||||||
}
|
}
|
||||||
|
void WriteLock() {
|
||||||
|
ASSERT(!is_being_used);
|
||||||
|
is_being_used = true;
|
||||||
|
is_scratch = true;
|
||||||
|
}
|
||||||
void AddValue(IR::Inst* inst) {
|
void AddValue(IR::Inst* inst) {
|
||||||
values.push_back(inst);
|
values.push_back(inst);
|
||||||
}
|
}
|
||||||
|
@ -50,11 +56,13 @@ public:
|
||||||
values.erase(to_erase, values.end());
|
values.erase(to_erase, values.end());
|
||||||
|
|
||||||
is_being_used = false;
|
is_being_used = false;
|
||||||
|
is_scratch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<IR::Inst*> values;
|
std::vector<IR::Inst*> values;
|
||||||
bool is_being_used = false;
|
bool is_being_used = false;
|
||||||
|
bool is_scratch = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RegAlloc final {
|
class RegAlloc final {
|
||||||
|
|
Loading…
Reference in a new issue