merge s6 and sp in variable naming pass

This commit is contained in:
water111
2021-12-28 20:45:45 -05:00
parent 696a6d87be
commit 33829b8dd3
9 changed files with 52 additions and 50 deletions
+19
View File
@@ -86,6 +86,14 @@ void VarMapSSA::merge(const VarSSA& var_a, const VarSSA& var_b) {
}
}
void VarMapSSA::merge_reg(Register reg) {
for (auto& entry : m_entries) {
if (entry.reg == reg) {
entry.var_id = 0;
}
}
}
/*!
* Make all Bs A.
*/
@@ -491,6 +499,13 @@ std::string SSA::print() const {
return result;
}
/*!
* Merge all variables in the same register to the given register.
*/
void SSA::merge_reg_to_single_variable(Register reg) {
map.merge_reg(reg);
}
/*!
* Simplify the SSA while still keeping it in SSA form.
* This does only a single pass of simplifications and returns true if it made changes.
@@ -1070,6 +1085,10 @@ std::optional<VariableNames> run_variable_renaming(const Function& function,
fmt::print("Simplified SSA\n{}-------------------------------\n", ssa.print());
}
// merge special registers
ssa.merge_reg_to_single_variable(Register(Reg::GPR, Reg::SP));
ssa.merge_reg_to_single_variable(Register(Reg::GPR, Reg::S6));
// remember what the SSA mapping was:
auto ssa_mapping = ssa.get_ssa_mapping();