reg_alloc: Remove unused functions

This commit is contained in:
MerryMage 2017-02-24 20:14:02 +00:00
parent 1ee4c07f14
commit 6c3df057fa
2 changed files with 9 additions and 56 deletions

View file

@ -101,27 +101,7 @@ std::tuple<OpArg, HostLoc> RegAlloc::UseDefOpArgHostLocReg(IR::Value use_value,
DEBUG_ASSERT_MSG(!ValueLocation(def_inst), "def_inst has already been defined"); DEBUG_ASSERT_MSG(!ValueLocation(def_inst), "def_inst has already been defined");
DEBUG_ASSERT_MSG(use_value.IsImmediate() || ValueLocation(use_value.GetInst()), "use_inst has not been defined"); DEBUG_ASSERT_MSG(use_value.IsImmediate() || ValueLocation(use_value.GetInst()), "use_inst has not been defined");
if (!use_value.IsImmediate()) { // TODO: IsLastUse optimization
const IR::Inst* use_inst = use_value.GetInst();
if (IsLastUse(use_inst)) {
HostLoc current_location = *ValueLocation(use_inst);
auto& loc_info = LocInfo(current_location);
if (!loc_info.IsIdle()) {
if (HostLocIsSpill(current_location)) {
loc_info.Lock();
DEBUG_ASSERT(loc_info.IsUse());
HostLoc location = ScratchHostLocReg(desired_locations);
DefineValue(def_inst, location);
return std::make_tuple(SpillToOpArg(current_location), location);
} else {
loc_info.Lock();
DefineValue(def_inst, current_location);
return std::make_tuple(HostLocToX64(current_location), current_location);
}
}
}
}
OpArg use_oparg = UseOpArg(use_value, any_gpr); OpArg use_oparg = UseOpArg(use_value, any_gpr);
HostLoc def_reg = ScratchHostLocReg(desired_locations); HostLoc def_reg = ScratchHostLocReg(desired_locations);
@ -247,7 +227,7 @@ HostLoc RegAlloc::SelectARegister(HostLocList desired_locations) const {
// Find all locations that have not been allocated.. // Find all locations that have not been allocated..
auto allocated_locs = std::partition(candidates.begin(), candidates.end(), [this](auto loc){ auto allocated_locs = std::partition(candidates.begin(), candidates.end(), [this](auto loc){
return !this->IsRegisterAllocated(loc); return !this->LocInfo(loc).IsLocked();
}); });
candidates.erase(allocated_locs, candidates.end()); candidates.erase(allocated_locs, candidates.end());
ASSERT_MSG(!candidates.empty(), "All candidate registers have already been allocated"); ASSERT_MSG(!candidates.empty(), "All candidate registers have already been allocated");
@ -256,7 +236,7 @@ HostLoc RegAlloc::SelectARegister(HostLocList desired_locations) const {
// TODO: Actually do LRU or something. Currently we just try to pick something without a value if possible. // TODO: Actually do LRU or something. Currently we just try to pick something without a value if possible.
std::partition(candidates.begin(), candidates.end(), [this](auto loc){ std::partition(candidates.begin(), candidates.end(), [this](auto loc){
return !this->IsRegisterOccupied(loc); return this->LocInfo(loc).IsEmpty();
}); });
return candidates.front(); return candidates.front();
@ -270,23 +250,6 @@ boost::optional<HostLoc> RegAlloc::ValueLocation(const IR::Inst* value) const {
return boost::none; return boost::none;
} }
bool RegAlloc::IsRegisterOccupied(HostLoc loc) const {
const auto& info = LocInfo(loc);
return !info.IsEmpty();
}
bool RegAlloc::IsRegisterAllocated(HostLoc loc) const {
return !LocInfo(loc).IsIdle();
}
bool RegAlloc::IsLastUse(const IR::Inst*) const {
//if (inst->UseCount() > 1)
// return false;
//return LocInfo(*ValueLocation(inst)).values.size() == 1;
return false;
}
void RegAlloc::DefineValue(IR::Inst* def_inst, HostLoc host_loc) { void RegAlloc::DefineValue(IR::Inst* def_inst, HostLoc host_loc) {
DEBUG_ASSERT_MSG(!ValueLocation(def_inst), "def_inst has already been defined"); DEBUG_ASSERT_MSG(!ValueLocation(def_inst), "def_inst has already been defined");
LocInfo(host_loc).AddValue(def_inst); LocInfo(host_loc).AddValue(def_inst);
@ -294,8 +257,8 @@ void RegAlloc::DefineValue(IR::Inst* def_inst, HostLoc host_loc) {
void RegAlloc::SpillRegister(HostLoc loc) { void RegAlloc::SpillRegister(HostLoc loc) {
ASSERT_MSG(HostLocIsRegister(loc), "Only registers can be spilled"); ASSERT_MSG(HostLocIsRegister(loc), "Only registers can be spilled");
ASSERT_MSG(IsRegisterOccupied(loc), "There is no need to spill unoccupied registers"); ASSERT_MSG(!LocInfo(loc).IsEmpty(), "There is no need to spill unoccupied registers");
ASSERT_MSG(!IsRegisterAllocated(loc), "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();
@ -307,7 +270,7 @@ void RegAlloc::SpillRegister(HostLoc loc) {
HostLoc RegAlloc::FindFreeSpill() const { HostLoc RegAlloc::FindFreeSpill() const {
for (size_t i = 0; i < SpillCount; i++) for (size_t i = 0; i < SpillCount; i++)
if (!IsRegisterOccupied(HostLocSpill(i))) if (LocInfo(HostLocSpill(i)).IsEmpty())
return HostLocSpill(i); return HostLocSpill(i);
ASSERT_MSG(false, "All spill locations are full"); ASSERT_MSG(false, "All spill locations are full");
@ -381,11 +344,10 @@ void RegAlloc::Exchange(HostLoc a, HostLoc b) {
void RegAlloc::MoveOutOfTheWay(HostLoc reg) { void RegAlloc::MoveOutOfTheWay(HostLoc reg) {
ASSERT(!LocInfo(reg).IsLocked()); ASSERT(!LocInfo(reg).IsLocked());
if (IsRegisterOccupied(reg)) { if (!LocInfo(reg).IsEmpty()) {
SpillRegister(reg); SpillRegister(reg);
} }
} }
} // namespace BackendX64 } // namespace BackendX64
} // namespace Dynarmic } // namespace Dynarmic

View file

@ -24,20 +24,14 @@ namespace BackendX64 {
struct HostLocInfo { struct HostLocInfo {
public: public:
bool IsIdle() const {
return !is_being_used;
}
bool IsLocked() const { bool IsLocked() const {
return is_being_used; return is_being_used;
} }
bool IsEmpty() const { bool IsEmpty() const {
return !is_being_used && values.empty(); return !is_being_used && values.empty();
} }
bool IsScratch() const { bool IsLastUse() const {
return is_being_used && values.empty(); return !is_being_used && std::all_of(values.begin(), values.end(), [](const auto& inst) { return !inst->HasUses(); });
}
bool IsUse() const {
return is_being_used && !values.empty();
} }
bool ContainsValue(const IR::Inst* inst) const { bool ContainsValue(const IR::Inst* inst) const {
@ -139,9 +133,6 @@ public:
private: private:
HostLoc SelectARegister(HostLocList desired_locations) const; HostLoc SelectARegister(HostLocList desired_locations) const;
boost::optional<HostLoc> ValueLocation(const IR::Inst* value) const; boost::optional<HostLoc> ValueLocation(const IR::Inst* value) const;
bool IsRegisterOccupied(HostLoc loc) const;
bool IsRegisterAllocated(HostLoc loc) const;
bool IsLastUse(const IR::Inst* inst) const;
void DefineValue(IR::Inst* def_inst, HostLoc host_loc); void DefineValue(IR::Inst* def_inst, HostLoc host_loc);