]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
add _jit_gen_exch_top and _jit_gen_spill_top functions; add some tracing
authorAleksey Demakov <ademakov@gmail.com>
Fri, 14 Apr 2006 14:44:29 +0000 (14:44 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Fri, 14 Apr 2006 14:44:29 +0000 (14:44 +0000)
ChangeLog
jit/jit-function.c
jit/jit-internal.h
jit/jit-reg-alloc.c
jit/jit-rules-arm.c
jit/jit-rules-interp.c
jit/jit-rules-x86.c
jit/jit-rules.h

index f5bf94ca613e9e2b7cd5a5fc96e6607ee81ceaf8..d9b07d59fc30b29a2d720a682554ceb6019c7c00 100644 (file)
--- 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  <ademakov@gmail.com>
 
        * jit/jit-insn.c (jit_insn_start_catcher): initialize
index 2a23f1deaf778ef8cdcfff25eedf365b614fd390..d2f354c65e21dae88d02743fba725e5936a50ae7 100644 (file)
@@ -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);
index fe47a1d1c8cda1e9b6292a777cd94a376dc1ab4c..cece21f63a30d4f110a12db45a4440d9771cff6b 100644 (file)
 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
 };
 
 /*
index 54cd06685dc7cde39b871951863aa1f31a342ba3..b884fbcc6397ed15f1f808d8cfddde50f2e4a146 100644 (file)
@@ -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
index 6c9fa046dfc2f740bdcb74c3b29309088fa6f650..dbff5df93f96e1555fe2f92740bb8af32864823f 100644 (file)
@@ -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))
index 504905970d790b3b2db0e199c70843592a0fd389..759ad6e242685a4a31edfc8d49e894951a666172 100644 (file)
@@ -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.
index 3a06fc0a3bed39849f4ab53c233fa0161b256145..99beee88d6290af19c9a0e6567b857142bb4c540 100644 (file)
@@ -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:
index f4a62aeed1dd11e52f3d75e56ab14a6746301888..d2fa7536159f9106a00b220fd86e050e72f0be89 100644 (file)
@@ -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);