[decompiler] fix (gpr->fpr when an integer arg is converted to float (#482)

* fix gpr fpr bug

* remove unused variable
This commit is contained in:
water111
2021-05-14 14:33:08 -04:00
committed by GitHub
parent 60c670df3a
commit b3eb05e37f
12 changed files with 95 additions and 42 deletions
+6
View File
@@ -489,6 +489,12 @@ void Env::disable_def(const RegisterAccess& access, DecompWarnings& warnings) {
}
}
void Env::disable_use(const RegisterAccess& access) {
if (has_local_vars()) {
m_var_names.disable_use(access);
}
}
/*!
* Set the stack hints. This must be done before type analysis.
* This actually parses the types, so it should be done after the dts is set up.
+1 -5
View File
@@ -162,11 +162,7 @@ class Env {
const std::vector<StackVarEntry>& stack_var_hints() const { return m_stack_vars; }
const UseDefInfo& get_use_def_info(const RegisterAccess& ra) const;
void disable_use(const RegisterAccess& access) {
if (has_local_vars()) {
m_var_names.disable_use(access);
}
}
void disable_use(const RegisterAccess& access);
void disable_def(const RegisterAccess& access, DecompWarnings& warnings);
+8 -3
View File
@@ -143,9 +143,14 @@ void pop_helper(const std::vector<RegisterAccess>& vars,
submit_reg_to_var.push_back(var_idx);
submit_regs.push_back(var.reg());
} else {
// fmt::print("Unsafe to pop {}: used {} times, def {} times, expected use {}\n",
// var.to_string(env), use_def.use_count(), use_def.def_count(),
// times);
/*auto var_id = env.get_program_var_id(var);
fmt::print(
"Unsafe to pop {}: used {} times, def {} times, expected use {} ({} {} rd: {}) ({}
{})\n", var.to_string(env), use_def.use_count(), use_def.def_count(), times,
var.reg().to_string(), var.idx(), var.mode() == AccessMode::READ,
var_id.reg.to_string(), var_id.id);
*/
// if (var.to_string(env) == "a3-0") {
// for (auto& use : use_def.uses) {
// if (!use.disabled) {
+19 -2
View File
@@ -252,6 +252,11 @@ bool is_arg_reg(Register r) {
}
}
int arg_reg_idx(Register r) {
assert(is_arg_reg(r));
return (int)r.get_gpr() - (int)Reg::A0;
}
bool is_saved_reg(Register r) {
if (r.get_kind() == Reg::GPR) {
if (r.get_gpr() == Reg::GP) {
@@ -349,8 +354,19 @@ SSA make_rc_ssa(const Function& function, const RegUsageInfo& rui, const Functio
if (is_possible_coloring_move(dst, src) &&
rui.op.at(op_id).consumes.find(src) != rui.op.at(op_id).consumes.end()) {
ssa_i.is_arg_coloring_move = true;
got_not_arg_coloring = false;
// an integer argument going into a fpr for int->float conversion shouldn't
// be recognized as a coloring move.
if (function.type.arg_count() > 0) {
auto arg_idx = arg_reg_idx(src);
if (dst.get_kind() != Reg::FPR ||
function.type.get_arg(arg_idx) == TypeSpec("float")) {
ssa_i.is_arg_coloring_move = true;
if (dst.get_kind() == Reg::FPR) {
ssa_i.is_gpr_fpr_coloring_move = true;
}
got_not_arg_coloring = false;
}
}
}
}
}
@@ -758,6 +774,7 @@ std::unordered_map<RegId, UseDefInfo, RegId::hash> SSA::get_use_def_info(
if (instr.is_dead_set) {
continue;
}
if (instr.dst.has_value()) {
// get the SSA var:
auto ssa_var_id =
+1
View File
@@ -111,6 +111,7 @@ struct SSA {
std::vector<VarSSA> src;
int op_id = -1;
bool is_arg_coloring_move = false;
bool is_gpr_fpr_coloring_move = false;
bool is_dead_set = false;
std::string print(const VarMapSSA& var_map) const;