From 3a0f45473926d7cda6673969d5b642082576a8ca Mon Sep 17 00:00:00 2001 From: Aleksey Demakov Date: Fri, 14 Apr 2006 14:44:29 +0000 Subject: [PATCH] add _jit_gen_exch_top and _jit_gen_spill_top functions; add some tracing --- ChangeLog | 12 ++++++ jit/jit-function.c | 23 +++++++++- jit/jit-internal.h | 9 ++++ jit/jit-reg-alloc.c | 1 + jit/jit-rules-arm.c | 12 +++++- jit/jit-rules-interp.c | 12 +++++- jit/jit-rules-x86.c | 95 ++++++++++++++++++++++++++++++++++++++---- jit/jit-rules.h | 6 ++- 8 files changed, 156 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5bf94c..d9b07d5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,18 @@ * jit/jit-reg-alloc.h, jit/jit-reg-alloc.c: new register allocator improved and extended to support stack registers. + * jit/jit-internal.h (struct _jit_builder): + * jit/jit-function.c (compile_block, jit_function_compile): add + some tracing. + + * jit/jit-rules.h: + * jit/jit-rules-arm.c: + * jit/jit-rules-interp.c: + * jit/jit-rules-x86.c: add _jit_gen_exch_top and _jit_gen_spill_top + functions used by new allocator to handle stack registers. Add reg + argument to _jit_gen_spill_global and_jit_gen_load_global + functions. + 2006-04-11 Aleksey Demakov * jit/jit-insn.c (jit_insn_start_catcher): initialize diff --git a/jit/jit-function.c b/jit/jit-function.c index 2a23f1d..d2f354c 100644 --- a/jit/jit-function.c +++ b/jit/jit-function.c @@ -445,10 +445,20 @@ static void compile_block(jit_gencode_t gen, jit_function_t func, jit_insn_iter_t iter; jit_insn_t insn; +#ifdef _JIT_COMPILE_DEBUG + printf("Block: %d\n", func->builder->block_count++); +#endif + /* Iterate over all blocks in the function */ jit_insn_iter_init(&iter, block); while((insn = jit_insn_iter_next(&iter)) != 0) { +#ifdef _JIT_COMPILE_DEBUG + unsigned char *p1, *p2; + p1 = gen->posn.ptr; + printf("Insn %5d: 0x%04x - ", func->builder->insn_count++, insn->opcode); +#endif + switch(insn->opcode) { case JIT_OP_NOP: break; /* Ignore NOP's */ @@ -482,7 +492,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func, if(insn->value1->has_global_register) { insn->value1->in_global_register = 1; - _jit_gen_load_global(gen, insn->value1); + _jit_gen_load_global(gen, insn->value1->global_reg, insn->value1); } else { @@ -540,6 +550,11 @@ static void compile_block(jit_gencode_t gen, jit_function_t func, } break; } + +#ifdef _JIT_COMPILE_DEBUG + p2 = gen->posn.ptr; + printf("%d\n", p2 - p1); +#endif } } @@ -626,6 +641,12 @@ int jit_function_compile(jit_function_t func) due to a lack of space in the current method cache page */ do { +#ifdef _JIT_COMPILE_DEBUG + printf("\n*** Start compilation ***\n\n"); + func->builder->block_count = 0; + func->builder->insn_count = 0; +#endif + /* Start function output to the cache */ start = _jit_cache_start_method (cache, &(gen.posn), JIT_FUNCTION_ALIGNMENT, func); diff --git a/jit/jit-internal.h b/jit/jit-internal.h index fe47a1d..cece21f 100644 --- a/jit/jit-internal.h +++ b/jit/jit-internal.h @@ -27,6 +27,11 @@ extern "C" { #endif +/* +#define _JIT_COMPILE_DEBUG 1 +*/ + + /* * Determine what kind of Win32 system we are running on. */ @@ -348,6 +353,10 @@ struct _jit_builder /* Size of the outgoing parameter area in the frame */ jit_nint param_area_size; +#ifdef _JIT_COMPILE_DEBUG + int block_count; + int insn_count; +#endif }; /* diff --git a/jit/jit-reg-alloc.c b/jit/jit-reg-alloc.c index 54cd066..b884fbc 100644 --- a/jit/jit-reg-alloc.c +++ b/jit/jit-reg-alloc.c @@ -2997,6 +2997,7 @@ _jit_regs_init(_jit_regs_t *regs, int flags) regs->stack_count = 0; regs->initial_stack_size = 0; regs->current_stack_size = 0; + regs->num_exchanges = 0; } void diff --git a/jit/jit-rules-arm.c b/jit/jit-rules-arm.c index 6c9fa04..dbff5df 100644 --- a/jit/jit-rules-arm.c +++ b/jit/jit-rules-arm.c @@ -761,12 +761,12 @@ void _jit_gen_load_value jit_cache_end_output(); } -void _jit_gen_spill_global(jit_gencode_t gen, jit_value_t value) +void _jit_gen_spill_global(jit_gencode_t gen, int reg, jit_value_t value) { /* TODO: Implement if ARM needs it. */ } -void _jit_gen_load_global(jit_gencode_t gen, jit_value_t value) +void _jit_gen_load_global(jit_gencode_t gen, int reg, jit_value_t value) { jit_cache_setup_output(32); arm_load_membase(inst, _jit_reg_info[value->global_reg].cpu_reg, @@ -774,6 +774,14 @@ void _jit_gen_load_global(jit_gencode_t gen, jit_value_t value) jit_cache_end_output(); } +void _jit_gen_exch_top(jit_gencode_t gen, int reg, int pop) +{ +} + +void _jit_gen_spill_top(jit_gencode_t gen, int reg, jit_value_t value, int pop) +{ +} + void _jit_gen_fix_value(jit_value_t value) { if(!(value->has_frame_offset) && !(value->is_constant)) diff --git a/jit/jit-rules-interp.c b/jit/jit-rules-interp.c index 5049059..759ad6e 100644 --- a/jit/jit-rules-interp.c +++ b/jit/jit-rules-interp.c @@ -914,7 +914,7 @@ void _jit_gen_load_value * after it. * @end deftypefun @*/ -void _jit_gen_spill_global(jit_gencode_t gen, jit_value_t value) +void _jit_gen_spill_global(jit_gencode_t gen, int reg, jit_value_t value) { /* Global registers are not used in the interpreted back end */ } @@ -927,11 +927,19 @@ void _jit_gen_spill_global(jit_gencode_t gen, jit_value_t value) * slots into their global register copies. * @end deftypefun @*/ -void _jit_gen_load_global(jit_gencode_t gen, jit_value_t value) +void _jit_gen_load_global(jit_gencode_t gen, int reg, jit_value_t value) { /* Global registers are not used in the interpreted back end */ } +void _jit_gen_exch_top(jit_gencode_t gen, int reg, int pop) +{ +} + +void _jit_gen_spill_top(jit_gencode_t gen, int reg, jit_value_t value, int pop) +{ +} + /*@ * @deftypefun void _jit_gen_fix_value (jit_value_t value) * Fix the position of a value within the local variable frame. diff --git a/jit/jit-rules-x86.c b/jit/jit-rules-x86.c index 3a06fc0..99beee8 100644 --- a/jit/jit-rules-x86.c +++ b/jit/jit-rules-x86.c @@ -767,6 +767,67 @@ fp_stack_index(jit_gencode_t gen, int reg) return top - reg; } +void +_jit_gen_exch_top(jit_gencode_t gen, int reg, int pop) +{ + if(IS_FLOAT_REG(reg)) + { + jit_cache_setup_output(2); + if(pop) + { + x86_fstp(inst, reg - X86_REG_ST0); + } + else + { + x86_fxch(inst, reg - X86_REG_ST0); + } + jit_cache_end_output(); + } +} + +void +_jit_gen_spill_top(jit_gencode_t gen, int reg, jit_value_t value, int pop) +{ + int offset; + if(IS_FLOAT_REG(reg)) + { + /* Fix the value in place within the local variable frame */ + _jit_gen_fix_value(value); + + /* Make sure that we have sufficient space */ + jit_cache_setup_output(16); + + /* Output an appropriate instruction to spill the value */ + offset = (int)(value->frame_offset); + + /* Spill the top of the floating-point register stack */ + switch(jit_type_normalize(value->type)->kind) + { + case JIT_TYPE_FLOAT32: + { + x86_fst_membase(inst, X86_EBP, offset, 0, pop); + } + break; + + case JIT_TYPE_FLOAT64: + { + x86_fst_membase(inst, X86_EBP, offset, 1, pop); + } + break; + + case JIT_TYPE_NFLOAT: + { + x86_fst80_membase(inst, X86_EBP, offset); + if(!pop) + { + x86_fld80_membase(inst, X86_EBP, offset); + } + } + break; + } + } +} + void _jit_gen_load_value(jit_gencode_t gen, int reg, int other_reg, jit_value_t value) { @@ -1135,20 +1196,36 @@ _jit_gen_load_value(jit_gencode_t gen, int reg, int other_reg, jit_value_t value jit_cache_end_output(); } -void _jit_gen_spill_global(jit_gencode_t gen, jit_value_t value) +void _jit_gen_spill_global(jit_gencode_t gen, int reg, jit_value_t value) { jit_cache_setup_output(16); - _jit_gen_fix_value(value); - x86_mov_membase_reg(inst, X86_EBP, value->frame_offset, - _jit_reg_info[value->global_reg].cpu_reg, sizeof(void *)); + if(value) + { + _jit_gen_fix_value(value); + x86_mov_membase_reg(inst, + X86_EBP, value->frame_offset, + _jit_reg_info[value->global_reg].cpu_reg, sizeof(void *)); + } + else + { + x86_push_reg(inst, _jit_reg_info[reg].cpu_reg); + } jit_cache_end_output(); } -void _jit_gen_load_global(jit_gencode_t gen, jit_value_t value) +void _jit_gen_load_global(jit_gencode_t gen, int reg, jit_value_t value) { jit_cache_setup_output(16); - x86_mov_reg_membase(inst, _jit_reg_info[value->global_reg].cpu_reg, - X86_EBP, value->frame_offset, sizeof(void *)); + if(value) + { + x86_mov_reg_membase(inst, + _jit_reg_info[value->global_reg].cpu_reg, + X86_EBP, value->frame_offset, sizeof(void *)); + } + else + { + x86_pop_reg(inst, _jit_reg_info[reg].cpu_reg); + } jit_cache_end_output(); } @@ -1502,7 +1579,11 @@ void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, switch(insn->opcode) { #define JIT_INCLUDE_RULES +#if _JIT_NEW_REG_ALLOC + #include "jit-rules-x86.inc" +#else #include "jit-rules-x86.slc" +#endif #undef JIT_INCLUDE_RULES default: diff --git a/jit/jit-rules.h b/jit/jit-rules.h index f4a62ae..d2fa753 100644 --- a/jit/jit-rules.h +++ b/jit/jit-rules.h @@ -193,8 +193,10 @@ void _jit_gen_free_reg(jit_gencode_t gen, int reg, int other_reg, int value_used); void _jit_gen_load_value (jit_gencode_t gen, int reg, int other_reg, jit_value_t value); -void _jit_gen_spill_global(jit_gencode_t gen, jit_value_t value); -void _jit_gen_load_global(jit_gencode_t gen, jit_value_t value); +void _jit_gen_spill_global(jit_gencode_t gen, int reg, jit_value_t value); +void _jit_gen_load_global(jit_gencode_t gen, int reg, jit_value_t value); +void _jit_gen_exch_top(jit_gencode_t gen, int reg, int pop); +void _jit_gen_spill_top(jit_gencode_t gen, int reg, jit_value_t value, int pop); void _jit_gen_fix_value(jit_value_t value); void _jit_gen_insn(jit_gencode_t gen, jit_function_t func, jit_block_t block, jit_insn_t insn); -- 2.47.3