From 865ceafd016266a1f146e4b7f516edcadaffd45a Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Fri, 30 Oct 2009 13:47:14 +0600 Subject: [PATCH] clean outgoing registers after calls --- ChangeLog | 5 +++++ jit/jit-compile.c | 7 +++++++ jit/jit-reg-alloc.c | 15 ++++++++++++++- jit/jit-reg-alloc.h | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d939080..9f78ab6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-10-30 Aleksey Demakov + * jit/jit-reg-alloc.h, jit/jit-reg-alloc.c + (_jit_regs_clear_all_outgoing): add function. + * jit/jit-compile.c (compile_block): use _jit_regs_clear_all_outgoing + after each function call. + * include/jit/jit-except.h (JIT_RESULT_CACHE_FULL): add result code. * jit/jit-cache.h, jit/jit-cache.c (_jit_cache_check_space): add function to check the available cache space. diff --git a/jit/jit-compile.c b/jit/jit-compile.c index 75dab3f..59bcca6 100644 --- a/jit/jit-compile.c +++ b/jit/jit-compile.c @@ -189,6 +189,7 @@ compile_block(jit_gencode_t gen, jit_function_t func, jit_block_t block) } break; +#ifndef JIT_BACKEND_INTERP case JIT_OP_CALL: case JIT_OP_CALL_TAIL: case JIT_OP_CALL_INDIRECT: @@ -199,8 +200,12 @@ compile_block(jit_gencode_t gen, jit_function_t func, jit_block_t block) case JIT_OP_CALL_EXTERNAL_TAIL: /* Spill all caller-saved registers before a call */ _jit_regs_spill_all(gen); + /* Generate code for the instruction with the back end */ _jit_gen_insn(gen, func, block, insn); + /* Free outgoing registers if any */ + _jit_regs_clear_all_outgoing(gen); break; +#endif #ifndef JIT_BACKEND_INTERP case JIT_OP_INCOMING_REG: @@ -208,6 +213,7 @@ compile_block(jit_gencode_t gen, jit_function_t func, jit_block_t block) _jit_regs_set_incoming(gen, (int)jit_value_get_nint_constant(insn->value2), insn->value1); + /* Generate code for the instruction with the back end */ _jit_gen_insn(gen, func, block, insn); break; #endif @@ -253,6 +259,7 @@ compile_block(jit_gencode_t gen, jit_function_t func, jit_block_t block) _jit_regs_set_incoming(gen, (int)jit_value_get_nint_constant(insn->value2), insn->value1); + /* Generate code for the instruction with the back end */ _jit_gen_insn(gen, func, block, insn); break; #endif diff --git a/jit/jit-reg-alloc.c b/jit/jit-reg-alloc.c index 3dad531..21798c6 100644 --- a/jit/jit-reg-alloc.c +++ b/jit/jit-reg-alloc.c @@ -2760,7 +2760,8 @@ void _jit_regs_alloc_global(jit_gencode_t gen, jit_function_t func) * Initialize the register allocation state for a new block. * @end deftypefun @*/ -void _jit_regs_init_for_block(jit_gencode_t gen) +void +_jit_regs_init_for_block(jit_gencode_t gen) { int reg; gen->current_age = 1; @@ -2940,6 +2941,18 @@ _jit_regs_set_outgoing(jit_gencode_t gen, int reg, jit_value_t value) } } +/*@ + * @deftypefun void _jit_regs_clear_all_outgoing (jit_gencode_t gen) + * Free registers used fot outgoing parameters. This is used to + * clean up after a function call. + * @end deftypefun +@*/ +void +_jit_regs_clear_all_outgoing(jit_gencode_t gen) +{ + gen->inhibit = jit_regused_init; +} + /* TODO: remove this function */ /*@ * @deftypefun void _jit_regs_force_out (jit_gencode_t gen, jit_value_t value, int is_dest) diff --git a/jit/jit-reg-alloc.h b/jit/jit-reg-alloc.h index 32adb6f..6368fe7 100644 --- a/jit/jit-reg-alloc.h +++ b/jit/jit-reg-alloc.h @@ -146,6 +146,7 @@ void _jit_regs_init_for_block(jit_gencode_t gen); void _jit_regs_spill_all(jit_gencode_t gen); void _jit_regs_set_incoming(jit_gencode_t gen, int reg, jit_value_t value); void _jit_regs_set_outgoing(jit_gencode_t gen, int reg, jit_value_t value); +void _jit_regs_clear_all_outgoing(jit_gencode_t gen); void _jit_regs_force_out(jit_gencode_t gen, jit_value_t value, int is_dest); int _jit_regs_load_value(jit_gencode_t gen, jit_value_t value, int destroy, int used_again); -- 2.47.3