Choose register with farthest next use for spilling. Signed-off-by: Kirill Batuzov <batuz...@ispras.ru> --- tcg/tcg.c | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/tcg/tcg.c b/tcg/tcg.c index c6e920e..61689e2 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1528,6 +1528,9 @@ static void tcg_reg_free(TCGContext *s, int reg) static int tcg_reg_alloc(TCGContext *s, TCGRegSet reg1, TCGRegSet reg2) { int i, reg; +#ifdef USE_ADVANCED_REGALLOC + int best_reg = -1, best_score = -2; +#endif TCGRegSet reg_ct; tcg_regset_andnot(reg_ct, reg1, reg2); @@ -1543,11 +1546,29 @@ static int tcg_reg_alloc(TCGContext *s, TCGRegSet reg1, TCGRegSet reg2) for(i = 0; i < ARRAY_SIZE(tcg_target_reg_alloc_order); i++) { reg = tcg_target_reg_alloc_order[i]; if (tcg_regset_test_reg(reg_ct, reg)) { +#ifdef USE_ADVANCED_REGALLOC + if (s->reg_next_use[reg] > best_score || + s->reg_next_use[reg] == -1) { + best_reg = reg; + best_score = s->reg_next_use[reg]; + if (best_score == -1) { + best_score = OPPARAM_BUF_SIZE + 1; + } + } +#else tcg_reg_free(s, reg); return reg; +#endif } } +#ifdef USE_ADVANCED_REGALLOC + if (best_score >= 0 && best_reg >= 0) { + tcg_reg_free(s, best_reg); + return best_reg; + } +#endif + tcg_abort(); } -- 1.7.4.1