]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
remove the closure_entry field from jit_function_t
authorAleksey Demakov <ademakov@gmail.com>
Tue, 23 Jan 2007 06:42:33 +0000 (06:42 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Tue, 23 Jan 2007 06:42:33 +0000 (06:42 +0000)
ChangeLog
jit/jit-function.c
jit/jit-internal.h
jit/jit-rules-alpha.ins
jit/jit-rules-x86.ins

index 6882e3cffbcee67adf92b30aa4d56f63d4c6ff81..d75a7d83428016f22ab0f78cf95237c469418f4e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-01-23  Aleksey Demakov  <ademakov@gmail.com>
+
+       * jit/jit-internal.h, jit/jit-function.c: remove the closure_entry
+       field from jit_function_t. Find this value on the fly in
+       jit_function_to_closure() and jit_function_to_vtable_pointer()
+       to be equal either to entry_point or indirector fields.
+
+       * jit/jit-rules-alpha.ins, jit/jit-rules-x86.ins: use
+       jit_function_to_closure() instead of the closure_entry field.
+
 2007-01-17  Aleksey Demakov  <ademakov@gmail.com>
 
        * jit/jit-reg-alloc.h, jit/jit-reg-alloc.c: complete special x87
index a4815139dc861b438186fddf89a826539b420e2c..ffb84bde2102a7c7aabe64db1704682e972f9223 100644 (file)
@@ -24,6 +24,9 @@
 #include "jit-reg-alloc.h"
 #include "jit-apply-func.h"
 #include "jit-setjmp.h"
+#ifdef _JIT_COMPILE_DEBUG
+#include <stdio.h>
+#endif
 
 /*@
  * @deftypefun jit_function_t jit_function_create (jit_context_t context, jit_type_t signature)
@@ -109,12 +112,10 @@ jit_function_t jit_function_create(jit_context_t context, jit_type_t signature)
                (func->redirector, (void *)_jit_function_compile_on_demand,
                 func, jit_type_get_abi(signature));
        jit_flush_exec(func->redirector, jit_redirector_size);
+
 # if defined(jit_indirector_size)
-       func->closure_entry = _jit_create_indirector
-               (func->indirector, (void**) &(func->entry_point));
+       _jit_create_indirector(func->indirector, (void**) &(func->entry_point));
        jit_flush_exec(func->indirector, jit_indirector_size);
-# else
-       func->closure_entry = func->entry_point;
 # endif
 #endif
 
@@ -496,7 +497,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func,
        jit_insn_t insn;
 
 #ifdef _JIT_COMPILE_DEBUG
-       printf("Block: %d\n", func->builder->block_count++);
+       printf("Block #%d: %d\n", func->builder->block_count++, block->label);
 #endif
 
        /* Iterate over all blocks in the function */
@@ -507,7 +508,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func,
                unsigned char *p1, *p2;
                p1 = gen->posn.ptr;
                printf("Insn: %5d, Opcode: 0x%04x\n", func->builder->insn_count++, insn->opcode);
-               printf("Start of binary code: 0x%08x\n",  p1);
+               printf("Start of binary code: 0x%08x\n", p1);
 #endif
 
                switch(insn->opcode)
@@ -611,6 +612,7 @@ static void compile_block(jit_gencode_t gen, jit_function_t func,
 #ifdef _JIT_COMPILE_DEBUG
                p2 = gen->posn.ptr;
                printf("Length of binary code: %d\n\n", p2 - p1);
+               fflush(stdout);
 #endif
        }
 }
@@ -648,9 +650,6 @@ int jit_function_compile(jit_function_t func)
        struct jit_gencode gen;
        jit_cache_t cache;
        void *start;
-#if !defined(jit_redirector_size) || !defined(jit_indirector_size) || defined(JIT_BACKEND_INTERP)
-       void *recompilable_start = 0;
-#endif
        void *end;
        jit_block_t block;
        int result;
@@ -784,12 +783,14 @@ int jit_function_compile(jit_function_t func)
                }
 #endif
 
-#if !defined(jit_redirector_size) || !defined(jit_indirector_size) || defined(JIT_BACKEND_INTERP)
+#if !defined(jit_redirector_size) || !defined(jit_indirector_size)
                /* If the function is recompilable, then we need an extra entry
                   point to properly redirect previous references to the function */
-               if(func->is_recompilable)
+               if(func->is_recompilable && !func->indirector)
                {
-                       recompilable_start = _jit_gen_redirector(&gen, func);
+                       /* TODO: use _jit_create_indirector() instead of
+                          _jit_gen_redirector() as both do the same. */
+                       func->indirector = _jit_gen_redirector(&gen, func);
                }
 #endif
 
@@ -842,22 +843,6 @@ int jit_function_compile(jit_function_t func)
 
        /* Record the entry point */
        func->entry_point = start;
-#if !defined(jit_redirector_size) || !defined(jit_indirector_size) || defined(JIT_BACKEND_INTERP)
-       if(recompilable_start)
-       {
-               func->closure_entry = recompilable_start;
-       }
-       else
-#else
-       /* If the function is recompilable, then we keep closure_entry
-          point to indirector to properly redirect previous references
-          to the function, otherwise we make it equal to the function
-          start */
-       if(!func->is_recompilable)
-#endif
-       {
-               func->closure_entry = start;
-       }
        func->is_compiled = 1;
 
        /* Free the builder structure, which we no longer require */
@@ -1040,7 +1025,11 @@ void *jit_function_to_closure(jit_function_t func)
                                                          function_closure, (void *)func);
 #else
        /* On native platforms, use the closure entry point */
-       return func->closure_entry;
+       if(func->indirector && (!func->is_compiled || func->is_recompilable))
+       {
+               return func->indirector;
+       }
+       return func->entry_point;
 #endif
 }
 
@@ -1127,14 +1116,15 @@ void *jit_function_to_vtable_pointer(jit_function_t func)
        return func;
 #else
        /* On native platforms, the closure entry point is the vtable pointer */
-       if(func)
+       if(!func)
        {
-               return func->closure_entry;
+               return 0;
        }
-       else
+       if(func->indirector && (!func->is_compiled || func->is_recompilable))
        {
-               return 0;
+               return func->indirector;
        }
+       return func->entry_point;
 #endif
 }
 
index 34f6f5eef88f0764e64afaa5eaa4bd93fca8414e..409b1517cf34409751df33338b77c3c6bbd41e1c 100644 (file)
@@ -395,9 +395,6 @@ struct _jit_function
        /* The entry point for the function's compiled code */
        void * volatile         entry_point;
 
-       /* The closure/vtable entry point for the function's compiled code */
-       void * volatile         closure_entry;
-
        /* The function to call to perform on-demand compilation */
        jit_on_demand_func      on_demand;
 
@@ -406,12 +403,12 @@ struct _jit_function
           Redirectors are used to support on-demand compilation */
        unsigned char           *redirector;
 #endif
-#ifdef jit_indirector_size
+
        /* Buffer that contains the indirector for this function.
-          The indirector is used to jump either to the function
-          redirector or the compiled function itself. */
+          The indirector jumps to the address that is currently
+          stored in the entry_point field. Indirectors are used
+          to support recompilation and on-demand compilation. */
        unsigned char           *indirector;
-#endif
 };
 
 /*
index dbb7a8b208b72f6bc565b55f02456b767478f336..ecd48b6e0610f5e844a9a16f323d6146bd437880 100644 (file)
@@ -410,7 +410,7 @@ JIT_OP_ILE_UN:
 JIT_OP_CALL:
        [] -> {
                jit_function_t func = (jit_function_t)(insn->dest);
-               alpha_call(inst, func->closure_entry);
+               alpha_call(inst, jit_function_to_closure(func));
        }
 
 /* TODO: JIT_OP_CALL_TAIL, JIT_OP_CALL_INDIRECT, JIT_OP_CALL_VTABLE_PTR */
index 78717b2b9b976802fa58fa4388a4783097a3c120..2f80e6f837769b6e4d88c448f6a2bacf8054cdea 100644 (file)
@@ -1464,7 +1464,7 @@ JIT_OP_CHECK_NULL: note
 JIT_OP_CALL:
        [] -> {
                jit_function_t func = (jit_function_t)(insn->dest);
-               x86_call_code(inst, func->closure_entry);
+               x86_call_code(inst, jit_function_to_closure(func));
        }
 
 JIT_OP_CALL_TAIL:
@@ -1472,7 +1472,7 @@ JIT_OP_CALL_TAIL:
                jit_function_t func = (jit_function_t)(insn->dest);
                x86_mov_reg_reg(inst, X86_ESP, X86_EBP, sizeof(void *));
                x86_pop_reg(inst, X86_EBP);
-               x86_jump_code(inst, func->closure_entry);
+               x86_jump_code(inst, jit_function_to_closure(func));
        }
 
 JIT_OP_CALL_INDIRECT: