> On the code itself, I don't really like the remaining, new_tmp(), > dead_tmp(), and even more the fact that some functions can allocate > (e.g load_reg) or free (e.g. store_reg) some TCG variables implicitely. > This is a way to make errors by reallocating or forgetting to free some > > variables, and that leads to strange code like: > | if (rn == 15) { > | tmp = new_tmp(); > | tcg_gen_movi_i32(tmp, 0); > | } else { > | tmp = load_reg(s, rn); > | }
There is actually logic behind this Consider the obvious implementation of the "neg" instruction: val = load_reg(rn); tcg_gen_neg_i32(val, val); store_reg(rd, val); With the current code this is safe. However if load_reg returns cpu_R[n] instead of a temporary then the above code will incorrectly clobber the source register. My theory was that tracking down an accidental write to a source register is much harder than tracking down a mismatched temporary. Paul